Exel 利用模板导出方法
- #region Exel导出方法
- [MaxuniAuthAttribute(Roles = "sysroles")]
- public void OrderExport(string id)
- {
- string strWhere = " from VOutProceExel where OProcessRequisitionId='" + id + "'";
- var obj = objBaseRepository.GetOneRecord(id);//数据库,表里的信息
- var objlist = objVOutProceExelRepository.GetAll(strWhere);//要导出的视图信息
- string path = Server.MapPath("~/exceltemplate/XX合同.xls");//模板
- FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);//用模板导出
- string suppliercontactperson1 = "";
- string supplierName = "";
- string supplierpaymentType = "";
- string suppliertel = "";
- string supplierfax = "";
- string supplierOrderNo = "";
- GetSupplierinfo(id, out suppliercontactperson1, out supplierName, out supplierpaymentType, out suppliertel, out supplierfax, out supplierOrderNo);
- string CompayName = "";
- string address = "";
- string tel = "";
- string fax = "";
- string homepage = "";
- string email = "";
- GetCompanyAddres(out CompayName, out address, out tel, out fax, out homepage, out email);
- IWorkbook hssfworkbook = WorkbookFactory.Create(file);//创建Execl
- ICellStyle style = hssfworkbook.CreateCellStyle();
- ISheet sheetk3 = hssfworkbook.GetSheet("inquiry");//导出的Execl里的工作表名称,一定要一致
- sheetk3.DefaultColumnWidth = * ;
- sheetk3.DefaultRowHeightInPoints = ;
- sheetk3.DisplayGridlines = true;
- style.BorderBottom = BorderStyle.THIN;
- style.BorderLeft = BorderStyle.THIN;
- style.BorderRight = BorderStyle.THIN;
- style.BorderTop = BorderStyle.THIN;
- int count = objlist.Count;
- //
- IRow row1 = sheetk3.GetRow();//.GetRow(2)代表Execl模板里的行数,2代表第二行
- row1.GetCell().SetCellValue("甲方(委托方):XX有限公司");//.GetCell(0)代表Execl模板里的列数,0代表第一列
- row1.GetCell().SetCellValue(obj.contractNO);//.GetCell(5)代表Execl模板里的列数,5代表第五列
- IRow row2 = sheetk3.GetRow();//代表Execl模板里的行数,3代表第三行
- row2.CreateCell().SetCellValue("乙方(加工方):");
- row2.CreateCell().SetCellValue(obj.supplierName);//
- IRow row3 = sheetk3.GetRow();//.GetRow(6)代表Execl模板里的行数,6代表第6行
- row3.CreateCell().SetCellValue("一、内容:");
- for (int i = ; i < count; i++)
- {
- IRow row = sheetk3.CreateRow( + i);//添加序列号,从第7行开始加,加到i行
- row.CreateCell().SetCellValue(i + );
- row.CreateCell().SetCellValue(objlist[i].mouldNo);
- row.CreateCell().SetCellValue(objlist[i].partName);
- row.CreateCell().SetCellValue(objlist[i].drawingNo);
- row.CreateCell().SetCellValue(objlist[i].OutTypeName);
- row.CreateCell().SetCellValue(objlist[i].qty);
- row.CreateCell().SetCellValue(objlist[i].processRemark);
- row.CreateCell().SetCellValue(objlist[i].Price);
- row.CreateCell().SetCellValue(objlist[i].TotaPricel);
- row.CreateCell().SetCellValue(objlist[i].oendDate == null ? "" : objlist[i].oendDate.Value.ToString("yyyy-MM-dd"));
- row.Cells[].CellStyle = style;
- row.Cells[].CellStyle = style;
- row.Cells[].CellStyle = style;
- row.Cells[].CellStyle = style;
- row.Cells[].CellStyle = style;
- row.Cells[].CellStyle = style;
- row.Cells[].CellStyle = style;
- row.Cells[].CellStyle = style;
- row.Cells[].CellStyle = style;
- row.Cells[].CellStyle = style;
- }
- IRow row4 = sheetk3.GetRow();
- string strdiscount = "";
- if (obj.discount == )
- strdiscount = "";
- else
- strdiscount = "折扣:" + obj.discount + "%";
- row4.GetCell().SetCellValue(obj.discountPrice.ToString());
- row4.GetCell().SetCellValue(strdiscount);
- IRow row5 = sheetk3.GetRow();
- row5.GetCell().SetCellValue("付款方式:" + supplierpaymentType);
- IRow row6 = sheetk3.GetRow();
- row6.GetCell().SetCellValue(obj.outUserName);
- MemoryStream ms = new MemoryStream();
- hssfworkbook.Write(ms);//
- Response.ContentType = "application/vnd.ms-excel";
- if (obj.contractNO == null)
- {
- Response.AddHeader("Content-Disposition", string.Format("attachment;filename=inquiry.xls"));
- }
- else
- {
- Response.AddHeader("Content-Disposition", string.Format("attachment;filename=" + obj.contractNO + ".xls"));
- }
- Response.BinaryWrite(ms.ToArray());
- Response.End();
- hssfworkbook = null;
- ms.Close();
- ms.Dispose();
- }
- #endregion
- #region 公司地址及详细信息
- private void GetCompanyAddres(out string CompayName, out string address, out string tel, out string fax, out string homepage, out string email)
- {
- var model = objCompayRepositoryRepository.GetAll();
- CompayName = "";
- address = "";
- tel = "";
- fax = "";
- homepage = "";
- email = "";
- if (model.Count > )
- {
- CompayName = model[].CompayName;
- address = model[].address;
- tel = model[].tel;
- fax = model[].fax;
- homepage = model[].homepage;
- email = model[].email;
- //ViewData["companyname"] = model[0].CompayName;
- //ViewData["address"] = model[0].address;
- //ViewData["tel"] = model[0].tel;
- //ViewData["fax"] = model[0].fax;
- //ViewData["homepage"] = model[0].homepage;
- //ViewData["email"] = model[0].email;
- }
- }
- #endregion
- #region 供应商地址级详细信息 合同条约
- private void GetSupplierinfo(string id, out string suppliercontactperson1, out string supplierName, out string supplierpaymentType, out string suppliertel, out string supplierfax, out string supplierOrderNo)
- {
- OProcessRequisition objOrderApply = objBaseRepository.GetOneRecord(id);
- string strSupplierid = objOrderApply.supplierID;
- Supplier objsupplier = new Supplier();
- if (!string.IsNullOrEmpty(strSupplierid))
- objsupplier = objSupplierRepository.GetOneRecord(strSupplierid);
- suppliercontactperson1 = objsupplier.contactperson1;
- supplierName = objsupplier.supplierName;
- supplierpaymentType = objsupplier.paymentType + ";税率:" + objsupplier.taxRate;
- suppliertel = objsupplier.tel;
- supplierfax = objsupplier.fax;
- supplierOrderNo = objOrderApply.contractNO;
- IList<OrderCond> objordercond = objOrderCondRepository.GetAll("from OrderCond where TypeNo=1").OrderBy(o => o.SortId).ToList();
- //var objplaymenthod = objordercond.FirstOrDefault(o => o.SortId ==6);
- //var obj = objplaymenthod;
- //objordercond.Remove(objplaymenthod);
- //obj.CondContent = objplaymenthod.CondContent.Replace(":", "").Replace(":", "") + ":" + objsupplier.paymentType + ";税率:" + objsupplier.taxRate;
- //objordercond.Insert(11, obj);
- ViewData["allcond"] = objordercond;
- }
- #endregion
Exel 利用模板导出方法的更多相关文章
- 使用Spire.Doc组件利用模板导出Word文档
以前一直是用Office的组件实现Word文档导出,但是让客户在服务器安装Office,涉及到版权:而且Office安装,包括权限配置也是比较麻烦. 现在流行使用第三方组件来实现对Office的操作, ...
- 使用Aspose.Cells利用模板导出Excel(C#)
前言 随着互联网的流行,web项目逐渐占据主流.我相信大部分人开发项目的过程中都写过上传以及导出Excel和Word的功能,本文仅讨论导出Excel.C#中有很多第三方组件支持导出Excel,比如:N ...
- Magicodes.IE之Excel模板导出教材订购表
说明 本教程主要说明如果使用Magicodes.IE.Excel完成教材订购表的Excel模板导出. 要点 本教程使用Magicodes.IE.Excel来完成Excel模板导出 需要通过创建Dto来 ...
- java根据模板导出PDF(利用itext)
一.制作模板 1.下载Adobe Acrobat 9 Pro软件(pdf编辑器),制作模板必须使用该工具. 2.下载itextpdf-5.5.5.jar.itext-asian-5.2.0.j ...
- Java利用模板生成pdf并导出
1.准备工作 (1)Adobe Acrobat pro软件:用来制作导出模板 (2)itext的jar包 2.开始制作pdf模板 (1)先用word做出模板界面 (2)文件另存为pdf格式文件 (3) ...
- 利用xlst导出多表头的简便方法
大家都知道在ASP.NET中进行表格导出有很多种办法,aspose,npoi,cvs等等,今天就来介绍xlst,导出多表头.与以往不一样的是我们利用模板,只需要在模板中定义好表格样式,然后绑定数据就可 ...
- java根据模板导出pdf
在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支持模板,有的只是随便把数据放里面生成文件,完全不考虑数据怎样放置的以及以后的维护性,想想还是自己总结一个完全版的导出 ...
- java使用freemarker模板导出word(带有合并单元格)文档
来自:https://blog.csdn.net/qq_33195578/article/details/73790283 前言:最近要做一个导出word功能,其实网上有很多的例子,但是我需要的是合并 ...
- 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的路由方案,与原来的方案在使用上差别不 ...
随机推荐
- linux 输入子系统(3)----事件处理(input_handler层)
输入子系统主要设计input_dev.input_handler.input_handle.如下: [1]每个struct input_dev代表一个输入设备 struct input_dev { c ...
- 【BZOJ 1821】 [JSOI2010]Group 部落划分 Group
Description 聪聪研究发现,荒岛野人总是过着群居的生活,但是,并不是整个荒岛上的所有野人都属于同一个部落,野人们总是拉帮结派形成属于自己的部落,不同的部落之间则经常发生争斗.只是,这一切都成 ...
- ashx与验证码
using System; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; us ...
- 商品库存SKU
一种解决方案(性能垃圾,基本实现功能)商品表 属性集表 属性表 属性值表 SKU表 SKU选项表 属性集和属性之间的中间表表关系商品表 *--------------1 属性集表属性集表 *- ...
- C# 写XML文件
/// <summary>x /// 修改xml文件 /// </summary> /// <param name="dt"></para ...
- [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 ...
- Android 如何切换到 Transform API?
摘要: 如果你的 Android 构建中涉及到字节码插装(bytecode instrumentation),或者应用中提供了进行插装的插件,并希望它能支持 Instant Run,那么你必须切换到 ...
- 安装Redis完整过程
概述 首先报告一下我系统的版本: [root@firefish init.d]# cat /etc/issue 系统版本信息如下: 引用 CentOS release 6.4 (Final) K ...
- Java泛型:类型擦除
类型擦除 代码片段一 Class c1 = new ArrayList<Integer>().getClass(); Class c2 = new ArrayList<String& ...
- [Unity菜鸟] Unity读XML
1. 在Unity中调试可行,发布成exe可行,发布成web不行 Application.dataPath 在Unity中调试是在“..Assets”文件夹下, 发布成exe文件是在“..yourNa ...