We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem with xlsx and custom styles in Aspose.Celss for .NET

Hi,

We are evaluating Aspose.Cells for .Net in our company and we have faced a problem regarding custom styles and Office 2007 .xslx documents.

We have created a template xsls file (attached). Upon opening the xlsx file, we try to programmatically insert contents into the worksheet using the following code:

var workbook = new Workbook();
workbook.Open("sample-styleproblem.xlsx", FileFormatType.Excel2007Xlsx);
var worksheet = workbook.Worksheets[0];

[...]

worksheet.Cells[row, 2].PutValue("0");
worksheet.Cells[row, 2].Style = workbook.Styles["TableBorderCurrency"];

(where 'row' is an integer).

For some reason, the custom styles created in the template xlsx (such as the "TableBorderCurrency") are not available in the workbook.Styles collection. Hence the style is not applied

However, if we change the template workbook into xls (Office 97/2003) format, Aspose.Cells recognises the styles correctly.

Can you give us any help into how we could use styles with Excel 2007 workbooks?

With best regards,
Henrik BlÄfield

Hi Henrik,

Thank you for considering Aspose.

Well as per your posted code, the value you are inserting in the number type cell by using Cells.PutValue method is of type string which cause the error on the cell and does not apply the currency style. Please correct this line of code as under and check if it works fine,

worksheet.Cells[row, 2].PutValue(0);

Please do let us know if you still face any problem,

Thank you and Best Regards.

Hi,

And you can use Cell.PutValue("0", true) to convert the string value to a numberic value if you get string value from the data source.