xlsx文件可以超出,excel2003行数限制。必要的dll文件。

        public void Export()
{
string filename = Request["searchString"]; Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename+ ".xlsx")); NPOI.XSSF.UserModel.XSSFWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook();
NPOI.SS.UserModel.ISheet sheet1 = workbook.CreateSheet("BOM详情"); //给sheet1添加第一行的头部标题
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow();
row1.CreateCell().SetCellValue("物料编码");
row1.CreateCell().SetCellValue("物料名称");
row1.CreateCell().SetCellValue("规格型号");
row1.CreateCell().SetCellValue("物料用量");
row1.CreateCell().SetCellValue("用量单位");
row1.CreateCell().SetCellValue("备注");
//将数据逐步写入sheet1各个行
List<AkBom> pageResult = _akBomRepository.GetPageList(, , Request["searchString"], "");
for (int i = ; i < pageResult.Count; i++)
{
NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + );
rowtemp.CreateCell().SetCellValue(pageResult[i].ChildNumber);
rowtemp.CreateCell().SetCellValue(pageResult[i].ChildName);
rowtemp.CreateCell().SetCellValue(pageResult[i].Spec);
rowtemp.CreateCell().SetCellValue(double.Parse(pageResult[i].MaterialSum.ToString()));
rowtemp.CreateCell().SetCellValue(pageResult[i].Unit);
rowtemp.CreateCell().SetCellValue(pageResult[i].Remark);
}
//写入到客户端
System.IO.MemoryStream ms = new System.IO.MemoryStream();
workbook.Write(ms);
Response.BinaryWrite(ms.ToArray()); Response.Flush();
Response.End();
}
public void Export()
{
string searchString = Request["searchString"];
string line = Request["line"];
string station = Request["station"];
string begin = Request["begin"];
string end = Request["end"]; Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", "FQC.xlsx")); NPOI.XSSF.UserModel.XSSFWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook();
NPOI.SS.UserModel.ISheet sheet1 = workbook.CreateSheet("FQC"); //excel格式化
NPOI.SS.UserModel.ICellStyle dateStyle = workbook.CreateCellStyle();
dateStyle.DataFormat = workbook.CreateDataFormat().GetFormat("yyyy/m/d h:mm:ss"); NPOI.SS.UserModel.ICellStyle numberStyle = workbook.CreateCellStyle();
numberStyle.DataFormat = workbook.CreateDataFormat().GetFormat("0.00000"); NPOI.SS.UserModel.ICellStyle textStyle = workbook.CreateCellStyle();
textStyle.DataFormat = workbook.CreateDataFormat().GetFormat("@"); //给sheet1添加第一行的头部标题
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow();
row1.CreateCell().SetCellValue("订单号");
row1.CreateCell().SetCellValue("条码");
row1.CreateCell().SetCellValue("档位名称");
row1.CreateCell().SetCellValue("Pmax");
row1.CreateCell().SetCellValue("功率档");
row1.CreateCell().SetCellValue("功率档范围");
row1.CreateCell().SetCellValue("Ipm");
row1.CreateCell().SetCellValue("电流档");
row1.CreateCell().SetCellValue("电流档范围");
row1.CreateCell().SetCellValue("规格");
row1.CreateCell().SetCellValue("产品等级");
row1.CreateCell().SetCellValue("电池片等级");
row1.CreateCell().SetCellValue("FQC不良");
row1.CreateCell().SetCellValue("判定结果");
row1.CreateCell().SetCellValue("人员");
row1.CreateCell().SetCellValue("线别");
row1.CreateCell().SetCellValue("工位");
row1.CreateCell().SetCellValue("备注");
row1.CreateCell().SetCellValue("扫描时间");
row1.CreateCell().SetCellValue("输入时间");
row1.CreateCell().SetCellValue("Eff");
row1.CreateCell().SetCellValue("Isc");
row1.CreateCell().SetCellValue("Voc");
row1.CreateCell().SetCellValue("Rs");
row1.CreateCell().SetCellValue("Rsh");
row1.CreateCell().SetCellValue("Vpm");
row1.CreateCell().SetCellValue("FF");
row1.CreateCell().SetCellValue("Sun");
row1.CreateCell().SetCellValue("Temp");
row1.CreateCell().SetCellValue("Class");
//将数据逐步写入sheet1各个行
string strSql = "where AkFqc.BarCode like '%@param%' and (AkFqc.DateTime between '@begin' and '@end') and AkFqc.LineTitle like '%@line%' and AkFqc.StationTitle like '%@station%'";
strSql = strSql.Replace("@param", searchString);
strSql = strSql.Replace("@begin", begin);
strSql = strSql.Replace("@end", end);
strSql = strSql.Replace("@line", line);
strSql = strSql.Replace("@station", station); List<AkFqc> pageResult = _akFqcRepository.GetPageList(, , strSql, "order by AkFqc.Id desc");
for (int i = ; i < pageResult.Count; i++)
{
NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + ); rowtemp.CreateCell().SetCellValue(pageResult[i].OrderNumber);
rowtemp.CreateCell().SetCellValue(pageResult[i].BarCode);
rowtemp.CreateCell().SetCellValue(pageResult[i].Title);
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Pmax)));
rowtemp.CreateCell().SetCellValue(pageResult[i].PTitle);
rowtemp.CreateCell().SetCellValue(pageResult[i].PScope);
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Ipm)));
rowtemp.CreateCell().SetCellValue(pageResult[i].ITitle);
rowtemp.CreateCell().SetCellValue(pageResult[i].IScope);
rowtemp.CreateCell().SetCellValue(pageResult[i].Spec);
rowtemp.CreateCell().SetCellValue(pageResult[i].ProductLevel);
rowtemp.CreateCell().SetCellValue(pageResult[i].BatteryLevel);
rowtemp.CreateCell().SetCellValue(pageResult[i].BadReason);
rowtemp.CreateCell().SetCellValue(pageResult[i].JudgeResult);
rowtemp.CreateCell().SetCellValue(pageResult[i].Employee);
rowtemp.CreateCell().SetCellValue(pageResult[i].LineTitle);
rowtemp.CreateCell().SetCellValue(pageResult[i].StationTitle);
rowtemp.CreateCell().SetCellValue(pageResult[i].Remark);
rowtemp.CreateCell().SetCellValue(pageResult[i].DateTime);
rowtemp.CreateCell().SetCellValue(pageResult[i].ScanDate);
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Eff)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Isc)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Voc)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Rs)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Rsh)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Vpm)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].FF)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Sun)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Temp)));
rowtemp.CreateCell().SetCellValue(pageResult[i].Class); rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = dateStyle;
rowtemp.GetCell().CellStyle = dateStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = textStyle;
}
//写入到客户端
System.IO.MemoryStream ms = new System.IO.MemoryStream();
workbook.Write(ms);
Response.BinaryWrite(ms.ToArray()); Response.Flush();
Response.End();
}

