Saturday 15 June 2013

excel - EPPlus File Load Issue with Mono -



excel - EPPlus File Load Issue with Mono -

i using below code reading excel file datatable epplus library:

public static datatable getdatatablefromexcel(string path) { datatable tbl = new datatable(); using (var pck = new excelpackage()) { using (var stream = file.openread(path)) { pck.load(stream); } //get first sheet in excel file var ws = pck.workbook.worksheets.first(); bool hasheader = true; // adjust accordingly( i've mentioned simple approach) //add columns (schema) datatable foreach (var firstrowcell in ws.cells[1, 1, 1, ws.dimension.end.column]) { tbl.columns.add(hasheader ? firstrowcell.text : string.format("column {0}", firstrowcell.start.column)); } //if excel sheet has first row column names start 2nd row else first row var startrow = hasheader ? 2 : 1; (var rownum = startrow; rownum <= ws.dimension.end.row; rownum++) { //ws.cells[rownum, 1, rownum, ws.dimension.end.column].style.numberformat.format = "general"; var wsrow = ws.cells[rownum, 1, rownum, ws.dimension.end.column]; var row = tbl.newrow(); foreach (var cell in wsrow) { if (cell.start.column > 20) continue; if (cell.start.column == 20) { datetime dt = new datetime(1947, 1, 1); datetime.tryparse(cell.value.tostring(), out dt); if (dt == new datetime(0001, 1, 1)) { long serialdate = long.parse(cell.value.tostring()); datetime result = datetime.fromoadate(serialdate); row[cell.start.column - 1] = result.tostring(); } else row[cell.start.column - 1] = cell.value; } else row[cell.start.column - 1] = cell.text; } tbl.rows.add(row); } } homecoming tbl; }

in aplication select excel file , using epplus convert excel datatable , datatable loaded in gridview if select new file- above method called , info loaded in gridview.

but not work on mono. works in .net same code when select different file browse button first file gets load 1 time again , again. load new file have close application , run again.

is there wrong method code? need close/unload excel in ep code somewhere?

regards,

thank much reply. got issue. using app.config file , modifying @ runtime save file path , path app.config load file grid. new changes in app.config have reload application.

excel mono epplus

No comments:

Post a Comment