.net - Edit a excel file while Exporting data from ms access to other excel file using c# without error occur -
i wrote program export data ms access excel. working properly. there error occur while editing or open other excel files. how solve error.
" exception hresult: 0x800ac472 "
private void writeexcel(system.data.datatable dt, string filename) { microsoft.office.interop.excel.applicationclass excel = new applicationclass(); microsoft.office.interop.excel.workbook wb = excel.workbooks.add(true); microsoft.office.interop.excel.worksheet wsht; int colid = 0; int rowid = 0; wsht = (microsoft.office.interop.excel.worksheet)wb.sheets[1]; range rng = wsht.get_range("a1", "iv" + (dt.rows.count + 1).tostring()); rng.numberformat = "@"; //fill column heading foreach (datacolumn col in dt.columns) { colid++; excel.cells[1, colid] = col.columnname; } } //fill row values foreach (datarow dr in dt.rows) { rowid++; colid = 0; foreach (datacolumn col in dt.columns) { colid++; excel.cells[rowid + 1, colid] = dr[col.columnname]; } } wsht.activate(); int rcount = wsht.usedrange.rows.count; rng = wsht.get_range("d1", "iv" + rcount.tostring()); rng.numberformat = "@"; wb.saveas(filename, microsoft.office.interop.excel.xlfileformat.xlworkbooknormal, "", "", false, false, microsoft.office.interop.excel.xlsaveasaccessmode.xlnochange, false, true, true, true, 1); excel.quit(); }
Comments
Post a Comment