c# - deleting a graph from an excel file -


i have function here takes worksheet , generates graph it. delete graph, excel sheet, after save have tried .delete() threw , error, how go doing that

    private void generategraph(worksheet worksheet, int lastrow, int lastcolumn, string filename)     {         string topleft = tocell(0, 0);         string bottomright = tocell(lastrow - 1, lastcolumn - 1);      worksheet.get_range(tocell(0, 0), missing).formula = "max(b2:" + bottomright + ")";     worksheet.get_range(tocell(0, 0), missing).formulahidden = true;     worksheet.get_range(tocell(0, 0), missing).calculate();     range range = (range)worksheet.cells[1,1];      string small = (string)range.value2;     double min = convert.todouble(small);     worksheet.get_range(tocell(0,0),missing).formula = "";      //generates graph     range = worksheet.get_range(topleft, bottomright);     chartobjects xlchart = (chartobjects)worksheet.chartobjects(missing);     chartobject chart = (chartobject)xlchart.add(20, 160, 600, 500);     excel.chart mychart = chart.chart;     mychart.setsourcedata(range, missing);      //sets y axis     axis axis = (axis)mychart.axes(xlaxistype.xlvalue, xlaxisgroup.xlprimary);     axis.minimumscaleisauto = true;     axis.maximumscaleisauto = true;     axis.hastitle = true;     axis.axistitle.text = "measure (m)";     axis.crossesat = (int)(min-1);      //sets x axis     axis xaxis = (axis)mychart.axes(xlaxistype.xlcategory, xlaxisgroup.xlprimary);     xaxis.hastitle = true;     xaxis.axistitle.text = "position (m)";      //makes graph line graph     mychart.charttype = xlcharttype.xlxyscatterlinesnomarkers;      //titles graph     mychart.hastitle = true;     mychart.charttitle.text = "profiles";      //saves graph     mychart.export(filename, "jpg", missing);      //     //here delete graph     // } 

if mychart.delete doesn't it, try mychart.parent.delete


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -