Hello
I have a data table and I export it to excel by
dataSheet.Cells.ImportDataTable(dtData, true, 0, 0, true, true);
The datatable values with percentage (eg 17.31%) is displayed in Excel as 0.1731. How do I format it to be displayed as 17.31%.
Thanks.
Kit
Hi,
Well, you may format your desired column to percentage values after importing data table to your worksheet cells, e.g
//…
//Adding a new Style to the styles collection of the Excel object
int styleIndex = workbook.Styles.Add();
//Accessing the newly added Style to the Excel object
Style style = workbook.Styles[styleIndex];
StyleFlag styleFlag = new StyleFlag();
style.Custom = “0.00%”;
//Apply your desired attributes on.
styleFlag.NumberFormat = true;
//Assigning the Style object to the third column which is supposed to be your percentage column.
dataSheet.Cells.ApplyColumnStyle(2, style, styleFlag);
Also, check the document for your reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/setting-display-formats-of-numbers-dates.html
Thank you.
Hi
thanks for your reply. I will chk this out and get back to you.
Cheers
Kit
It works perfect. Thanks.
How do I make a particular row bold? Is it possible to apply a style rowwise. for eg I have hundred rows. Rows 1, 23, 54 should be bold. How to achieve this?
Thanks
Kit
Hi,
Yes, quite possible, see the sample code segment below for your reference:
//Adding a new Style to the styles collection of the Excel object
workbook.Styles.Add();
//Accessing the newly added Style to the Excel object
Style style = workbook.Styles[0];
style.Font.IsBold = true;
//Creating StyleFlag
StyleFlag styleFlag = new StyleFlag();
styleFlag.FontBold = true;
//Accessing a row from the Rows collection
Row row = worksheet.Cells.Rows[0];
//Assigning the Style object to the Style property of the row
row.ApplyStyle(style,styleFlag);
For further reference, please check the document:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/formatting-rows-columns.html
Thank you.