1、How can I set column width in the excel when export grid data to excel.
2、The format has changed when I export a "datetime" type to excel.
For example:In grid the data is '2012/02/02'
After exported:In excel the data is '2012-02-02'
How can I make the format is the same? (do not change the datetime to string )
Hi Foxbabby,
foxbabby said:1、How can I set column width in the excel when export grid data to excel.
You can use the Width property of the columns in order to set directly the Width while exporting the data:
worksheet.Columns[2]. Width = 6100
http://help.infragistics.com/NetAdvantage/ASPNET/2012.1/CLR4.0/?page=ExcelEngine_Resizing_Rows_and_Columns.html
foxbabby said: 2、The format has changed when I export a "datetime" type to excel. For example:In grid the data is '2012/02/02' After exported:In excel the data is '2012-02-02' How can I make the format is the same? (do not change the datetime to string )
You can use CellFormat.FormatString in order to format the data you need, otherwise the excel will use own format strings:
worksheet.Rows[4].Cells[0].CellFormat.FormatString = “yyyy/mm/dd”
worksheet.Rows[4].Cells[0].CellFormat.FormatString =
“yyyy/mm/dd”
http://help.infragistics.com/NetAdvantage/ASPNET/2012.1/CLR4.0/?page=ExcelEngine_Applying_Styles_to_Cells.html
You can retrieve the Cell and Column object by handling the GridFieldCaptionExporting event form WebExcelExporter. This will give you the active column number and you can set the width and style you want to the whole column, otherwise you can use CellExported event if you need to set if for specific cell.
Please let me know if you have any furthered questions.