Free Support Forum -

How to set the DefaultStyle for a Workbook


I would like to change de default style (actualy, the default font) for all the workbook.

I have try this code, but it does not work:

Excel xls = new Excel();

xls.DefaultStyle.Font.Name = "Tahoma";

xls.Worksheets[0].Cells[0,0].PutValue("Hello World");


The "Hello World" is in Arial.

Is it a way to set the default style without setting the style of all Cells ?

Thanks !


I will check and add this feature in the future release.

Is there an ETA on when this might be implemented? Any guesses?

I’ve downloaded and been playing with version, and the DefaultStyle attributes still behave as described above (i.e., don’t get changed when set). This functionality would definitely be a BIG help, and it would be great if it were being added in the near future.

Thanks. It’s a great component.

Please try the following sample code :

Excel xls = new Excel();
Style style = xls.DefaultStyle;
style.Font.Name = “Tahoma”;
xls.DefaultStyle = style;
xls.Worksheets[0].Cells[0,0].PutValue(“Hello World”);

Thanks for the suggestion. I believe I had tried most everything else (e.g., changing the DefaultStyle elements, creating a style and assigning it to DefaultStyle, etc.), but not this particular tack.

It seems (to me at least) almost counterintuitive that to change elements of DefaultStyle you need to “off-load” it to a style instance, make changes to that instance, and then re-apply the instance to DefaultStyle. It works, no question about that, and now that I know, it’s simple enough to do. The documentation (chm and IntelliSense) seems to suggest something a little more straightforward: in, coding “xls.DefaultStyle.Font.Name” shows it as a get/set property, but set doesn’t work in that context; to do a set, one has to follow what you show, above.

But, as I said, that works. Thanks again for the reply.

Your suggestion is helpful. Thank you.
I will check this issue and change it if possible. If it's impossible to change the property, I will change the documentation to clear this confusion.