C# 读取一个CSV文件,怎么把CSV文件中的数据放到DataTabel中?
///
/// 读取Excel文件为DataTable,使用Aspose.Cells.dll
///
/// Excel文件的全路径
///
DataTable public static DataTable ExcelToDataTable(string filepath)
{
DataTable dt = new DataTable();
try
{
if (!File .Exists(filepath))
{
MessageBox.Show(@"文件不存在!" ,@"提示");
return null ;
}
Aspose.Cells. Workbook workbook = new Aspose.Cells.Workbook();
workbook.Open(filepath);
Aspose.Cells. Worksheet worksheet = workbook.Worksheets[0];
dt = worksheet.Cells.ExportDataTable(0, 0, worksheet.Cells.MaxDataRow + 1, worksheet.Cells.MaxColumn + 1, true );//showTitle
return dt;
}
catch (System.Exception e)
{
return null ;
}