using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using NPOI.HSSF;
using NPOI.HSSF.UserModel;
using NPOI.POIFS.FileSystem;
public partial class d14 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
HSSFWorkbook workbook = new HSSFWorkbook();
MemoryStream ms = new MemoryStream();
workbook.CreateSheet("試算表 SheetA");
workbook.CreateSheet("試算表 SheetB");
workbook.CreateSheet("試算表 SheetC");
workbook.Write(ms);
Response.AddHeader("Content-Disposition", String.Format("attachment;filename=EmptyWorkbook_1.xls"));
Response.BinaryWrite(ms.ToArray());
workbook = null;
ms.Close();
ms.Dispose();
}
protected void Button2_Click(object sender, EventArgs e)
{
HSSFWorkbook wb = new HSSFWorkbook();
MemoryStream ms = new MemoryStream();
HSSFSheet ns = (HSSFSheet) wb.CreateSheet("mySheet");
ns.CreateRow(0).CreateCell(0).SetCellValue("0000");
ns.CreateRow(1).CreateCell(0).SetCellValue("1111");
ns.CreateRow(2).CreateCell(0).SetCellValue("2222");
ns.CreateRow(3).CreateCell(0).SetCellValue("3333");
ns.CreateRow(4).CreateCell(0).SetCellValue("4444");
ns.CreateRow(6).CreateCell(3).SetCellValue("7777");
wb.Write(ms);
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));
Response.BinaryWrite(ms.ToArray());
wb = null;
ms.Close();
ms.Dispose();
}
}
留言列表