文件名称:ASP.NET 导出Excel NPOI
文件大小:700KB
文件格式:ZIP
更新时间:2014-04-06 10:45:59
NPOI ASP.NET NPOI 导出Excel
将dll 导入程序,使用相当简单。 protected void getExcel(DataTable dt) { NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); NPOI.SS.UserModel.Sheet sheet = book.CreateSheet("table1"); NPOI.SS.UserModel.Row row = sheet.CreateRow(0); for (int i = 0; i < dt.Columns.Count; i++) { row.CreateCell(i).SetCellValue(dt.Columns[i].ColumnName); } for (int i = 0; i < dt.Rows.Count; i++) { NPOI.SS.UserModel.Row row2 = sheet.CreateRow(i + 1); for (int j = 0; j < dt.Columns.Count; j++) row2.CreateCell(j).SetCellValue(dt.Rows[i][j].ToString()); } //写入到客户端 System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); Response.AddHeader("Content-Disposition", string.Format("attachment; filename=excel.xls")); Response.BinaryWrite(ms.ToArray()); book = null; ms.Close(); ms.Dispose(); }
【文件预览】:
Ionic_Utils_Zip_license.txt
License.txt
NPOI.dll
Ionic.Zip.dll
Release Notes.txt
Read Me.txt