NPOI学习札记
NPOI教程:http://www.cnblogs.com/tonyqus/archive/2009/04/12/1434209.html
http://www.cnblogs.com/zplutor/archive/2009/07/31/1536146.html
http://www.cnblogs.com/vihone/archive/2010/06/04/1751490.html session问题
小键盘方向键
4 = 100
2 = 98
6 = 102
8 = 104
Session丢失的解决办法小结
http://jhxk.iteye.com/blog/458559
DataTable dt = new DataTable();
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = order_field;
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
dt.Columns.Add(column);
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using NPOI;
using NPOI.HPSF;
using NPOI.HSSF;
using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using NPOI.POIFS;
using NPOI.Util;
using System.Data.SqlClient;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
DataSet DS = new DataSet();
string connectStr = "Server=MUYE-PC\\STANDY;Database=TESTED;Uid=sa;Pwd=muye";
SqlConnection conn = new SqlConnection(connectStr);
string sql = "select * from test";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(DS);
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("工作表名稱");
//顯示 Table 0 的所有欄位名稱
HSSFRow headerRow = (HSSFRow)sheet.CreateRow(0);
foreach (DataColumn column in DS.Tables[0].Columns)
{
headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
}
//顯示 所有資料列
int rowIndex = 1;
foreach (DataRow row in DS.Tables[0].Rows)
{
HSSFRow dataRow = (HSSFRow)sheet.CreateRow(rowIndex);
foreach (DataColumn column in DS.Tables[0].Columns)
{
dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());
}
dataRow = null;
rowIndex++;
}
Response.Clear();
// 產生 Excel 資料流
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
headerRow = null;
sheet = null;
workbook = null;
// 設定強制下載標頭
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=Download.xls"));
// 輸出檔案
Response.BinaryWrite(ms.ToArray());
ms.Close();
ms.Dispose();
Response.End();
}
}