Hello
I am trying to find a source file name of a linked Excel chart in a Word document.
But I could not do it using Aspose.Words. The following is the code I am using.
///////// using Aspose.Words
Document doc = new Document("doc1.docx");
var shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Aspose.Words.Drawing.Shape shape in shapes)
{
var oleFormat = shape.OleFormat;
if (oleFormat != null)
{
if (oleFormat.IsLink)
{
var sourceFullName = oleFormat.SourceFullName;
if (!string.IsNullOrEmpty(sourceFullName))
{
Console.WriteLine(sourceFullName);
}
}
}
}
////////
shape.OleFormat is always null.
If I am using VSTO, I can find a source file name by referencing LinkFormat, but Aspose.Words does not have LinkFormat property.
//////// This is part of the code using VSTO
using Word = Microsoft.Office.Interop.Word;
Word.Document doc = Application.Documents.Add("Doc1.docx");
foreach (Word.Section section in doc.Sections)
{
foreach (Word.InlineShape shape in section.Range.InlineShapes)
{
if (shape.LinkFormat != null)
{
var sourceFullName = shape.LinkFormat.SourceFullName;
if (!string.IsNullOrEmpty(sourceFullName))
{
Console.WriteLine(sourceFullName);
}
}
}
}
///////
Please see the sample file I am testing. It has a linked Excel chart.
Doc1.zip (15.0 KB)