using System;
using System.Text;
using System.IO;
using NPOI.HSSF;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using NPOI.POIFS.FileSystem;
using NPOI.SS.UserModel;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
protected void Button4_Click(object sender, EventArgs e)
{
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
HSSFSheet sheet1 = hssfworkbook.CreateSheet("Sheet1") as HSSFSheet;
HSSFCellStyle style1 = hssfworkbook.CreateCellStyle() as HSSFCellStyle;
MemoryStream ms = new MemoryStream();
style1.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Blue.Index;
style1.FillPattern = FillPattern.BigSpots;
style1.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Pink.Index;
sheet1.CreateRow(0).CreateCell(0).CellStyle = style1;
string fileName = "Excel_" + DateTime.Now.ToShortDateString() + "_" + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".xls";
Response.AddHeader("Content-Disposition", String.Format("attachment;filename=" + fileName));
hssfworkbook.Write(ms);
Response.BinaryWrite(ms.ToArray());
hssfworkbook = null;
ms.Close();
ms.Dispose();
}
請先 登入 以發表留言。