不廢話直接上代碼 主要注意是 紅色代碼部分
Aspose.Cells.TxtLoadOptions lo = new TxtLoadOptions();
lo.Encoding = Encoding.Default;
//創建一個Workbook和Worksheet對象
Worksheet wkSheet = null;
Workbook wkBook = new Workbook(strFileName,lo);
wkBook.FileFormat = FileFormatType.CSV;
wkSheet = wkBook.Worksheets[SheetIndex];
Cells cells = wkSheet.Cells;
//讀取標頭數據
DataTable dt = cells.ExportDataTableAsString(SheetIndex, HeaderRowIndex, cells.MaxDataRow + 1, cells.MaxColumn + 1, true);
//釋放對象
wkSheet = null;
wkBook = null;
//返回數據
return dt;