1. #region Exel导出方法
  2. [MaxuniAuthAttribute(Roles = "sysroles")]
  3. public void OrderExport(string id)
  4. {
  5. string strWhere = " from VOutProceExel where OProcessRequisitionId='" + id + "'";
  6. var obj = objBaseRepository.GetOneRecord(id);//数据库,表里的信息
  7. var objlist = objVOutProceExelRepository.GetAll(strWhere);//要导出的视图信息
  8. string path = Server.MapPath("~/exceltemplate/XX合同.xls");//模板
  9. FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);//用模板导出
  10.  
  11. string suppliercontactperson1 = "";
  12. string supplierName = "";
  13. string supplierpaymentType = "";
  14. string suppliertel = "";
  15. string supplierfax = "";
  16. string supplierOrderNo = "";
  17. GetSupplierinfo(id, out suppliercontactperson1, out supplierName, out supplierpaymentType, out suppliertel, out supplierfax, out supplierOrderNo);
  18.  
  19. string CompayName = "";
  20. string address = "";
  21. string tel = "";
  22. string fax = "";
  23. string homepage = "";
  24. string email = "";
  25. GetCompanyAddres(out CompayName, out address, out tel, out fax, out homepage, out email);
  26.  
  27. IWorkbook hssfworkbook = WorkbookFactory.Create(file);//创建Execl
  28. ICellStyle style = hssfworkbook.CreateCellStyle();
  29. ISheet sheetk3 = hssfworkbook.GetSheet("inquiry");//导出的Execl里的工作表名称,一定要一致
  30.  
  31. sheetk3.DefaultColumnWidth = * ;
  32. sheetk3.DefaultRowHeightInPoints = ;
  33. sheetk3.DisplayGridlines = true;
  34.  
  35. style.BorderBottom = BorderStyle.THIN;
  36. style.BorderLeft = BorderStyle.THIN;
  37. style.BorderRight = BorderStyle.THIN;
  38. style.BorderTop = BorderStyle.THIN;
  39. int count = objlist.Count;
  40.  
  41. //
  42. IRow row1 = sheetk3.GetRow();//.GetRow(2)代表Execl模板里的行数,2代表第二行
  43. row1.GetCell().SetCellValue("甲方(委托方):XX有限公司");//.GetCell(0)代表Execl模板里的列数,0代表第一列
  44. row1.GetCell().SetCellValue(obj.contractNO);//.GetCell(5)代表Execl模板里的列数,5代表第五列
  45.  
  46. IRow row2 = sheetk3.GetRow();//代表Execl模板里的行数,3代表第三行
  47. row2.CreateCell().SetCellValue("乙方(加工方):");
  48. row2.CreateCell().SetCellValue(obj.supplierName);//
  49.  
  50. IRow row3 = sheetk3.GetRow();//.GetRow(6)代表Execl模板里的行数,6代表第6行
  51. row3.CreateCell().SetCellValue("一、内容:");
  52.  
  53. for (int i = ; i < count; i++)
  54. {
  55. IRow row = sheetk3.CreateRow( + i);//添加序列号,从第7行开始加,加到i行
  56. row.CreateCell().SetCellValue(i + );
  57. row.CreateCell().SetCellValue(objlist[i].mouldNo);
  58. row.CreateCell().SetCellValue(objlist[i].partName);
  59. row.CreateCell().SetCellValue(objlist[i].drawingNo);
  60. row.CreateCell().SetCellValue(objlist[i].OutTypeName);
  61. row.CreateCell().SetCellValue(objlist[i].qty);
  62. row.CreateCell().SetCellValue(objlist[i].processRemark);
  63. row.CreateCell().SetCellValue(objlist[i].Price);
  64. row.CreateCell().SetCellValue(objlist[i].TotaPricel);
  65. row.CreateCell().SetCellValue(objlist[i].oendDate == null ? "" : objlist[i].oendDate.Value.ToString("yyyy-MM-dd"));
  66.  
  67. row.Cells[].CellStyle = style;
  68. row.Cells[].CellStyle = style;
  69. row.Cells[].CellStyle = style;
  70. row.Cells[].CellStyle = style;
  71. row.Cells[].CellStyle = style;
  72. row.Cells[].CellStyle = style;
  73. row.Cells[].CellStyle = style;
  74. row.Cells[].CellStyle = style;
  75. row.Cells[].CellStyle = style;
  76. row.Cells[].CellStyle = style;
  77.  
  78. }
  79.  
  80. IRow row4 = sheetk3.GetRow();
  81. string strdiscount = "";
  82. if (obj.discount == )
  83. strdiscount = "";
  84. else
  85. strdiscount = "折扣:" + obj.discount + "%";
  86. row4.GetCell().SetCellValue(obj.discountPrice.ToString());
  87. row4.GetCell().SetCellValue(strdiscount);
  88.  
  89. IRow row5 = sheetk3.GetRow();
  90. row5.GetCell().SetCellValue("付款方式:" + supplierpaymentType);
  91.  
  92. IRow row6 = sheetk3.GetRow();
  93. row6.GetCell().SetCellValue(obj.outUserName);
  94.  
  95. MemoryStream ms = new MemoryStream();
  96. hssfworkbook.Write(ms);//
  97. Response.ContentType = "application/vnd.ms-excel";
  98. if (obj.contractNO == null)
  99. {
  100. Response.AddHeader("Content-Disposition", string.Format("attachment;filename=inquiry.xls"));
  101. }
  102. else
  103. {
  104. Response.AddHeader("Content-Disposition", string.Format("attachment;filename=" + obj.contractNO + ".xls"));
  105. }
  106. Response.BinaryWrite(ms.ToArray());
  107. Response.End();
  108. hssfworkbook = null;
  109. ms.Close();
  110. ms.Dispose();
  111.  
  112. }
  113. #endregion
  114.  
  115. #region 公司地址及详细信息
  116. private void GetCompanyAddres(out string CompayName, out string address, out string tel, out string fax, out string homepage, out string email)
  117. {
  118. var model = objCompayRepositoryRepository.GetAll();
  119. CompayName = "";
  120. address = "";
  121. tel = "";
  122. fax = "";
  123. homepage = "";
  124. email = "";
  125. if (model.Count > )
  126. {
  127. CompayName = model[].CompayName;
  128. address = model[].address;
  129. tel = model[].tel;
  130. fax = model[].fax;
  131. homepage = model[].homepage;
  132. email = model[].email;
  133. //ViewData["companyname"] = model[0].CompayName;
  134. //ViewData["address"] = model[0].address;
  135. //ViewData["tel"] = model[0].tel;
  136. //ViewData["fax"] = model[0].fax;
  137. //ViewData["homepage"] = model[0].homepage;
  138. //ViewData["email"] = model[0].email;
  139. }
  140. }
  141. #endregion
  142.  
  143. #region 供应商地址级详细信息 合同条约
  144.  
  145. private void GetSupplierinfo(string id, out string suppliercontactperson1, out string supplierName, out string supplierpaymentType, out string suppliertel, out string supplierfax, out string supplierOrderNo)
  146. {
  147. OProcessRequisition objOrderApply = objBaseRepository.GetOneRecord(id);
  148. string strSupplierid = objOrderApply.supplierID;
  149. Supplier objsupplier = new Supplier();
  150. if (!string.IsNullOrEmpty(strSupplierid))
  151. objsupplier = objSupplierRepository.GetOneRecord(strSupplierid);
  152.  
  153. suppliercontactperson1 = objsupplier.contactperson1;
  154. supplierName = objsupplier.supplierName;
  155. supplierpaymentType = objsupplier.paymentType + ";税率:" + objsupplier.taxRate;
  156. suppliertel = objsupplier.tel;
  157. supplierfax = objsupplier.fax;
  158. supplierOrderNo = objOrderApply.contractNO;
  159.  
  160. IList<OrderCond> objordercond = objOrderCondRepository.GetAll("from OrderCond where TypeNo=1").OrderBy(o => o.SortId).ToList();
  161. //var objplaymenthod = objordercond.FirstOrDefault(o => o.SortId ==6);
  162. //var obj = objplaymenthod;
  163. //objordercond.Remove(objplaymenthod);
  164. //obj.CondContent = objplaymenthod.CondContent.Replace(":", "").Replace(":", "") + ":" + objsupplier.paymentType + ";税率:" + objsupplier.taxRate;
  165. //objordercond.Insert(11, obj);
  166. ViewData["allcond"] = objordercond;
  167. }
  168. #endregion

