c# - Deleting Excel ListObject after Unlisting it -


i'm doing vsto add-in project in c#.

basically, want retrieve data database , put excel. however, want write data in format of simple range , dont keep kind of binding datasource.

to it, i'm creating listobject , setting datasource datatable populated data. then, i'm calling method unlist convert table normal range , them i'm trying remove listobject worksheet can use same listobject name when repeat process.

the problem when try delete listobject c# throwing bad index exception.

here code:

   microsoft.office.interop.excel.worksheet worksheet = (microsoft.office.interop.excel.worksheet)globals.thisaddin.application.activesheet;      worksheet extendedworksheet = globals.factory.getvstoobject(worksheet);      microsoft.office.interop.excel.range cell = extendedworksheet.application.activecell;     microsoft.office.tools.excel.listobject listobject;     bindingsource bindingsource = new system.windows.forms.bindingsource();     datatable datatable = new datatable();     bindingsource.datasource = datatable;     listobject = extendedworksheet.controls.addlistobject(cell, "list1");     listobject.autosetdataboundcolumnheaders = true;     listobject.setdatabinding(bindingsource, "");     listobject.unlist();     extendedworksheet.controls.removeat(0); 

i tried variations remove listobject, none of them worked:

extendedworksheet.controls.remove("list1'); //or listobject.delete() //or foreach (listobject x in extendedworksheet.controls) {     x.delete(); } 


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -