c# - When I click anywhere in my excel doc, while exporting data to that doc, it will throw: Exception from HRESULT: 0x800AC472 -
so code making excel document , loading lists in different sheets. now, whenever click on random cell stop loading data , give me expection: exception hresult: 0x800ac472
in visual studio. now, when press start debugging(f5)
again finish excel doc , filling in rest of data. how can possibly fix this?
exceldatahandler.excel_create("c:\\users\\me\\desktop\\testmap\\testno3.xlsx"); (int = 0; < listoflists.count; i++) { (int j = 1; j <= listoflists[i].count; j++) { exceldatahandler.excel_setvalue("b" + j, listoflists[i][j-1], (i+1)); } } exceldatahandler.excel_close("c:\\users\\me\\desktop\\testmap\\testno3.xlsx");
exceldatahandler:
private static microsoft.office.interop.excel.applicationclass appexcel; private static workbook newworkbook_first = null; private static _worksheet objsheet = null; private static _worksheet newsheets = null; ' public void excel_create(string path) { try { appexcel = new microsoft.office.interop.excel.applicationclass(); appexcel.visible = true; newworkbook_first = appexcel.workbooks.add(1); newsheets = (microsoft.office.interop.excel._worksheet)newworkbook_first.sheets.add(type.missing, type.missing, 30, type.missing); } catch (exception e) { console.write("error"); } { } } public void excel_setvalue(string cellname, string value, int worksheet) { //error in line below ((microsoft.office.interop.excel._worksheet)newworkbook_first.sheets[worksheet]).get_range(cellname).set_value(type.missing, value); } public void excel_close(string save) { if (save == "") { } else { newworkbook_first.saveas(save); } if (appexcel != null) { try { newworkbook_first.close(); // system.runtime.interopservices.marshal.releasecomobject(appexcel.activeworkbook.activesheet); // system.runtime.interopservices.marshal.releasecomobject(appexcel.activeworkbook); system.runtime.interopservices.marshal.releasecomobject(appexcel); appexcel = null; objsheet = null; } catch (exception ex) { appexcel = null; console.writeline("unable release object " + ex.tostring()); } { gc.collect(); } } }
i tried this: (microsoft.office.interop.excel._worksheet)newworkbook_first.sheets[worksheet] = (_worksheet)appexcel.activeworkbook.activesheet;
gave error
i did put in try/catch. , swallowed exception. idea provided @claies
Comments
Post a Comment