Free Support Forum - aspose.com

Compile time error while using workbook.styles (wb.styles)

Calling Method
SetWorkbookStyle(wb.DefaultStyle, wb.Styles);

Called Method
private Style SetWorkbookStyle(Style defaultStyle, StyleCollection styles)
{}

While Upgrading aspose version V8 to latest version (V20.9.0), workbook method has 2 methods 1) Default style 2) styles.
when compiling code, the second parameter wb.styles throws an error ‘Workbook doesn’t contain a definition for styles’.

please suggest alternative for wb.styles

@sindhu0234,
The class StyleCollection & property Workbook.Styles have been marked obsoleted since the release of Aspose.Cells 8.3.2. It is advised to use the Workbook.CreateStyle method to create an instance of Style . Moreover, Workbook.GetNamedStyle(string) method can be used to get named style instead of StyleCollection[string] .

For example, please take a look at below code:

Workbook wb = new Workbook();
Worksheet worksheet = wb.Worksheets[0];
Style oStyle = wb.CreateStyle();
oStyle.Font.Name = "Times New Roman";
oStyle.Font.Size = 16;
StyleFlag oFlag = new StyleFlag();
oFlag.FontName = true;
oFlag.FontSize = true;
worksheet.Cells.ApplyStyle(oStyle, oFlag);
wb.Save("e:\test\outputBook.xls");