我想按照this code來閱讀Excel文件。不幸的是,我無法使它工作,因爲我需要閱讀沒有標題的Excel文件。我怎樣才能讀取沒有標題的Excel文件?閱讀不帶頭文件的Excel文件ASP.Net
public static DataTable ToDataTable(this ExcelPackage package)
{
ExcelWorksheet workSheet = package.Workbook.Worksheets.First();
DataTable table = new DataTable();
foreach (var firstRowCell in workSheet.Cells[1, 1, 1, workSheet.Dimension.End.Column])
{
table.Columns.Add(firstRowCell.Text);
}
for (var rowNumber = 2; rowNumber <= workSheet.Dimension.End.Row; rowNumber++)
{
var row = workSheet.Cells[rowNumber, 1, rowNumber, workSheet.Dimension.End.Column];
var newRow = table.NewRow();
foreach (var cell in row)
{
newRow[cell.Start.Column-1] = cell.Text;
}
table.Rows.Add(newRow);
}
return table;
}
也許嘗試這樣一個http://stackoverflow.com/questions/13396604/excel-to-datatable-using-epplus-excel-locked-for-editing用'布爾hasHeader = FALSE;' – Slai