通过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 567 Project


下一篇:IDEA报错Plugin "XXX" was not loaded: required plugin "Java EE: EJB, JPA, Servlets"