【发布时间】:2016-06-17 05:08:12
【问题描述】:
我已尝试导入 excel,excel 中的日期列正在更改为数字格式。 例如 我在excel中有3列 姓名、年龄和出生地
当我尝试将此 excel 转换为数据表时,Dob 列中的日期正在更改为数字。
using (ExcelPackage excelPackage = new ExcelPackage(fi))
{
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets[sheetName];
ExcelCellAddress startCell = worksheet.Dimension.Start;
ExcelCellAddress endCell = worksheet.Dimension.End;
if (endCell.Row > 0)
{
for (int col = startCell.Column; col <= endCell.Column; col++)
{
dt.Columns.Add(Convert.ToString(worksheet.Cells[startCell.Row, col].Value));
}
for (int row = startCell.Row + 1; row <= endCell.Row; row++)
{
DataRow dr = dt.NewRow();
int x = 0;
for (int col = startCell.Column; col <= endCell.Column; col++)enter code here
{
dr[x++] = worksheet.Cells[row, col].Value;
}
dt.Rows.Add(dr);
}
}
}
【问题讨论】:
-
提供excel中的格式和你在datatable中得到的格式。
-
excel格式为MM/dd/yyyy
-
你在 DataTable 中得到了什么?
-
例如:2016 年 7 月 1 日上述日期在转换为数据表时我得到数字 42552