We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Reading .ole files

Hello,

we want to use you library to read “.ole” files. I see inside the structure that is a kind of RTF. Can you describe how we can process here to get teh preview image and the linked document, to open it with the accurate application? Works the OLEFormat for that?

I attach you a file. Thank you very much for your support.

Hi there,

Thanks for your inquiry. Aspose.Words for .NET is a class library that enables your applications to perform a great range of document processing tasks. Aspose.Words supports DOC, DOCX, RTF, HTML, OpenDocument, PDF, XPS, EPUB and other formats. With Aspose.Words you can generate, modify, convert, render and print documents without utilizing Microsoft Word®.

With Aspose.Words you can not read OLE files. The shared OLE is ‘Excel.Sheet.8’. However, you can extract OLE file from Word document using following code example.


//Open document

Document doc = new Document(@“in.doc”);

//OLE embedded objects are available through OleFormat property of Shape object

//So first we should extract shapes from the document

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

//Index will be used to generate unique name for each extracted object

int oleIndex = 0;

//Define variable that specifies base path

string basePath = @“Test091\obj_{0}.{1}”;

//Loop through all shapes

foreach (Shape shape in shapes)

{

//Check whether shape contains OLE object

if (shape.OleFormat != null)

{

//We can determine type of an OLE object using ProgId property

switch (shape.OleFormat.ProgId)

{

//ZIP archive ProgId = Package

case “Package”:

shape.OleFormat.Save(String.Format(basePath, oleIndex, “zip”));

break;

//DOC files

case “Word.Document.8”:

shape.OleFormat.Save(String.Format(basePath, oleIndex, “doc”));

break;

//By default let’s save OLE object with .object extension

default:

shape.OleFormat.Save(String.Format(basePath, oleIndex, “object”));

break;

}

//Increase index

oleIndex++;

}

}

Hi, thank you for your replay.

My next question is, how can I create OleObject inside RTF document with Aspose.Word tool? Is it possible? If yes, can you provide me an example code?

Thanks
Jan

Hi Jan,


Thanks for your inquiry. Yes, Aspose.Words now supports insertion of embedded OLE objects in Microsoft Word document. Please see the following examples:

Insert embedded Excel 97-2003 document as iconic OLE object from stream using predefined image:

Document doc = new
Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Stream memoryStream = File.OpenRead(MyDir + "Book1.xls");

Shape oleObject = builder.InsertOleObject(memoryStream, "Excel.Sheet.8", true, null);

doc.Save(MyDir + @“out.docx”);


Insert linked Word document from file as normal OLE object using custom presentation image

Document doc = new
Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Image image = Image.FromFile(MyDir + "Aspose.Words.png");

Shape oleObject = builder.InsertOleObject(MyDir + "Doc1.docx", true, false, image);

doc.Save(MyDir + @“out.docx”);


I hope, this helps.

Best regards,

Hi,

I tried you sample and works ok with OLE added like icon. But without icon, like a preview of the document, there is just a generic icon like in attachment. After i opened it to edit the preview appeared.
My questions are: there is a way to handle the OLE as preview, not like icon? There is a way to find out the progId(“Excel.Sheet.8”) for each file type that inserted?

Regards,
Jan


Hi Jan,


Thanks for your inquiry. Please attach the following resources here for testing.

  1. Input word document.
  2. File that you want to insert as an embedded OLE object.
  3. Code you’re using on your end.
  4. Aspose.Words generated output word document which shows the undesired behavior.
  5. Create your target word document using Microsoft Word application that shows your desired output and attach it here for our reference.

We will investigate the issue on our end and provide you more information.

Secondly, you can get the “ProgId” by using the following property:

oleObject.OleFormat.ProgId

Best regards,

Hi,

Because the preview is not anymore needed, we focus only on asIcon.

Now we have a different problem. With this sample code we to extract files like the one attached.
Many of them are working ok, the extension is suggested right, but for this one there is no suggested extension. Because we don’t know what kind of files can be inside we used SuggestedExtension function. Can you provide me a list with the extensions supported? Or a different approach to handle them?


mDocument = new Document(fileName);

//Look for embedded objects inside the document and extract them in different files.
string MyDir =
foreach (Aspose.Words.Drawing.Shape shp in mDocument.GetChildNodes(NodeType.Shape, true))
{
shp.OleFormat.Save(MyDir + shp.OleFormat.SuggestedExtension);
}

Hi Jan,


Thanks for your inquiry. In this case, please use the following code to insert this “Package” ole object in Word document:

Document doc = new
Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Shape oleObject = builder.InsertOleObject(MyDir + @"105_Object_Text_0.ole", false, false, null);

doc.Save(MyDir + @“out.docx”);


Now the “SuggestedExtension” property will return the correct extension. Unfortunately, there is no such list. The ProgID is stored in document binary as string. We just extract it from there. Here are examples of possible values of ProgId:
  • MS_ClipArt_Gallery
  • Equation.3
  • WPGraphic21
  • MIDFile
  • MSGraph.Chart.8
  • PBrush
  • MSPhotoEd.3
  • Excel.Sheet.8
  • Excel.Sheet.12
  • WordPad.Document.1
  • Word.Document.8
  • Word.Document.12
  • PowerPoint.Show.12
  • Package
  • Visio.Drawing.11

I hope, this helps.

Best regards,

Hi,

Thank You for your answer!

Now we got this exception when we try to extract ole files from inside word document, this is the code used:

mDocument = new Document(fileName);

//Look for embedded objects inside the document and extract them in different files.
string MyDir =
foreach (Aspose.Words.Drawing.Shape shp in mDocument.GetChildNodes(NodeType.Shape, true))
{
shp.OleFormat.Save(MyDir + shp.OleFormat.SuggestedExtension);
}




The file inside is quite large, about 80 MB.
Here is the exception:

************** Exception Text **************
System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
at Aspose.Words.Document.(Stream , LoadOptions )
at Aspose.Words.Document.(Stream , LoadOptions )
at Aspose.Words.Document…ctor(Stream stream, LoadOptions loadOptions)
at Aspose.Words.Document…ctor(Stream stream)
at ReqEdit.Classes.DocumentHandler.FileDocument.DoAnImportOnDocument(FileDocument fileDoc, String tempFolder)
at ReqEdit.Classes.DocumentHandler.FileDocument.Import(String[] filesToImport, String projectFileName)
at ReqEdit.Forms.MainForm.Import()
at ReqEdit.Forms.MainForm.tsmiImportIbm_Click(Object sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at ReqEdit.Controls.BaseControls.bToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


Regards,
Jan

Hi Jan,


Thanks for your inquiry. First off, please make sure you’re using latest version of Aspose.Words i.e. 14.3.0. Most likely, the problem occurs because there is not enough free space available in RAM. Aspose.Words needs few times more memory than document size to build model of the document in memory. For example if your document’s size is 1 MB, Aspose.Words needs 10-20 MB of RAM to build its DOM in memory. So, we suggest you to use a few small documents instead of one huge document.

Best regards,