利用NPOI匯出到Excel2007

2021-06-17 17:27:59 字數 990 閱讀 7540

專案中匯出到excel2003中遇到瓶頸,因為列表資料已經超過了65535行,excel2003乙個工作表中最大只支援65535行,解決的辦法有兩個:

1,當資料超過65535行時,新建另乙個工作表,把資料寫入另外的工作表中,

下面來介紹一下匯出npoi 1.2.4 版本 匯出到excel2003和npoi 2.0 beta 1匯出excel2007的具體方法及注意事項。

引用命名空間:

using

npoi.xssf.usermodel;

using

npoi.ss.usermodel;

using

npoi.hssf.usermodel;

using system.io;

早期版本引入的命名空間:

using

npoi.hssf.usermodel;

using

npoi.ss.usermodel;

using

system.io;

using npoi.hssf.util;

親,看到**不同了嗎?

支援excel2003與支援excel2007大體類似,不同之處可以檢視官方demo,

匯出到excel中的寫法:            hssfworkbook wk = new hssfworkbook();

匯出到excel2007中的寫法:   iworkbook workbook = new xssfworkbook();

詳細見**,注意的是執行環境,在開發機器上寫demo測試通過,發布到windows server2003上就報出異常,就這麼折騰了一天,最後一步一步比較,才發現

伺服器端.net framework沒有安裝sp1,特別提醒如果是.net framewok2.0環境,一定要打上 sp1補丁。

匯出到Excel中NPOI

1 npoi 感謝tony qu分享出npoi元件的使用方法 3 net呼叫npoi元件匯入匯出excel的操作類 此npoi操作類的優點如下 1 支援web及winform從datatable匯出到excel 2 生成速度很快 3 準確判斷資料型別,不會出現身份證轉數值等問題 4 如果單頁條數大於...

c 使用NPOI匯出到excel

1 新增程式包。在專案名右鍵。選擇管理nuget程式包,瀏覽處搜尋npoi並安裝。2 引用。using system.io using system.data.sqlclient using system.diagnostics using npoi.hssf.usermodel using npo...

利用NPOI操作excel匯出

npoi外掛程式要.netframe4.0 開啟excel按鈕事件 private void button1 click object sender,eventargs e private void button2 click object sender,eventargs e if datearr...