NPOI导出Excel(异步请求)
来源:互联网 发布:网站域名怎么续费go 编辑:程序博客网 时间:2024/04/29 23:05
1:前台JavaScript异步调用后台C#方法
<script type="javascript"> <span style="white-space:pre"></span>function ReportDepartmentExcel() { <span style="white-space:pre"></span>Ywsz.Web.Windows.WindowsCheckInfo.CreateExcel(return_Excel); } function return_Excel(res) { <span style="white-space:pre"></span>window.location = res.value; } </script>
2:后台C#方法
[AjaxPro.AjaxMethod] public string ExportExcelSample() { DataSet ds = Department_Bll.GetList(""); HSSFWorkbook hssfworkbook = new HSSFWorkbook(); HSSFSheet sheet = (HSSFSheet)hssfworkbook.CreateSheet(); for (int i = 0; i < ds.Tables[0].Rows.Count + 1; i++) { IRow row = sheet.CreateRow(i); for (int j = 0; j < 3; j++) { row.CreateCell(j); } } sheet.GetRow(0).GetCell(0).SetCellValue("部门编码"); sheet.GetRow(0).GetCell(1).SetCellValue("部门名称"); sheet.GetRow(0).GetCell(2).SetCellValue("办公号码"); for (int k = 0; k < ds.Tables[0].Rows.Count; k++) { DataRow dr = ds.Tables[0].Rows[k]; sheet.GetRow(k + 1).GetCell(0).SetCellValue(dr["DeptCode"].ToString()); sheet.GetRow(k + 1).GetCell(1).SetCellValue(dr["DeptName"].ToString()); sheet.GetRow(k + 1).GetCell(2).SetCellValue(dr["DeptTelephone"].ToString()); } //自动列宽 for (int i = 0; i < 3; i++) { int leng = 4; for (int j = 0; j < ds.Tables[0].Rows.Count + 1; j++) { ICell cell = sheet.GetRow(j).GetCell(i); if (Encoding.Default.GetBytes(cell.ToString()).Length > leng) { leng = Encoding.Default.GetBytes(cell.ToString()).Length; } } sheet.SetColumnWidth(i, (leng) * 256); } string savapath = "../Windows" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"; FileStream fileout = new FileStream(Server.MapPath(savapath), FileMode.Create); hssfworkbook.Write(fileout); fileout.Close(); fileout.Dispose(); return savapath; }
0 0
- NPOI导出Excel(异步请求)
- 导出Excel(npoi)
- Npoi导出excel整理(附源码)
- Npoi导出excel整理(附源码)
- Npoi导出excel整理(附源码)
- Npoi导出excel整理(附源码)
- NPOI导出Excel
- 利用npoi导出excel
- NPOI导出Excel
- NPOI Excel导入导出
- 使用NPOI导出EXCEL
- NPOI导出excel
- 利用npoi导出excel
- NPOI导出Excel功能
- npoi导出到EXCEL
- NPOI导出Excel
- NPOI实现EXCEL导出
- NPOI导出到Excel
- 30. Socket下载时,服务器端出错: len=10240 count=115 len=10240 count=116 len=7168 count=last java.net.SocketExc
- code vs1099 字串变化 字符串搜索(STL)
- [CSS]IE6和360浏览器兼容模式下的兼容性问题
- Python初始化实例属性
- 钱咖是什么?钱咖怎么赚钱?钱咖是真的吗?钱咖能提现吗?钱咖安全吗?
- NPOI导出Excel(异步请求)
- Socket客户端与服务端
- 带k最长上升子序列
- 常用meta整理
- ffmpeg和Opencv结合进行视频解码播放
- Eclipse 代码提示功能失效问题解决
- 【进阶android】ListView源码分析——布局三大方法
- SSH项目中向数据库写中文数据时出现乱码解决办法
- 按键码---VK_LEFT 0x4b00