将Word.InlineShape转换为Excel.Workbook c#

时间:2015-07-30 07:56:01

标签: c# excel ms-office vsto

Word文档中有一些excel.workbooks。

我可以获得Word.Inline形状,但我需要将它们转换为Excel.Application

Word.InlineShapes shapes=wordApp.ActiveDocument.InlineShapes;

通过

创建的那些形状
wordApp.Selection.InlineShapes.AddOLEObject("MSGraph.Chart.8", excellApp.ActiveWorkbook.Name, false, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

如何将它们再次转换为Excel.Workbook?

我也试过;

Word.InlineShapes shapes = wordApp.ActiveDocument.InlineShapes;

foreach(Word.Shape shape in shapes)
{
     Word.Chart chart = shape.Chart;
}

但它会抛出未实现的异常。

1 个答案:

答案 0 :(得分:1)

试试这个:

Word.OLEFormat ole = shape.OLEFormat;
ole.Activate();
Excel.Workbook book = (Excel.Workbook)ole.Object;