c# - Excel exception HRESULT: 0x800A03EC from ChartArea.Copy() -
i'm working on c# application thats interacts excel instance using excel interop.dll v11.0. i'm using following code copy chart excel worksheet clipboard:
public image readchart(chart chartaccess) { try { microsoft.office.interop.excel.worksheet sheet = workbook.sheets[chartaccess.sheet.name]; microsoft.office.interop.excel.chartobject chart = sheet.chartobjects(chartaccess.name); chart.chart.chartarea.copy(); // exception gets thrown here return system.windows.forms.clipboard.getimage(); } catch (comexception) { // display error dialog etc... }
this worked fine excel 2007. since switching excel 2013 function chartarea.copy() results in following comexceptions being thrown:
message: "dimension not valid chart type" stack trace: system.runtimetype.forwardcalltoinvokemember(string membername, bindingflags flags, object target, int32[] awrappertypes, messagedata& msgdata) microsoft.office.interop.excel.chartarea.copy() message: "hresult: 0x800a03ec" stack trace: system.runtimetype.forwardcalltoinvokemember(string membername, bindingflags flags, object target, int32[] awrappertypes, messagedata& msgdata) microsoft.office.interop.excel.chartarea.copy()
this happens excel sheets of old .xls format, xlsm / xlsx files work fine. using newer versions of interop.dll (v14.0 , v15.0) didn't help.
any appreciated!
edit:
i resolved problem using following workaround:
// ... chart.chart.activate(); chart.chart.export(filename, "png", false); using (stream reader = file.openread(filename)) { image = image.fromstream(stream); } return image;
the documentation copy shows there difference between versions 2003 , 2010.
2003:
void copy( [in, optional] object before, [in, optional] object after );
2010:
void copy( object before, object after )
as can see, arguments optional in 2003, , mandatory in later version.
Comments
Post a Comment