I used the following code to change the OleIcon parameter to true for each embedded object. But there is no success. What is the reason? Is there any way to do this? I need this urgently. Please find the attached document (wordattached.doc).
Thank in advance.
Document asposeDoc = new Document(sourceFile, LoadFormat.Doc, "");
NodeList shapeNodeList = asposeDoc.SelectNodes("//Shape");
foreach(Node ole in shapeNodeList)
{
if (ole is Aspose.Words.Drawing.Shape && ((Aspose.Words.Drawing.Shape) ole).OleFormat != null)
{
((Aspose.Words.Drawing.Shape) ole).OleFormat.OleIcon = true;
}
}
asposeDoc.UpdateFields();
asposeDoc.Save(destinationFile, SaveFormat.Doc);
}
Thanks for your request. I suppose you have attached the document after processing it using this code. Could you please attach your source document here for testing? I will investigate the issue and provide you more information.
Best regards.
Thank you for additional information. I think you should also specify an icon, which will be shown. Please see the following code:
Document doc = new Document(@"Test208\WordAttached.docx", LoadFormat.Docx, "");
NodeCollection shapeNodeList = doc.GetChildNodes(NodeType.Shape, true);
foreach(Shape ole in shapeNodeList)
{
if (ole.OleFormat != null)
{
ole.OleFormat.OleIcon = true;
// Here you should set icon that will be shown.
// I set the same icon for all embedded objects, but you can set different iconts
// depends on OLE object type.
ole.ImageData.SetImage(@"Common\test.jpg");
}
}
doc.Save(@"Test208\out.doc");
I used your DOCX file for testing. And as I can see all works as expected. I attached input and output documents. Code is the same, I provided in my previous post.
Also, as, I can see, your DOCX document was created using some third party tool, because all embedded OLE objects has the same ProgId:
Thank for response.
In out.doc file you attached does not really have a DrawAspect=“Icon”. This can be proved by calling following code.
Document doc = new Document(@"Test208\out.doc", LoadFormat.Docx, "");
NodeCollection shapeNodeList = doc.GetChildNodes(NodeType.Shape, true);
foreach(Shape ole in shapeNodeList)
{
if (ole.OleFormat != null)
{
if (!ole.OleFormat.OleIcon)
{
// Here we come only if OleIcon is false. i.e, only
// if DrawAspect is "Content".
// But for out.doc we come to here every times
}
}
}
Thank for response.
In out.doc file you attached does not really have a DrawAspect=“Icon”. This can be proved by calling following code.
Document doc = new Document(@"Test208\out.doc", LoadFormat.Doc, "");
NodeCollection shapeNodeList = doc.GetChildNodes(NodeType.Shape, true);
foreach(Shape ole in shapeNodeList)
{
if (ole.OleFormat != null)
{
if (!ole.OleFormat.OleIcon)
{
// Here we come only if OleIcon is false. i.e, only
// if DrawAspect is "Content".
// But for out.doc we come to here every times
}
}
}
Thank you for additional information. I linked your request to the appropriate issue. You will be notified as soon as this problem is resolved.
Best regards.
Hi,
As it turns out programmatically changing OleFormat.OleIcon (e.g. DrawAspect) in Aspose.Words will never work because it requires the host OLE application to display the OLE object in the requried way.
To eliminate confusion, in the next version of Aspose.Words I am making OleFormat.OleIcon readonly.