zoukankan      html  css  js  c++  java
  • apose 根据excel 导出模版

     string file = Server.MapPath("~/Excel/ZWxxtj.xls");
                DataSet ds = new DataSet();
                DataTable dtout = new DataTable();
                dtout.Columns.Add("单位", typeof(string));
                dtout.Columns.Add("数量", typeof(string));
                dtout.Columns.Add("分数", typeof(string));
                dtout.Columns.Add("看看", typeof(string));

                List<DataTable> lst = null;
                for (int i = 0; i < 3; i++)
                {
                    lst = new List<DataTable>();

                    DataRow dr = dtout.NewRow();
                    dr["单位"] = "AAAA" + i;
                    dr["数量"] = "BBBB" + i;
                    dr["分数"] = "CCCC" + i;
                    dr["看看"] = "DDDD" + i;
                    dtout.Rows.Add(dr);

                }
                ds.Tables.Add(dtout);

                lst.Add(ds.Tables[0]);


                ExportExcelModel(this.Response, lst, file, 4);//从第四行开始填充数据

    public void ExportExcelModel(HttpResponse res, List<System.Data.DataTable> Datas, string ExcelTemplatePath, int FirstRow)
            {
                //Excel的路径 是放excel模板的路径
                WorkbookDesigner designer = new WorkbookDesigner();
                designer.Open(ExcelTemplatePath);

                Worksheet sheet = designer.Workbook.Worksheets[0];
                sheet.Cells.ImportDataTable(Datas[0], false, FirstRow, 0, true);

                var c11 = sheet.Cells[0, 0];//第一行 第一列

                c11.PutValue("我是标题,大家新年快乐。。。");

                SaveOptions s = new XlsSaveOptions(SaveFormat.Excel97To2003);
                string str = "";

                str = HttpUtility.UrlEncode("测试.xls", Encoding.UTF8).ToString();


                designer.Workbook.Save(res, str, ContentDisposition.Attachment, s);

            }

  • 相关阅读:
    高可用的MongoDB集群-实战篇
    【转载】特征选择常用算法综述
    【转载】Pytorch tutorial 之Datar Loading and Processing
    论文笔记系列-Well Begun Is Half Done:Generating High-Quality Seeds for Automatic Image Dataset Construction from Web
    重新定义Pytorch中的TensorDataset,可实现transforms
    【转载】机器学习之特征工程
    Pytorch里的CrossEntropyLoss详解
    Python日志模块logging用法
    【转载】如何进行数据变换
    【转载】使用sklearn优雅地进行数据挖掘
  • 原文地址:https://www.cnblogs.com/cxlings/p/3550023.html
Copyright © 2011-2022 走看看