c# - appending to an existing excel file -
i have function writes , saves excel file. want append same existing excel file.this function:
private void button8_click(object sender, eventargs e)//creates excel file , writes data { excel.application xlapp = new microsoft.office.interop.excel.application(); if (xlapp == null) { messagebox.show("excel not installed!!"); return; } if (system.io.file.exists("cross_check.xls")) { } else { excel.workbook xlworkbook; excel.worksheet xlworksheet; object misvalue = system.reflection.missing.value; xlworkbook = xlapp.workbooks.add(misvalue); xlworksheet = (excel.worksheet)xlworkbook.worksheets.get_item(1); indexprop += 1; xlworksheet.cells[indexprop, 1] = combobox2.text; xlworksheet.cells[indexprop, 2] = textbox5.text; xlworksheet.cells[indexprop, 3] = textbox2.text; xlworksheet.cells[indexprop, 4] = combobox3.text; xlworksheet.cells[indexprop, 5] = textbox3.text; xlworksheet.cells[indexprop, 6] = combobox1.text; xlworkbook.saveas(@"cross_check.xls", excel.xlfileformat.xlworkbooknormal, misvalue, misvalue, misvalue, misvalue, excel.xlsaveasaccessmode.xlexclusive, misvalue, misvalue, misvalue, misvalue, misvalue); xlworkbook.close(true, misvalue, misvalue); xlapp.quit(); marshal.releasecomobject(xlworksheet); marshal.releasecomobject(xlworkbook); marshal.releasecomobject(xlapp); messagebox.show("excel file created succcessfully"); } } } this particular block checking file if exists , append operation if exists. how do this?
if (system.io.file.exists("cross_check.xls")) { }
you want open file make active work book , make changes want. there can save or ever want it.
Comments
Post a Comment