Npoi导出xlsx的更多相关文章

  1. asp.net NPOI导出xlsx格式文件,打开文件报“Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃”

    NPOI导出xlsx格式文件,会出现如下情况: 点击“是”: 导出代码如下: /// <summary> /// 将datatable数据写入excel并下载 /// </summa ...

  2. NPOI 2.1.1 系列(1) 使用NPOI读取 Excel文档 ;NpoiExcelHelper 导入导出 2003格式 2007格式的 Excel; Npoi 导出 xlsx 格式

    下载地址 http://npoi.codeplex.com/releases 下面放一个 NPOIHelper 助手类吧,也不是我写的- NpoiExcelHelper 可以生成xlsx格式publi ...

  3. C# Aspose.Cells导出xlsx格式Excel,打开文件报“Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃”

    报错信息: 最近打开下载的 Excel,会报如下错误.(xls 格式不受影响) 解决方案: 下载代码(红色为新添代码) public void download() { string fileName ...

  4. NPOI 2.1.1 系列(2) 使用NPOI读取List或者datatable数据生成 Excel文档 ;Npoi生成 xlsx 2007以上文档

    结合上一篇文章  NPOI 2.1.1 系列(1) 使用NPOI读取 Excel文档 ;NpoiExcelHelper 导入导出 2003格式 2007格式的 Excel; Npoi 导出 xlsx ...

  5. NPOI 导出 excel 性能测试

    NPOI 导出 excel 性能测试 Intro 网上看到很多人说 NPOI 的性能不行,自己写了一个 NPOI 的扩展库,于是想尝试看看 NPOI 的性能究竟怎么样,道听途说始终不如自己动手一试. ...

  6. 基于NPOI导出和导入Excel

    概述 NPOI,顾名思义,就是POI的.NET版本.NPOI就是用.NET语言编写的一套数据导出Excel的开源项目,支持XML.xls.xlsx.ppt等格式..NET不仅实现Excel导出还可以实 ...

  7. C# NPOI导出Excel和EPPlus导出Excel比较

    系统中经常会使用导出Excel的功能. 之前使用的是NPOI,但是导出数据行数多就报内存溢出. 最近看到EPPlus可以用来导出Excel,就自己测了下两者导出上的差异. NPIO官网地址:http: ...

  8. .NET NPOI导出Excel详解

    NPOI,顾名思义,就是POI的.NET版本.那POI又是什么呢?POI是一套用Java写成的库,能够帮助开发者在没有安装微软Office的情况下读写Office的文件. 支持的文件格式包括xls, ...

  9. NPOI导出Excel(含有超过65335的处理情况)

    NPOI导出Excel的网上有很多,正好自己遇到就学习并总结了一下: 首先说明几点: 1.Excel2003及一下:后缀xls,单个sheet最大行数为65335 Excel2007 单个sheet ...

随机推荐

  1. POJ-2991 Crane(区间更新+向量旋转)

    题目大意:n个向量首尾相连,每次操作使某个区间中的所有向量都旋转同样的角度.每次操作后都回答最后一个向量的坐标. 题目分析:区间维护向量信息.向量旋转:x1=x0*cos(t)-y0*sin(t),y ...

  2. POJ-2528 Mayor's posters (线段树区间更新+离散化)

    题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...

  3. 【原创】Algorithms:原地归并排序

    第一次归并: a[0] a[1] a[2] a[3] a[4] a[5] a[6] 23 8 19 33 15 6 27 ↑             ↑ i     j 最开始i指向a[0],j指向a ...

  4. dom4j测试

    book.xml <?xml version="1.0" encoding="UTF-8"?><books><book>&l ...

  5. js定义变量需赋予初始值

    这是console.log打印出来的日志,就是多了一个undefined 日志: hitTableObjectID:undefinedbfa4be7b-32fc-459a-9092-ecde316b3 ...

  6. Oracle字符集与客户端

    http://www.linuxidc.com/Linux/2011-11/47383p2.htm 什么是Oracle字符集Oracle字符集是一个字节数据的解释的符号集合,有大小之分,有相互的包容关 ...

  7. Dubbo架构设计详解-转

    Dubbo架构设计详解  2013-09-03 21:26:59    Yanjun Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解 ...

  8. windows下android环境的搭建:完成后添加android其他版本

    JDK: jdk-6u10-rc2-bin-b32-windows-i586-p-12_sep_2008.exe Eclipse:Eclipse3.7.1 Android sdk:android-sd ...

  9. TKinter之菜单

    菜单的分类也较多,通常可以分为下拉菜单.弹出菜单. 1.使用Menu类创建一个菜单 2.add_command添加菜单项,如果该菜单是顶层菜单,则添加的菜单项依次向右添加. 如果该菜单时顶层菜单的一个 ...

  10. SQL Server锁、闩等资源的阻塞诊断---osql/sqlcmd,sp_blocker_pss80

          osql/sqlcmd 工具是一个 SqlServer的命令提示符工具,我们可以使用它运行 Transact-SQL 语句和脚本文件.该工具所在目录:C:\Program Files\Mi ...