Setting default styles for workbook not sticking

I’ve read on several posts that you can set global styles by modifying the DefaultStyle property of a workbook similar to the following:

wb.DefaultStyle.Font.Color = System.Drawing.Color.Black
wb.DefaultStyle.BackgroundColor = System.Drawing.Color.Empty
wb.DefaultStyle.ForegroundColor = System.Drawing.Color.Empty
wb.DefaultStyle.Pattern = BackgroundType.None

But it doesn’t seem to affect existing text on a workbook. I am trying to reset all cells in a workbook to black text on a white background.

Thanks.

Hi,

Well, Workbook.DefaultStyle only works on new workbooks which you are creating from the scratch. If you are modifying formattings of an existing excel file, you 'd better create a style object, set all the attributes related formattings, create style flag struct and specify the related attributes to true, loop through the rows and columns and use ApplyStyle(style,styleflag) method.

And we will also enhance style formattings soon.

Thank you.

It’s running very slow when there are thousands of rows of data.

When do you expect the enhancements to be released? Are we talking days, weeks, or months?

I’m just trying to get an idea if I should implement the existing code or wait for a release.

Thanks again for your hard work!

Hi,

Thanks for considering Aspose.

We will update you soon.

Thanks for being patient!

Hi,

Please change your codes. See following codes:

Style defaultStyle = workbook.DefaultStyle;
defaultStyle.Font.Color = System.Drawing.Color.Black;
defaultStyle.BackgroundColor = System.Drawing.Color.Empty;
defaultStyle.ForegroundColor = System.Drawing.Color.Empty;
defaultStyle.Pattern = BackgroundType.None;

// the following codes will keep your setting of default style.
workbook.DefaultStyle = defaultStyle;

Yes, but the same problem remains, this is only for new information added to the spreadsheet, it doesn’t affect existing data.

Essentially, if you’re trying to change the formatting of an entire worksheet with a lot of cells then there’s no fast or easy way to format them. Looping through the columns or creating a range is extremely slow compared to highlighting the sheet in excel and clicking format cells. It also increases the file size pretty significantly.

Any word on an update?

Hi,

Please try this fix in <A href="https://forum.aspose.com/t/92826</FONT></A>.</P> <P>It inlcudes the fix for this bug.We have added a method Cells.ApplyStyle to apply the style to entire worksheet.See following codes:</P> <P>StyleFlag flag = new StyleFlag();<BR> flag.All = true;<BR> cells.ApplyStyle(style, flag);</P>