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

            }

  • 相关阅读:
    如何在tomcat安装部署php项目
    十大建站开源程序
    虚拟主机、VPS、云主机以及独立服务器的关系
    heritrix启动问题修正
    网页布局:float与position的区别
    C#中利用委托实现多线程跨线程操作
    Java Service Wrapper配置详解
    Windows7部署WordPress傻瓜式教程(IIS7.5+MySQL+PHP+WordPress)
    关于favicon.ico的使用
    使用JAVA对字符串进行DES加密解密(修正问题)
  • 原文地址:https://www.cnblogs.com/cxlings/p/3550023.html
Copyright © 2011-2022 走看看