Exel 利用模板导出方法的更多相关文章

  1. 使用Spire.Doc组件利用模板导出Word文档

    以前一直是用Office的组件实现Word文档导出,但是让客户在服务器安装Office,涉及到版权:而且Office安装,包括权限配置也是比较麻烦. 现在流行使用第三方组件来实现对Office的操作, ...

  2. 使用Aspose.Cells利用模板导出Excel(C#)

    前言 随着互联网的流行,web项目逐渐占据主流.我相信大部分人开发项目的过程中都写过上传以及导出Excel和Word的功能,本文仅讨论导出Excel.C#中有很多第三方组件支持导出Excel,比如:N ...

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

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

  4. java根据模板导出PDF(利用itext)

    一.制作模板     1.下载Adobe Acrobat 9 Pro软件(pdf编辑器),制作模板必须使用该工具. 2.下载itextpdf-5.5.5.jar.itext-asian-5.2.0.j ...

  5. Java利用模板生成pdf并导出

    1.准备工作 (1)Adobe Acrobat pro软件:用来制作导出模板 (2)itext的jar包 2.开始制作pdf模板 (1)先用word做出模板界面 (2)文件另存为pdf格式文件 (3) ...

  6. 利用xlst导出多表头的简便方法

    大家都知道在ASP.NET中进行表格导出有很多种办法,aspose,npoi,cvs等等,今天就来介绍xlst,导出多表头.与以往不一样的是我们利用模板,只需要在模板中定义好表格样式,然后绑定数据就可 ...

  7. java根据模板导出pdf

    在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支持模板,有的只是随便把数据放里面生成文件,完全不考虑数据怎样放置的以及以后的维护性,想想还是自己总结一个完全版的导出 ...

  8. java使用freemarker模板导出word(带有合并单元格)文档

    来自:https://blog.csdn.net/qq_33195578/article/details/73790283 前言:最近要做一个导出word功能,其实网上有很多的例子,但是我需要的是合并 ...

  9. 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的路由方案,与原来的方案在使用上差别不 ...

随机推荐

  1. linux 输入子系统(3)----事件处理(input_handler层)

    输入子系统主要设计input_dev.input_handler.input_handle.如下: [1]每个struct input_dev代表一个输入设备 struct input_dev { c ...

  2. 【BZOJ 1821】 [JSOI2010]Group 部落划分 Group

    Description 聪聪研究发现,荒岛野人总是过着群居的生活,但是,并不是整个荒岛上的所有野人都属于同一个部落,野人们总是拉帮结派形成属于自己的部落,不同的部落之间则经常发生争斗.只是,这一切都成 ...

  3. ashx与验证码

    using System; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; us ...

  4. 商品库存SKU

    一种解决方案(性能垃圾,基本实现功能)商品表  属性集表 属性表 属性值表 SKU表 SKU选项表  属性集和属性之间的中间表表关系商品表  *--------------1  属性集表属性集表 *- ...

  5. C# 写XML文件

    /// <summary>x /// 修改xml文件 /// </summary> /// <param name="dt"></para ...

  6. [scalability] Find all documents that contain a list of words

    Given a list of millions of documents, how would you find all documents that contain a list of words ...

  7. Android 如何切换到 Transform API?

    摘要: 如果你的 Android 构建中涉及到字节码插装(bytecode instrumentation),或者应用中提供了进行插装的插件,并希望它能支持 Instant Run,那么你必须切换到 ...

  8. 安装Redis完整过程

    概述    首先报告一下我系统的版本: [root@firefish init.d]# cat /etc/issue 系统版本信息如下: 引用 CentOS release 6.4 (Final) K ...

  9. Java泛型:类型擦除

    类型擦除 代码片段一 Class c1 = new ArrayList<Integer>().getClass(); Class c2 = new ArrayList<String& ...

  10. [Unity菜鸟] Unity读XML

    1. 在Unity中调试可行,发布成exe可行,发布成web不行 Application.dataPath 在Unity中调试是在“..Assets”文件夹下, 发布成exe文件是在“..yourNa ...