当前位置:网站首页>Npoi export Excel2007
Npoi export Excel2007
2022-07-02 19:22:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
public void Export_ProjectList(DataTable dt, HttpRequestBase Request) { string strModelFile = “”; strModelFile = Request.PhysicalApplicationPath + “ProjectList.xls”;// Template address XSSFWorkbook workbook = null; FileStream file = new FileStream(strModelFile, FileMode.Open, FileAccess.Read); workbook = new XSSFWorkbook(file);// If you export 2003 It is HSSFWorkbook HSSFSheet sheet = (HSSFSheet)workbook.GetSheet(“ProjectList”);// It can be ISheet Sheet=null; if (sheet == null) { return; } ICellStyle cellStyle = workbook.CreateCellStyle(); cellStyle.BorderBottom = BorderStyle.Thin; cellStyle.BorderLeft = BorderStyle.Thin; cellStyle.BorderRight = BorderStyle.Thin; cellStyle.BorderTop = BorderStyle.Thin; cellStyle.WrapText = true; cellStyle.Alignment = HorizontalAlignment.Center; cellStyle.VerticalAlignment = VerticalAlignment.Center;
// Set details if (dt != null && dt.Rows.Count > 0) { IRow dataRowtitle = sheet.CreateRow(0); dataRowtitle.Height = 500; dataRowtitle.CreateCell(0).SetCellValue(“ Serial number ”); dataRowtitle.CreateCell(1).SetCellValue(“ Item number ”); dataRowtitle.CreateCell(2).SetCellValue(“ Project name ”); dataRowtitle.CreateCell(3).SetCellValue(“ Project content ”); dataRowtitle.CreateCell(4).SetCellValue(“ Administrative region ”); dataRowtitle.CreateCell(5).SetCellValue(“ Affiliated branch ”); dataRowtitle.CreateCell(6).SetCellValue(“ Contacts ”); dataRowtitle.CreateCell(7).SetCellValue(“ Contact number ”);
for (int i = 0; i < dt.Rows.Count; i++) { IRow dataRow = sheet.CreateRow(i + 1); dataRow.Height = 450;
for (int j = 0; j < 8; j++) { ICell iCell = dataRow.CreateCell(j); iCell.CellStyle = cellStyle; switch (j) { case 0: iCell.SetCellValue(i + 1);// Serial number break; case 1: iCell.SetCellValue(dt.Rows[i][“PROJECTCODE”] == null ? “” : String.Format(“{0:d}”, dt.Rows[i][“PROJECTCODE”]));// Item number break; case 2: iCell.SetCellValue(dt.Rows[i][“NAME”].ToString());// Project name break; case 3: iCell.SetCellValue(dt.Rows[i][“CONTENT”].ToString());// Project content break; case 4: iCell.SetCellValue(GetListName(GFun.SafeToInt32(dt.Rows[i][“DISTRICT”])));// Administrative region break; case 5: iCell.SetCellValue(GetListName(GFun.SafeToInt32(dt.Rows[i][“BRANCH”])));// Affiliated branch break; case 6: iCell.SetCellValue(dt.Rows[i][“CONTACTS”].ToString());// Contacts break; case 7: iCell.SetCellValue(dt.Rows[i][“PHONENUM”].ToString());// Contact number break; }
} } } string fileName = string.Empty; //sheet.GetRow(0).GetCell(0).SetCellValue(“ Project information ”);// title SetExportFileName(fileName + “ Query result export .xlsx”, workbook); } public static void SetExportFileName(string sFileName, XSSFWorkbook workbook) { System.Web.HttpContext.Current.Response.Charset = “GB2312”; System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; sFileName = System.Web.HttpUtility.UrlEncode(sFileName, System.Text.Encoding.UTF8); // Add header information , by ” File download / Save as ” Dialog box specifies the default file name System.Web.HttpContext.Current.Response.AddHeader(“Content-Disposition”, “attachment; filename=” + sFileName);
// Specifies that the returned stream is a stream that cannot be read by the client , Must be downloaded System.Web.HttpContext.Current.Response.ContentType = “application/ms-Excel”;
// Send the file stream to the client workbook.Write(System.Web.HttpContext.Current.Response.OutputStream); // Stop page execution System.Web.HttpContext.Current.Response.End(); }
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/148598.html Link to the original text :https://javaforall.cn
边栏推荐
- "Patient's family, please come here" reading notes
- metric_logger小解
- 【JVM调优实战100例】03——JVM堆调优四例
- Learn the knowledge points of eight part essay ~ ~ 1
- PyTorch函数中的__call__和forward函数
- mybatiesHelperPro工具必须的可以生成到对应项目文件夹下
- 2022软件工程期末考试 回忆版
- 思维意识转变是施工企业数字化转型成败的关键
- R language uses lrtest function of epidisplay package to perform likelihood ratio test on multiple GLM models (logisti regression). Compare whether the performance of the two models is different, and
- C文件输入操作
猜你喜欢

云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统

为什么要做企业固定资产管理系统,企业如何加强固定资产管理

使用CLion编译OGLPG-9th-Edition源码

医院在线问诊源码 医院视频问诊源码 医院小程序源码

Yunna | why use the fixed asset management system and how to enable it

Markdown基础语法

IEDA refactor的用法

思维意识转变是施工企业数字化转型成败的关键

Data dimensionality reduction principal component analysis
![[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter](/img/c4/3bba96fda92328704c2ddd929dcdf6.png)
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter
随机推荐
According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
QT中的QPropertyAnimation使用和toast案列
Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
[论文阅读] CA-Net: Leveraging Contextual Features for Lung Cancer Prediction
Fastdfs installation
2022软件工程期末考试 回忆版
性能测试如何创造业务价值
mysql备份后缀是什么_mysql备份还原
High frequency interview questions
Use cheat engine to modify money, life and stars in Kingdom rush
Date tool class (updated from time to time)
Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5
【JVM调优实战100例】02——虚拟机栈与本地方法栈调优五例
Mysql高级篇学习总结8:InnoDB数据存储结构页的概述、页的内部结构、行格式
使用xml文件打印mybaties-log插件的方式
golang:[]byte转string
【测试开发】一文带你了解什么是软件测试
PHP非对称加密方法私钥及公钥加密解密的方法
Learning summary of MySQL advanced 6: concept and understanding of index, detailed explanation of b+ tree generation process, comparison between MyISAM and InnoDB