上個月正好做導出數據這塊,可以先把數據賦予於壹張自定義Datatable表裏面,再用NPOI第三方控件導出來更方便,而且也不存在引用office時引起的安全簽名問題。
調用代碼:
public void OutToExcel(DataTable tb,string filename)
{
NPOIHelper myhelper = new NPOIHelper();
byte[] data = myhelper.DataTable2Excel(tb, filename);
string path = wenjianlujing;//存放路徑
FileStream fs = new FileStream(path, FileMode.CreateNew);
fs.Write(data, 0, data.Length);
fs.Close();
GC.Collect();
}