private void ToExcel(HttpContext context, string TempletFileName//模版文件, string ReportFileName//导出文件, DataTable dt2) { //模板文件 //string TempletFileName = context.Server.MapPath(TempletFileName); //导出文件 //string ReportFileName = context.Server.MapPath("out.xls"); FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read); HSSFWorkbook hssfworkbook = new HSSFWorkbook(file); //XSSFWorkbook hssfworkbook = new XSSFWorkbook(file); //HSSFSheet ws = (HSSFSheet)hssfworkbook.GetSheetAt(0);//GetSheet("Sheet1"); HSSFSheet ws2 = null; int rowsCount = dt2.Rows.Count; int columnCount = dt2.Columns.Count; int num = 60000; int row = 0; if (rowsCount > 0) { int sheetCount = rowsCount > num ? (int)Math.Ceiling((double)(rowsCount / num)) : 0; for (int i = 0; i <= sheetCount; i++) { try { ws2 = (HSSFSheet)hssfworkbook.GetSheetAt(i); } catch { ws2 = (HSSFSheet)hssfworkbook.CreateSheet("Sheet" + (i + 1)); } int strRows = i * num; int endRows = num > rowsCount - (num * i) ? rowsCount : (i + 1) * num; NPOI.SS.UserModel.IRow row1 = null; for (int j = strRows; j < endRows; j++) { row++; int m = 0; if (i == 0) { m = 4; } row1 = ws2.CreateRow(row + m); row1.HeightInPoints = 25;//行高 for (int k = 0; k < columnCount; k++) { ICell cell = row1.CreateCell(k); cell.SetCellValue(dt2.Rows[j][k].ToString()); cell.CellStyle.Alignment = HorizontalAlignment.Center; } } row = 0; ws2.ForceFormulaRecalculation = true; using (FileStream fs = new FileStream(ReportFileName, FileMode.Append, FileAccess.Write)) { hssfworkbook.Write(fs); } } }










//模版文件名称 TempletFileName,
//导出文件名称 ReportFileName,
private void ToExcel(HttpContext context, string TempletFileName, string ReportFileName, DataTable dt2)
{
FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
HSSFSheet ws2 = null;
int rowsCount = dt2.Rows.Count;
int columnCount = dt2.Columns.Count;
int num = 60000;//每页数量
int row = 0;
if (rowsCount > 0)
{
int sheetCount = rowsCount > num ? (int)Math.Ceiling((double)(rowsCount / num)) : 0;
for (int i = 0; i <= sheetCount; i++)
{
try
{
ws2 = (HSSFSheet)hssfworkbook.GetSheetAt(i);
}
catch
{
ws2 = (HSSFSheet)hssfworkbook.CreateSheet("Sheet" + (i + 1));
}
int strRows = i * num;
int endRows = num > rowsCount - (num * i) ? rowsCount : (i + 1) * num;



- 粉丝: 1
- 资源: 1
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 最新版windows notepad-plus-8.5.3-installer.zip
- c语言哈夫曼树编码器,通过构建哈夫曼树来实现对数据的编码和解码
- 75滤镜特别版agc8.4v9.9_r4_lur3库超强降噪色彩细腻正式版fix2.apk
- 用MATLAB形成节点导纳矩阵(电力系统稳态分析)
- ctcdecode报错指南
- A Conceptual Introduction to Markov Chain Monte Carlo Methods
- 2_计算机应用211+202120762121+陈小宇.cdr
- Netron-Setup-7.3.1
- learning_1.cpp
- 雷达公式距离与接收功率的关系验算


