【发布时间】:2015-08-21 08:24:50
【问题描述】:
我正在使用 infragistics excel 导出到 excel。 我想将 excel 的列类型设置为与 db 的列类型相同。意味着如果列类型是 datetime,它应该在 infragistics excel 表中创建 datetime 列。
我试过下面的代码。
Infragistics.Documents.Excel.Workbook workbook = new Infragistics.Documents.Excel.Workbook();
// Create the worksheet to represent this data table
Infragistics.Documents.Excel.Worksheet worksheet = workbook.Worksheets.Add(dtReportData.TableName);
// Create column headers for each column
for (int columnIndex = 0; columnIndex < dtReportData.Columns.Count; columnIndex++)
{
worksheet.Rows[0].Cells[columnIndex].Value = dtReportData.Columns[columnIndex].ColumnName;
}
// Starting at row index 1, copy all data rows in
// the data table to the worksheet
int rowIndex = 1;
foreach (DataRow dataRow in dtReportData.Rows)
{
Infragistics.Documents.Excel.WorksheetRow row = worksheet.Rows[rowIndex++];
for (int columnIndex = 0; columnIndex < dataRow.ItemArray.Length; columnIndex++)
{
row.Cells[columnIndex].Value = dataRow.ItemArray[columnIndex];
if (dtReportData.Columns[columnIndex].DataType == Type.GetType("System.Decimal"))
{
//Here column should be of type decimal.
}
else if (dtReportData.Columns[columnIndex].DataType == Type.GetType("System.DateTime"))
{
//Here column type should be of type datetime.
}
}
有人可以帮我解决这个问题吗..
【问题讨论】:
标签: c# asp.net .net export-to-excel infragistics