c# - Does NPOI have support to .xlsx format? -
will npoi dll recognize .xlsx
file?
currently i'm using npoi 1.2.5 version dll microsoft excel 97-2003, need access excel sheets of extension .xlsx
also.
will npoi support above?
code snippet:
static void main(string[] args) { xssfworkbook xssfwb; using(filestream file=new filestream( @"c:\users\347702\desktop\hello.xlsx", filemode.open, fileaccess.read)) { xssfwb=new xssfworkbook(file); } isheet sheet=xssfwb.getsheet("sheet1"); sheet.getrow(1048576); console.writeline(sheet.getrow(1048576).getcell(0).stringcellvalue); }
yes does. npoi 2.0 beta works. here's sample code started:
class program { static xssfworkbook hssfworkbook; static dataset dataset1 = new dataset(); static void main(string[] args) { initializeworkbook(@"e:\docs\hourswidget_rtm.xlsx"); xlsxtodt(); displaydata(dataset1.tables[0]); console.readline(); } static void initializeworkbook(string path) { using (filestream file = new filestream(path, filemode.open, fileaccess.read)) { hssfworkbook = new xssfworkbook(file); } } static void xlsxtodt() { datatable dt = new datatable(); isheet sheet = hssfworkbook.getsheetat(1); irow headerrow = sheet.getrow(0); ienumerator rows = sheet.getrowenumerator(); int colcount = headerrow.lastcellnum; int rowcount = sheet.lastrownum; (int c = 0; c < colcount; c++) { dt.columns.add(headerrow.getcell(c).tostring()); } bool skipreadingheaderrow = rows.movenext(); while (rows.movenext()) { irow row = (xssfrow)rows.current; datarow dr = dt.newrow(); (int = 0; < colcount; i++) { icell cell = row.getcell(i); if (cell != null) { dr[i] = cell.tostring(); } } dt.rows.add(dr); } hssfworkbook = null; sheet = null; dataset1.tables.add(dt); } static void displaydata(datatable table) { foreach (datarow row in table.rows) { foreach (datacolumn col in table.columns) { console.writeline("{0} = {1}", col.columnname, row[col]); } console.writeline("-------------------------------------------"); } } }
Comments
Post a Comment