本文介绍了Excel异常HRESULT:来自ChartArea.Copy()的0x800A03EC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用excel interop.dll v11.0与Excel实例进行交互的C#应用​​程序。
我使用以下代码将excel工作表中的图表复制到剪贴板:

  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(); //异常在这里抛出
return System.Windows.Forms.Clipboard.GetImage();
} catch(COMException){
//显示错误对话框等...
}

Excel 2007可以正常工作。但是从切换到Excel 2013后,函数ChartArea.Copy()会导致抛出以下COMExceptions:

 消息:维度对图表类型无效
堆栈跟踪:System.RuntimeType.ForwardCallToInvokeMember(String memberName,BindingFlags flags,Object target,Int32 [] aWrapperTypes,MessageData& msgData)
Microsoft.Office.Interop.Excel.ChartArea.Copy()

消息:HRESULT:0x800A03EC
堆栈跟踪:System.RuntimeType.ForwardCallToInvokeMember(String memberName,BindingFlags flags ,Object target,Int32 [] aWrapperTypes,MessageData& msgData)
Microsoft.Office.Interop.Excel.ChartArea.Copy()

这只会发生在旧的.xls格式的Excel表格中,xlsm / xlsx文件工作正常。
使用更新版本的interop.dll(v14.0和v15.0)没有帮助。



任何帮助都赞赏!



编辑:



我使用以下解决方法解决了问题:

  // ... 
chart.Chart.activate();
chart.Chart.Export(filename,PNG,false);
using(Stream reader = File.OpenRead(filename)){
image = Image.fromStream(stream);
}
返回图片;


解决方案

复制显示有一个2003年和2010年之间的差异。



2003:

  void复制(
[In,Optional] object Before,
[In,Optional] object After
);

2010:

 



$ / $ b

正如你所看到的,这些参数在2003年是可选的,在以后的版本中是强制性的。


I'm working on a C# Application thats interacts with an Excel instance using excel interop.dll v11.0. I'm using the following code to copy a chart from the excel worksheet to the 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 with Excel 2007. However since switching to Excel 2013 the function ChartArea.Copy() results in the following COMExceptions being thrown:

Message:      "Dimension not valid for 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 only happens with excel sheets of the old .xls format, xlsm / xlsx files work fine.Using newer versions of interop.dll (v14.0 and v15.0) didn't help.

Any help is appreciated!

EDIT:

I resolved the Problem using the 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 for Copy shows that there is a difference between versions 2003 and 2010.

2003:

void Copy(
    [In, Optional] object Before,
    [In, Optional] object After
);

2010:

void Copy(
    Object Before,
    Object After
)

As you can see, the arguments were optional in 2003, and mandatory in later version.

这篇关于Excel异常HRESULT:来自ChartArea.Copy()的0x800A03EC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 12:57