当前位置:网站首页>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
边栏推荐
- metric_logger小解
- C file input operation
- xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
- [error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
- Progress progress bar
- R language ggplot2 visualization: gganimate package creates dynamic histogram animation (GIF) and uses transition_ The States function displays a histogram step by step along a given dimension in the
- GMapping代码解析[通俗易懂]
- MySQL advanced learning summary 7: MySQL data structure - Comparison of hash index, AVL tree, B tree and b+ tree
- Progress-进度条
- 守望先锋世界观架构 ——(一款好的游戏是怎么来的)
猜你喜欢

Data dimensionality reduction principal component analysis

教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5

使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星

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

Why should we build an enterprise fixed asset management system and how can enterprises strengthen fixed asset management

How to copy and paste interlaced in Excel

Markdown basic grammar

高频面试题

How can retail enterprises open the second growth curve under the full link digital transformation

STM32G0 USB DFU 升级校验出错-2
随机推荐
Masa framework - DDD design (1)
Codeworks 5 questions per day (1700 average) - day 4
PHP parser badminton reservation applet development requires online system
数据降维——主成分分析
2022编译原理期末考试 回忆版
ORA-01455: converting column overflows integer datatype
R language ggplot2 visualization: gganimate package creates dynamic histogram animation (GIF) and uses transition_ The States function displays a histogram step by step along a given dimension in the
Learn the knowledge points of eight part essay ~ ~ 1
Date tool class (updated from time to time)
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
虚拟机初始化脚本, 虚拟机相互免秘钥
【JVM调优实战100例】01——JVM的介绍与程序计数器
PHP-Parser羽毛球预约小程序开发require线上系统
PHP非对称加密方法私钥及公钥加密解密的方法
数字滚动带动画
R language uses the lsnofunction function function of epidisplay package to list all objects in the current space, except user-defined function objects
STM32G0 USB DFU 升级校验出错-2
【JVM调优实战100例】02——虚拟机栈与本地方法栈调优五例
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
Why should we build an enterprise fixed asset management system and how can enterprises strengthen fixed asset management