通过Aspose上传excel到服务器并转换为table
作者:互联网
public static bool GetExcelDatatable(out DataTable dt, out string strMSG) { strMSG = null; dt = null; try { HttpPostedFile files = HttpContext.Current.Request.Files[0]; Workbook workbook = new Workbook(files.InputStream); //创建工作簿对象 WorksheetCollection worksheets = workbook.Worksheets; //创建工作表对象 string sheetName = worksheets[0].Name; Worksheet worksheet = workbook.Worksheets[0]; Cells cells = worksheet.Cells; dt = cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true); return true; ; } catch (Exception ee) { strMSG = ee.Message; return false; } }
注意需要在NuGet包中添加Aspose组件!
此处我用的是webapi
标签:ee,cells,excel,strMSG,Aspose,workbook,table,dt,null 来源: https://www.cnblogs.com/mushuizzz/p/11840312.html