Open GoogleCodeExporter opened 9 years ago
Original comment by jetcat
on 12 Feb 2009 at 3:31
Original comment by jetcat
on 12 Feb 2009 at 3:32
Workbook book = Workbook.Load(filename);
Worksheet sheet = book.Worksheets[0];
if (sheet.Cells.Rows.Count > 0)
{
DataTable tab = new DataTable();
Row HeadRow = sheet.Cells.GetRow(0);
DataColumn dc;
//把第一行当成列标题 the First Row is ColumName
for (int a = 0; a < HeadRow.LastColIndex; a++)
{
dc = new DataColumn(HeadRow.GetCell(a).StringValue);
tab.Columns.Add(dc);
}
for (int rowIndex = sheet.Cells.FirstRowIndex + 1; rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
{
DataRow dr = tab.NewRow();
Row row = sheet.Cells.GetRow(rowIndex);
for (int colIndex = row.FirstColIndex; colIndex <= row.LastColIndex; colIndex++)
{
//Can not use row.GetCell(colIndex).Format.FormatType
if (HeadRow.GetCell(colIndex).StringValue.IndexOf("日期") >= 0)
{
Double df = double.Parse(row.GetCell(colIndex).StringValue);
DateTime dt= DateTime.FromOADate(df);
dr[colIndex] = dt.ToString("yyyy-MM-dd HH:mm:ss");
}
else { dr[colIndex] = row.GetCell(colIndex).StringValue; }
}
tab.Rows.Add(dr);
}
book = null;
sheet = null;
dgv.DataSource = tab;
Original comment by mingiqu...@gmail.com
on 15 Nov 2013 at 8:43
Original issue reported on code.google.com by
marco.di...@gmail.com
on 11 Feb 2009 at 10:01