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);

            }

  • 相关阅读:
    服务端跳转和客户端跳转的区别
    jsp:include标签与include指令的区别
    jsp错误页不跳转显示500
    使用Cookie进行会话管理
    深入理解重定向和转发
    appium环境搭建(二)----搭建android开发环境
    appium环境搭建(一)----安装appium
    Fiddler实现移动端手机抓包
    黑盒测试人员必备技能
    SVN服务器搭建
  • 原文地址:https://www.cnblogs.com/cxlings/p/3550023.html
Copyright © 2011-2022 走看看