c# file 上传EXCEL文件,以流的形式读取数据

1.引入  Aspose.Cells

public void test()
{
HttpFileCollection filelist = HttpContext.Current.Request.Files;
                if (filelist != null && filelist.Count > 0)
                {
                    for (int i = 0; i < filelist.Count; i++)
                    {
                        HttpPostedFile file = filelist[i];
var listData = ReadExcelToTable(file.InputStream).Rows;
                    }
                 }      
}

private DataTable ReadExcelToTable(Stream stream)
        {
            DataTable result = new DataTable();
            Workbook workbook = new Workbook();
            workbook.Open(stream);
            Cells cells = workbook.Worksheets[0].Cells;
            result = cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxColumn + 1, false);
            return result;
        }              

 

上一篇:el-upload 文件上传失败时标红显示,且文件名拼接上(上传失败)


下一篇:arcpy简单示例