NPOI 建立Excel,資料讀取與寫入

2021-06-23 05:09:45 字數 2474 閱讀 4909

namespace 匯入匯出excel

//------------------------------------------讀取excel的資料-------------

using (stream stream1 = file.openread("d:/excel.xls"))

else}}

//-----------------建立乙個新的excel檔案 workbook2工作薄,並將workbook的內容複製到workbook2中---------------------

hssfworkbook workbook2 = new hssfworkbook();//建立乙個workbook2工作薄,其實就是我們常說的excel檔案

isheet sheet2 = workbook2.createsheet("sheet1");//為workbook2工作建立乙個sheet1頁

//根據sheet頁的總行數,來建立sheet2頁的總行數

for (int i = 0; i <= cellrows; i++)

else

//根據shee1頁的總列數,建立shee2頁的總列數

for (int j = 0; j < maxcellcount; j++)

if (cell.celltype == celltype.numeric) //如果資料來源的當前格的型別為numeric型別}}

}//開打指定路徑下的檔案,如果檔案不存在則建立檔案,並開啟,以進行寫入

using (stream stream = file.openwrite("d:/excel2.xls"))

context.response.write("ok"); //提示ok}}

public bool isreusable}}

}

using system;

using system.collections.generic;

using system.linq;

using system.web;

using npoi.hssf.usermodel;

using npoi.ss.usermodel;

using npoi.ss.formula.functions;

using system.io;

using system.text;

namespace 匯入匯出excel

//------------------------------------------讀取excel的資料-------------

using (stream stream1 = file.openread("d:/excel.xls"))

else}}

//-----------------建立乙個新的excel檔案 workbook2工作薄,並將workbook的內容複製到workbook2中---------------------

hssfworkbook workbook2 = new hssfworkbook();//建立乙個workbook2工作薄,其實就是我們常說的excel檔案

isheet sheet2 = workbook2.createsheet("sheet1");//為workbook2工作建立乙個sheet1頁

//根據sheet頁的總行數,來建立sheet2頁的總行數

for (int i = 0; i <= cellrows; i++)

else

//根據shee1頁的總列數,建立shee2頁的總列數

for (int j = 0; j < maxcellcount; j++)

if (cell.celltype == celltype.numeric) //如果資料來源的當前格的型別為numeric型別}}

}//開打指定路徑下的檔案,如果檔案不存在則建立檔案,並開啟,以進行寫入

//using (stream stream = file.openwrite("d:/excel2.xls"))

//context.response.write("ok"); //提示ok}}

public bool isreusable}}

}

NPOI讀取Excel資料應用

npoi 是 poi專案的 net 版本。使用 npoi 你就可以在沒有安裝 office 或者相應環境的機器上對 word excel 文件進行讀寫。npoi 是構建在 poi 3.x 版本之上的,它可以在沒有安裝 office 的情況下對 word excel 文件進行讀寫操作。需求 根據exc...

NPOI 讀取 excel通用類

using system using system.collections.generic using system.text using system.io using system.data using npoi.hssf.usermodel using npoi.ss.usermodel na...

使用NPOI讀取Excel資料並寫入SQLite

首先,我們來建乙個資料庫,我們就叫hello.db 不一定是db字尾,你可以sqlite,sqlite3,db3 都可以作為識別,然後往裡面建乙個空的 如下圖所示 然後建乙個excel 往 裡面寫入一些資料,我這裡只是demo形式,可以根據自己的實際情況,稍作修改 然後開始建乙個新的專案,我這裡用的...