当前位置:网站首页>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
边栏推荐
- 2022.7.1-----leetcode. two hundred and forty-one
- Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
- Progress-进度条
- golang:[]byte转string
- juypter notebook 修改默认打开文件夹以及默认浏览器
- How to copy and paste interlaced in Excel
- 论文导读 | 关于将预训练语言模型作为知识库的分析与批评
- 新手必看,點擊兩個按鈕切換至不同的內容
- C的内存管理
- Excel finds the same value in a column, deletes the row or replaces it with a blank value
猜你喜欢

开发固定资产管理系统,开发固定资产管理系统用什么语音

Juypter notebook modify the default open folder and default browser

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

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

Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径

9D电影是怎样的?(+维度空间常识)

新手必看,点击两个按钮切换至不同的内容

Develop fixed asset management system, what voice is used to develop fixed asset management system

【测试开发】软件测试—概念篇

Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
随机推荐
Excel finds the same value in a column, deletes the row or replaces it with a blank value
【测试开发】一文带你了解什么是软件测试
Markdown basic grammar
#gStore-weekly | gStore源码解析(四):安全机制之黑白名单配置解析
开发固定资产管理系统,开发固定资产管理系统用什么语音
Gstore weekly gstore source code analysis (4): black and white list configuration analysis of security mechanism
性能测试如何创造业务价值
"Patient's family, please come here" reading notes
R language uses the lsnofunction function function of epidisplay package to list all objects in the current space, except user-defined function objects
Imitation Jingdong magnifying glass effect (pink teacher version)
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
Progress progress bar
[0701] [paper reading] allowing data imbalance issue with perforated input during influence
Markdown基础语法
Date tool class (updated from time to time)
新手必看,點擊兩個按鈕切換至不同的內容
Juypter notebook modify the default open folder and default browser
Processing strategy of message queue message loss and repeated message sending
Learn the knowledge points of eight part essay ~ ~ 1
[test development] takes you to know what software testing is