#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 利用模板导出方法的更多相关文章

  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. php header头信息 举例

    发布:sunday01   来源:Net     [大 中 小] 转自:http://www.jbxue.com/article/6915.html 用于演示PHP header()函数用法的代码,介 ...

  2. push notification for iphone

    由于公司业务需求,以前一直做PHP开发,突然让我研究push notification ,一下子迷糊啦,不知所措,抓狂!但是在自己的努力下还是初有成效!现拿出来显摆一下! 1:push notific ...

  3. PHP实现冒泡算法

    <?php //php函数:count($arr)返回array的数值总数. function bubble_sort($arr){ for ($i = 6;$i > 0;$i --){ ...

  4. 这个SpringMVC的一直刷屏的问题你见过吗?无解

    严重: Servlet.service() for servlet DispatcherServlet threw exceptionjava.lang.StackOverflowError at o ...

  5. SpotLight的下载地址以及注册码可供参考

    ToadDBASuiteforOracle_101R2.exe 试用版http://worlddownloads.quest.com.edgesuite.net/Repository/www.ques ...

  6. HDU 1159

    Description A subsequence of a given sequence is the given sequence with some elements (possible non ...

  7. Hadoop 相关链接

    Apache   软件下载 http://mirror.bit.edu.cn/apache/ 相关文档链接: Apache Hadoop 2.5.2  http://hadoop.apache.org ...

  8. 使用泛型 类型“System.Collections.Generic.IEnumerator<T>”需要 1 个类型参数

    解决办法:添加 using System.Collections:命名空间

  9. asp 回发的时候样式变化

    在一个按钮确定后弹出一个提示框,在提示框没有关闭时有时会发现页面的样式发生变化. 解决方法: 在DIV外增加,<table><tr><td align="lef ...

  10. xcode 6.3 打包crash问题--参考

    xcode升级6.3之后,有些项目会出现打包crash的问题,只要选择偏好设置,把source control全部禁用掉就可以了.