使用Aspose将数据表格下载为Excel文件

2019/7/24 11:07:30 人评论 次浏览 分类:学习教程

小白总结,大神勿喷。

Excel文件样式需要自己微调

Aspose 类库可以不购买(生成的文件最后一个Sheet有水印)       

private void downLoadExcel(string ExcelName, DataTable DT)
        {
            License license = new License();
            license.SetLicense("Aspose.Cells.lic");

            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];
            worksheet.Cells.ImportDataTable(DT, true, "A1");

            Aspose.Cells.Style s = workbook.CreateStyle();
            s.ForegroundColor = System.Drawing.Color.Gray;
            s.Pattern = Aspose.Cells.BackgroundType.Solid;
            Aspose.Cells.Range r = worksheet.Cells.CreateRange(0, 0, 1, DT.Columns.Count);
            r.SetStyle(s);
            Cells cells = worksheet.Cells;
            cells.StandardHeight = 18;
            cells.StandardWidth = 15;
            workbook.Save(Response, HttpUtility.UrlEncode(ExcelName, System.Text.Encoding.UTF8) + ".xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
        }

相关资讯

    暂无相关的资讯...

共有访客发表了评论 网友评论

验证码: 看不清楚?
    -->