NOPI导出加载模板

ListExcel导出(加载模板)

 1 /// <summary>
 2         /// List根据模板导出ExcelMemoryStream
 3         /// </summary>
 4         /// <param name="list"></param>
 5         /// <param name="templdateName"></param>
 6         public static MemoryStream ExportListByTempale(List<TemplateMode> list, string templdateName)
 7         {
 8             try
 9             {
10
11                 string templatePath = HttpContext.Current.Server.MapPath("/") + "/Resource/ExcelTemplate/";
12                 string templdateName1 = string.Format("{0}{1}", templatePath, templdateName);
13
14                 FileStream fileStream = new FileStream(templdateName1, FileMode.Open, FileAccess.Read);
15                 ISheet sheet = null;
16                 if (templdateName.IndexOf(".xlsx") == -1)//2003
17                 {
18                     HSSFWorkbook hssfworkbook = new HSSFWorkbook(fileStream);
19                     sheet = hssfworkbook.GetSheetAt(0);
20                     SetPurchaseOrder(sheet, list);
21                     sheet.ForceFormulaRecalculation = true;
22                     using (MemoryStream ms = new MemoryStream())
23                     {
24                         hssfworkbook.Write(ms);
25                         ms.Flush();
26                         return ms;
27                     }
28                 }
29                 else//2007
30                 {
31                     XSSFWorkbook xssfworkbook = new XSSFWorkbook(fileStream);
32                     sheet = xssfworkbook.GetSheetAt(0);
33                     SetPurchaseOrder(sheet, list);
34                     sheet.ForceFormulaRecalculation = true;
35                     using (MemoryStream ms = new MemoryStream())
36                     {
37                         xssfworkbook.Write(ms);
38                         ms.Flush();
39                         return ms;
40                     }
41                 }
42
43             }
44             catch (Exception)
45             {
46                 throw;
47             }
48         }
49         /// <summary>
50         /// 赋值单元格
51         /// </summary>
52         /// <param name="sheet"></param>
53         /// <param name="list"></param>
54         private static void SetPurchaseOrder(ISheet sheet, List<TemplateMode> list)
55         {
56             try
57             {
58                 foreach (var item in list)
59                 {
60                     IRow row = null;
61                     ICell cell = null;
62                     row = sheet.GetRow(item.row);
63                     if (row == null)
64                     {
65                         row = sheet.CreateRow(item.row);
66                     }
67                     cell = row.GetCell(item.cell);
68                     if (cell == null)
69                     {
70                         cell = row.CreateCell(item.cell);
71                     }
72                     cell.SetCellValue(item.value);
73                 }
74             }
75             catch (Exception)
76             {
77                 throw;
78             }
79         }
80         #endregion
时间: 2024-11-04 22:48:41

NOPI导出加载模板的相关文章

NOPI导出Excel

Imports System.IO Imports NPOI.HSSF.UserModel Imports NPOI.HPSF Imports NPOI.POIFS.FileSystem Imports NPOI.HSSF.Util Imports NPOI.SS.UserModel Imports NPOI.SS.Util Imports Common Public Class NopExcel Private Init_Date As String = String.Empty Privat

zepto.js按需加载模板对象

Zepto.js 是支持移动WebKit浏览器的JavaScript框架,具有与jQuery兼容的语法.2-5k的库,通过不错的API处理绝大多数的基本工作.这里要说说它的load方法,原型是: load(url, function(data, status, xhr){ ... }) ? self 其描述这样说道: Set the html contents of the current collection to the result of a GET Ajax call to the gi

WPF Excel导出加个手动修改地址

http://blog.csdn.net/sanjiawan/article/details/6818921 以上是CSDN上的WPF Excel导入导出,我看到有人提问怎么能够手动选择地址,正好用到了,就写一下. 手动选择地址需要用到SaveFileDialog 引用 using Microsoft.Win32; SaveFileDialog sfd = new SaveFileDialog(); sfd.DefaultExt = ".xlsx"; sfd.AddExtension

NOPI导出Excel 自定义列名

NOPI 做Excel 导出确实很方便 ,但是一直在用没好好研究. 在网上没找到自定义Columns的方法 ,于是乎自己就在原来的方法上简单地改改. 想用的童鞋们可以直接拿去用! 1 /// 数据大于65536时使用 2 /// </summary> 3 /// <param name="dt">数据源</param> 4 /// <param name="Columns">列名</param> 5 ///

Asp.net MVC 利用 Nopi 导出 Excel

/// <summary> /// 导出认账流水 /// </summary> /// <returns></returns> public ActionResult ExportAdmitBankTrans(BankTransQueryModel queryModel) { HSSFWorkbook workBook = new HSSFWorkbook(); ISheet sheet = workBook.CreateSheet("商务报表&q

django加载模板文件

          views.py中编写相关代码 第一种加载方式 from django.http import HttpResponsefrom django.template import loader,Context def index(req): #生成模板对象 t=loader.get_template("index.html") #生成Context对象 context = Context({}) return HttpResponse(t.render(context)

NOPI导出多个sheet,一列图片

NPOI API: http://www.cnblogs.com/atao/archive/2009/11/15/1603528.html http://blog.csdn.net/pan_junbiao/article/details/39717443 -- NPOI使用手册 http://www.cnblogs.com/wei325/p/4748324.html 每一张表只能有一个HSSFPatriarch对象,如果把它的创建放到了setPic方法中,那么一行只会出现一张图片,最后的图片会消

velocity merge作为工具类从web上下文和jar加载模板的两种常见情形

很多时候,处于各种便利性或折衷或者通用性亦或是限制的原因,会借助于模板生成结果,在此介绍两种使用velocity merge的情形,第一种是和spring mvc一样,将模板放在velocityConfigurer属性指定的路径下,如: <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <pr

NOPI 导出Excle

using System; using System.Data; using System.IO; using System.Text; using System.Web; using NPOI.HPSF; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; public class ExcelHelper { /// <summary> /// DataTable导出到Excel文件 /// </summary> /// <