转载自:http://www.cnblogs.com/jbps/p/3549671.html?utm_source=tuicool&utm_medium=referral

 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7 using Aspose.Cells;
8 using System.Text;
9 using System.Data;
10
11 namespace Oceansoft.Net.CeSWeb.Module.导出Excel_通过模板_
12 {
13 public partial class daochu : System.Web.UI.Page
14 {
15 protected void Page_Load(object sender, EventArgs e)
16 {
17
18 }
19 /// <summary>
20 /// 单击导出
21 /// </summary>
22 /// <param name="sender"></param>
23 /// <param name="e"></param>
24 public void btnDaochu_ServerClick(object sender, EventArgs e)
25 {
26 string file = Server.MapPath("~/Excel/ZWxxtj.xls");
27 DataSet ds = new DataSet();
28 DataTable dtout = new DataTable();
29 dtout.Columns.Add("单位", typeof(string));
30 dtout.Columns.Add("数量", typeof(string));
31 dtout.Columns.Add("分数", typeof(string));
32 dtout.Columns.Add("看看", typeof(string));
33
34 List<DataTable> lst = null;
35 for (int i = 0; i < 3; i++)
36 {
37 lst = new List<DataTable>();
38
39 DataRow dr = dtout.NewRow();
40 dr["单位"] = "AAAA" + i;
41 dr["数量"] = "BBBB" + i;
42 dr["分数"] = "CCCC" + i;
43 dr["看看"] = "DDDD" + i;
44 dtout.Rows.Add(dr);
45
46 }
47 ds.Tables.Add(dtout);
48
49 lst.Add(ds.Tables[0]);
50
51
52 ExportExcelModel(this.Response, lst, file, 4);//从第四行开始填充数据
53 }
54
55 public void ExportExcelModel(HttpResponse res, List<System.Data.DataTable> Datas, string ExcelTemplatePath, int FirstRow)
56 {
57 //Excel的路径 是放excel模板的路径
58 WorkbookDesigner designer = new WorkbookDesigner();
59 designer.Open(ExcelTemplatePath);
60
61 Worksheet sheet = designer.Workbook.Worksheets[0];
62 sheet.Cells.ImportDataTable(Datas[0], false, FirstRow, 0, true);
63
64 var c11 = sheet.Cells[0, 0];//第一行 第一列
65
66 c11.PutValue("我是标题,大家新年快乐。。。");
67
68 SaveOptions s = new XlsSaveOptions(SaveFormat.Excel97To2003);
69 string str = "";
70
71 str = HttpUtility.UrlEncode("测试.xls", Encoding.UTF8).ToString();
72
73
74 designer.Workbook.Save(res, str, ContentDisposition.Attachment, s);
75
76 }
77 }
78 }

Net 自定义Excel模板导出数据的更多相关文章

  1. kettle 使用excel模板导出数据

    通过excel进行高速开发报表: 建设思路: 1.首先制订相关的execl模板. 2.通过etl工具(kettle)能够高速的 将数据库中的数据按excel模板导出成新的excel就可以. 当中ket ...

  2. Aspose.cell中的Excel模板导出数据

    //Excel模板导数据(Eexcel中根据DataTable中的个数,给多个Sheet中的模板赋值) public void DataSetToManyExcel(string fileName, ...

  3. 6、jeecg 笔记之 自定义excel 模板导出(一)

    1.前言 jeecg 中已经自带 excel 的导出导出功能,其所使用的是 easypoi,尽管所导出的 excel 能满足大部分需求, 但总是有需要用到自定义 excel 导出模板,下文所用到的皆是 ...

  4. C# Winform Excel的导出,根据excel模板导出数据

    namespace dxhbskymDemo { public partial class ExcelForm : DevExpress.XtraEditors.XtraForm { public E ...

  5. ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案 try.dot.net 的正确使用姿势 .Net NPOI 根据excel模板导出excel、直接生成excel .Net NPOI 上传excel文件、提交后台获取excel里的数据

    ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案   ASP.NET Core 从2.2版本开始,采用了一个新的名为Endpoint的路由方案,与原来的方案在使用上差别不 ...

  6. .Net NPOI 根据excel模板导出excel、直接生成excel

    一.根据Excel模板导出excel 1.导入NPOI.dll  2.DAL中添加类ExportExcel.cs using NPOI.SS.UserModel; using System; usin ...

  7. 用NPOI从DataTable到Excel,向Excel模板填充数据

    DataTable---->Excel,填充数据 private IWorkbook workbook = null; private ISheet sheet = null; private ...

  8. Magicodes.IE之Excel模板导出教材订购表

    说明 本教程主要说明如果使用Magicodes.IE.Excel完成教材订购表的Excel模板导出. 要点 本教程使用Magicodes.IE.Excel来完成Excel模板导出 需要通过创建Dto来 ...

  9. java实现excel模板导出

    一. 准备工作 1. 点击此下载相关开发工具 2. 将poi-3.8.jxls-core-1.0两个jar包放到工程中,并引用 3. 将excel模板runRecord.xls放到RunRecordB ...

随机推荐

  1. iosNSMutableAttributedString 简单操作

    // 打印系统中所有字体的类型名字    NSArray *familyNames = [UIFont familyNames];    for(NSString *familyName in fam ...

  2. ios可变数组的所有操作

    #pragma mark 创建数组c NSMutableArray * array =[[NSMutableArray alloc] initWithObjects:@"a",@& ...

  3. django搭建Bootstrap常用问题解决方法

    1.进入页面,提示Creating a ModelForm without either the 'fields' attribute or the 'exclude'时 解决方法:打开forms.p ...

  4. 定时执行.SH

    crontab -l 看自定义定时列表 crontab -e  编辑 */10 * * * * /bak/bak.sh10分钟执行一次 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  5. Git的Bug分支----临时保存现场git stash

    软件开发中,bug就像家常便饭一样,有了bug就需要修复,在Git中,由于分支是如此的强大,所以每个bug通过一个新的分支来修复,在修复后,合并分支,然后将临时分支删除. 当你接到一个修复代号为119 ...

  6. CTRL key

    ctrl key其实是用于扩展键盘,单独一个ctrl键没有什么作用,也没有ascii码,当与其他键相结合时,相当于创造出一个新键.例如:用getchar()侦测输入的字符,当按下ctrl+a时,只输出 ...

  7. Golang: pprof

    压测的时候,如果在应用包里加入runtime包,会对压测产生非常严重的干扰. 测试1:开启runtime包 [luwenwei@test-weishi01v ~]$ siege -c --time=1 ...

  8. PopUpManager弹出窗口

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  9. C# API 大全

    C:\ProgramFiles\MicrosoftVisual Studio .NET\ FrameworkSDK\Samples\ Technologies\ Interop\PlatformInv ...

  10. Cookie 的设置和获取

    获取:var userName = getCookieValue("userName"); 设置:setCookie("userName",equpid,24, ...