public class OleFormat
Use the Example:
Document doc = new Document(getMyDir() + "OLE spreadsheet.docm");
// The first shape will contain an OLE object
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
// This object is a Microsoft Excel spreadsheet
OleFormat oleFormat = shape.getOleFormat();
Assert.assertEquals(oleFormat.getProgId(), "Excel.Sheet.12");
// Our object is neither auto updating nor locked from updates
Assert.assertFalse(oleFormat.getAutoUpdate());
Assert.assertEquals(oleFormat.isLocked(), false);
// If we want to extract the OLE object by saving it into our local file system, this property can tell us the relevant file extension
Assert.assertEquals(oleFormat.getSuggestedExtension(), ".xlsx");
// We can save it via a stream
OutputStream stream = new FileOutputStream(getArtifactsDir() + "OLE spreadsheet extracted via stream" + oleFormat.getSuggestedExtension());
try {
oleFormat.save(stream);
} finally {
if (stream != null) stream.close();
}
// We can also save it directly to a file
oleFormat.save(getArtifactsDir() + "OLE spreadsheet saved directly" + oleFormat.getSuggestedExtension());
Property Getters/Setters Summary | ||
---|---|---|
boolean | getAutoUpdate() | |
void | setAutoUpdate(booleanvalue) | |
Specifies whether the link to the OLE object is automatically updated or not in Microsoft Word. | ||
java.util.UUID | getClsid() | |
Gets the CLSID of the OLE object.
|
||
java.lang.String | getIconCaption() | |
Gets icon caption of OLE object.
In case of OLE object is not embedded as icon or caption couldn't be retrieved returns empty string. |
||
boolean | isLink() | |
Returns true if the OLE object is linked (when |
||
boolean | isLocked() | |
void | isLocked(booleanvalue) | |
Specifies whether the link to the OLE object is locked from updates. | ||
OleControl | getOleControl() | |
Gets |
||
boolean | getOleIcon() | |
Gets the draw aspect of the OLE object. When true, the OLE object is displayed as an icon.
When false, the OLE object is displayed as content.
|
||
OlePackage | getOlePackage() | |
Provide access to |
||
java.lang.String | getProgId() | |
void | setProgId(java.lang.Stringvalue) | |
Gets or sets the ProgID of the OLE object. | ||
java.lang.String | getSourceFullName() | |
void | setSourceFullName(java.lang.Stringvalue) | |
Gets or sets the path and name of the source file for the linked OLE object. | ||
java.lang.String | getSourceItem() | |
void | setSourceItem(java.lang.Stringvalue) | |
Gets or sets a string that is used to identify the portion of the source file that is being linked. | ||
java.lang.String | getSuggestedExtension() | |
Gets the file extension suggested for the current embedded object if you want to save it into a file.
|
||
java.lang.String | getSuggestedFileName() | |
Gets the file name suggested for the current embedded object if you want to save it into a file.
|
Method Summary | ||
---|---|---|
byte[] | getOleEntry(java.lang.String oleEntryName) | |
Gets OLE object data entry.
|
||
byte[] | getRawData() | |
Gets OLE object raw data.
|
||
void | save(java.io.OutputStream stream) | |
Saves the data of the embedded object into the specified stream.
|
||
void | save(java.lang.String fileName) | |
Saves the data of the embedded object into a file with the specified name.
|
public boolean getAutoUpdate() / public void setAutoUpdate(boolean value)
The default value is false.
Example:
Shows how to extract embedded OLE objects into files.Document doc = new Document(getMyDir() + "OLE spreadsheet.docm"); // The first shape will contain an OLE object Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true); // This object is a Microsoft Excel spreadsheet OleFormat oleFormat = shape.getOleFormat(); Assert.assertEquals(oleFormat.getProgId(), "Excel.Sheet.12"); // Our object is neither auto updating nor locked from updates Assert.assertFalse(oleFormat.getAutoUpdate()); Assert.assertEquals(oleFormat.isLocked(), false); // If we want to extract the OLE object by saving it into our local file system, this property can tell us the relevant file extension Assert.assertEquals(oleFormat.getSuggestedExtension(), ".xlsx"); // We can save it via a stream OutputStream stream = new FileOutputStream(getArtifactsDir() + "OLE spreadsheet extracted via stream" + oleFormat.getSuggestedExtension()); try { oleFormat.save(stream); } finally { if (stream != null) stream.close(); } // We can also save it directly to a file oleFormat.save(getArtifactsDir() + "OLE spreadsheet saved directly" + oleFormat.getSuggestedExtension());
public java.util.UUID getClsid()
Example:
Shows how to access an OLE control embedded in a document and its child controls.// Open a document that contains a Microsoft Forms OLE control with child controls Document doc = new Document(getMyDir() + "OLE ActiveX controls.docm"); // Get the shape that contains the control Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true); Assert.assertEquals(shape.getOleFormat().getClsid().toString(), "6e182020-f460-11ce-9bcd-00aa00608e01"); Forms2OleControl oleControl = (Forms2OleControl) shape.getOleFormat().getOleControl(); // Some controls contain child controls Forms2OleControlCollection oleControlCollection = oleControl.getChildNodes(); // In this case, the child controls are 3 option buttons Assert.assertEquals(oleControlCollection.getCount(), 3); Assert.assertEquals(oleControlCollection.get(0).getCaption(), "C#"); Assert.assertEquals(oleControlCollection.get(0).getValue(), "1"); Assert.assertEquals(oleControlCollection.get(1).getCaption(), "Visual Basic"); Assert.assertEquals(oleControlCollection.get(1).getValue(), "0"); Assert.assertEquals(oleControlCollection.get(2).getCaption(), "Delphi"); Assert.assertEquals(oleControlCollection.get(2).getValue(), "0");
public java.lang.String getIconCaption()
In case of OLE object is not embedded as icon or caption couldn't be retrieved returns empty string.
Example:
Shows how to insert linked and unlinked OLE objects.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Embed a Microsoft Visio drawing as an OLE object into the document builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", false, false, new FileInputStream(getImageDir() + "Logo.jpg")); // Insert a link to the file in the local file system and display it as an icon builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", true, true, new FileInputStream(getImageDir() + "Logo.jpg")); // Both the OLE objects are stored within shapes NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true); Assert.assertEquals(shapes.getCount(), 2); // If the shape is an OLE object, it will have a valid OleFormat property // We can use it check if it is linked or displayed as an icon, among other things Shape firstShape = (Shape) shapes.get(0); OleFormat oleFormat = firstShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), false); Assert.assertEquals(oleFormat.getOleIcon(), false); Shape secondShape = (Shape) shapes.get(1); oleFormat = secondShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), true); Assert.assertEquals(oleFormat.getOleIcon(), true); // Get the name or the source file and verify that the whole file is linked Assert.assertTrue(oleFormat.getSourceFullName().endsWith("Images" + File.separatorChar + "Microsoft Visio drawing.vsd")); Assert.assertEquals(oleFormat.getSourceItem(), ""); Assert.assertEquals(oleFormat.getIconCaption(), "Microsoft Visio drawing.vsd"); doc.save(getArtifactsDir() + "Shape.OleLinks.docx"); // We can get a stream with the OLE data entry, if the object has this byte[] oleEntryBytes = oleFormat.getOleEntry("\u0001CompObj"); Assert.assertEquals(oleEntryBytes.length, 76);
public boolean isLink()
Example:
Shows how to insert linked and unlinked OLE objects.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Embed a Microsoft Visio drawing as an OLE object into the document builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", false, false, new FileInputStream(getImageDir() + "Logo.jpg")); // Insert a link to the file in the local file system and display it as an icon builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", true, true, new FileInputStream(getImageDir() + "Logo.jpg")); // Both the OLE objects are stored within shapes NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true); Assert.assertEquals(shapes.getCount(), 2); // If the shape is an OLE object, it will have a valid OleFormat property // We can use it check if it is linked or displayed as an icon, among other things Shape firstShape = (Shape) shapes.get(0); OleFormat oleFormat = firstShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), false); Assert.assertEquals(oleFormat.getOleIcon(), false); Shape secondShape = (Shape) shapes.get(1); oleFormat = secondShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), true); Assert.assertEquals(oleFormat.getOleIcon(), true); // Get the name or the source file and verify that the whole file is linked Assert.assertTrue(oleFormat.getSourceFullName().endsWith("Images" + File.separatorChar + "Microsoft Visio drawing.vsd")); Assert.assertEquals(oleFormat.getSourceItem(), ""); Assert.assertEquals(oleFormat.getIconCaption(), "Microsoft Visio drawing.vsd"); doc.save(getArtifactsDir() + "Shape.OleLinks.docx"); // We can get a stream with the OLE data entry, if the object has this byte[] oleEntryBytes = oleFormat.getOleEntry("\u0001CompObj"); Assert.assertEquals(oleEntryBytes.length, 76);
public boolean isLocked() / public void isLocked(boolean value)
The default value is false.
Example:
Shows how to extract embedded OLE objects into files.Document doc = new Document(getMyDir() + "OLE spreadsheet.docm"); // The first shape will contain an OLE object Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true); // This object is a Microsoft Excel spreadsheet OleFormat oleFormat = shape.getOleFormat(); Assert.assertEquals(oleFormat.getProgId(), "Excel.Sheet.12"); // Our object is neither auto updating nor locked from updates Assert.assertFalse(oleFormat.getAutoUpdate()); Assert.assertEquals(oleFormat.isLocked(), false); // If we want to extract the OLE object by saving it into our local file system, this property can tell us the relevant file extension Assert.assertEquals(oleFormat.getSuggestedExtension(), ".xlsx"); // We can save it via a stream OutputStream stream = new FileOutputStream(getArtifactsDir() + "OLE spreadsheet extracted via stream" + oleFormat.getSuggestedExtension()); try { oleFormat.save(stream); } finally { if (stream != null) stream.close(); } // We can also save it directly to a file oleFormat.save(getArtifactsDir() + "OLE spreadsheet saved directly" + oleFormat.getSuggestedExtension());
public OleControl getOleControl()
Example:
Shows how to get ActiveX control and properties from the document.Document doc = new Document(getMyDir() + "ActiveX controls.docx"); // Get ActiveX control from the document Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true); OleControl oleControl = shape.getOleFormat().getOleControl(); Assert.assertEquals(oleControl.getName(), null); // Get ActiveX control properties if (oleControl.isForms2OleControl()) { Forms2OleControl checkBox = (Forms2OleControl) oleControl; Assert.assertEquals(checkBox.getCaption(), "Первый"); Assert.assertEquals(checkBox.getValue(), "0"); Assert.assertEquals(checkBox.getEnabled(), true); Assert.assertEquals(checkBox.getType(), Forms2OleControlType.CHECK_BOX); Assert.assertEquals(checkBox.getChildNodes(), null); }
public boolean getOleIcon()
Aspose.Words does not allow to set this property to avoid confusion. If you were able to change the draw aspect in Aspose.Words, Microsoft Word would still display the OLE object in its original draw aspect until you edit or update the OLE object in Microsoft Word.
Example:
Shows how to insert linked and unlinked OLE objects.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Embed a Microsoft Visio drawing as an OLE object into the document builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", false, false, new FileInputStream(getImageDir() + "Logo.jpg")); // Insert a link to the file in the local file system and display it as an icon builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", true, true, new FileInputStream(getImageDir() + "Logo.jpg")); // Both the OLE objects are stored within shapes NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true); Assert.assertEquals(shapes.getCount(), 2); // If the shape is an OLE object, it will have a valid OleFormat property // We can use it check if it is linked or displayed as an icon, among other things Shape firstShape = (Shape) shapes.get(0); OleFormat oleFormat = firstShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), false); Assert.assertEquals(oleFormat.getOleIcon(), false); Shape secondShape = (Shape) shapes.get(1); oleFormat = secondShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), true); Assert.assertEquals(oleFormat.getOleIcon(), true); // Get the name or the source file and verify that the whole file is linked Assert.assertTrue(oleFormat.getSourceFullName().endsWith("Images" + File.separatorChar + "Microsoft Visio drawing.vsd")); Assert.assertEquals(oleFormat.getSourceItem(), ""); Assert.assertEquals(oleFormat.getIconCaption(), "Microsoft Visio drawing.vsd"); doc.save(getArtifactsDir() + "Shape.OleLinks.docx"); // We can get a stream with the OLE data entry, if the object has this byte[] oleEntryBytes = oleFormat.getOleEntry("\u0001CompObj"); Assert.assertEquals(oleEntryBytes.length, 76);
public OlePackage getOlePackage()
Example:
Shows how insert ole object as ole package and set it file name and display name.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); byte[] zipFileBytes = Files.readAllBytes(Paths.get(getDatabaseDir() + "cat001.zip")); InputStream stream = new ByteArrayInputStream(zipFileBytes); InputStream representingImage = new FileInputStream(getImageDir() + "Logo.jpg"); try { Shape shape = builder.insertOleObject(stream, "Package", true, representingImage); OlePackage setOlePackage = shape.getOleFormat().getOlePackage(); setOlePackage.setFileName("Cat FileName.zip"); setOlePackage.setDisplayName("Cat DisplayName.zip"); doc.save(getArtifactsDir() + "Shape.InsertOlePackage.docx"); } finally { if (stream != null) { stream.close(); } }
public java.lang.String getProgId() / public void setProgId(java.lang.String value)
The ProgID property is not always present in Microsoft Word documents and cannot be relied upon.
Cannot be null.
The default value is an empty string.
Example:
Shows how to extract embedded OLE objects into files.Document doc = new Document(getMyDir() + "OLE spreadsheet.docm"); // The first shape will contain an OLE object Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true); // This object is a Microsoft Excel spreadsheet OleFormat oleFormat = shape.getOleFormat(); Assert.assertEquals(oleFormat.getProgId(), "Excel.Sheet.12"); // Our object is neither auto updating nor locked from updates Assert.assertFalse(oleFormat.getAutoUpdate()); Assert.assertEquals(oleFormat.isLocked(), false); // If we want to extract the OLE object by saving it into our local file system, this property can tell us the relevant file extension Assert.assertEquals(oleFormat.getSuggestedExtension(), ".xlsx"); // We can save it via a stream OutputStream stream = new FileOutputStream(getArtifactsDir() + "OLE spreadsheet extracted via stream" + oleFormat.getSuggestedExtension()); try { oleFormat.save(stream); } finally { if (stream != null) stream.close(); } // We can also save it directly to a file oleFormat.save(getArtifactsDir() + "OLE spreadsheet saved directly" + oleFormat.getSuggestedExtension());
public java.lang.String getSourceFullName() / public void setSourceFullName(java.lang.String value)
The default value is an empty string.
If
Example:
Shows how to insert linked and unlinked OLE objects.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Embed a Microsoft Visio drawing as an OLE object into the document builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", false, false, new FileInputStream(getImageDir() + "Logo.jpg")); // Insert a link to the file in the local file system and display it as an icon builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", true, true, new FileInputStream(getImageDir() + "Logo.jpg")); // Both the OLE objects are stored within shapes NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true); Assert.assertEquals(shapes.getCount(), 2); // If the shape is an OLE object, it will have a valid OleFormat property // We can use it check if it is linked or displayed as an icon, among other things Shape firstShape = (Shape) shapes.get(0); OleFormat oleFormat = firstShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), false); Assert.assertEquals(oleFormat.getOleIcon(), false); Shape secondShape = (Shape) shapes.get(1); oleFormat = secondShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), true); Assert.assertEquals(oleFormat.getOleIcon(), true); // Get the name or the source file and verify that the whole file is linked Assert.assertTrue(oleFormat.getSourceFullName().endsWith("Images" + File.separatorChar + "Microsoft Visio drawing.vsd")); Assert.assertEquals(oleFormat.getSourceItem(), ""); Assert.assertEquals(oleFormat.getIconCaption(), "Microsoft Visio drawing.vsd"); doc.save(getArtifactsDir() + "Shape.OleLinks.docx"); // We can get a stream with the OLE data entry, if the object has this byte[] oleEntryBytes = oleFormat.getOleEntry("\u0001CompObj"); Assert.assertEquals(oleEntryBytes.length, 76);
public java.lang.String getSourceItem() / public void setSourceItem(java.lang.String value)
The default value is an empty string.
For example, if the source file is a Microsoft Excel workbook, the
Example:
Shows how to insert linked and unlinked OLE objects.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Embed a Microsoft Visio drawing as an OLE object into the document builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", false, false, new FileInputStream(getImageDir() + "Logo.jpg")); // Insert a link to the file in the local file system and display it as an icon builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", true, true, new FileInputStream(getImageDir() + "Logo.jpg")); // Both the OLE objects are stored within shapes NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true); Assert.assertEquals(shapes.getCount(), 2); // If the shape is an OLE object, it will have a valid OleFormat property // We can use it check if it is linked or displayed as an icon, among other things Shape firstShape = (Shape) shapes.get(0); OleFormat oleFormat = firstShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), false); Assert.assertEquals(oleFormat.getOleIcon(), false); Shape secondShape = (Shape) shapes.get(1); oleFormat = secondShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), true); Assert.assertEquals(oleFormat.getOleIcon(), true); // Get the name or the source file and verify that the whole file is linked Assert.assertTrue(oleFormat.getSourceFullName().endsWith("Images" + File.separatorChar + "Microsoft Visio drawing.vsd")); Assert.assertEquals(oleFormat.getSourceItem(), ""); Assert.assertEquals(oleFormat.getIconCaption(), "Microsoft Visio drawing.vsd"); doc.save(getArtifactsDir() + "Shape.OleLinks.docx"); // We can get a stream with the OLE data entry, if the object has this byte[] oleEntryBytes = oleFormat.getOleEntry("\u0001CompObj"); Assert.assertEquals(oleEntryBytes.length, 76);
public java.lang.String getSuggestedExtension()
Example:
Shows how to extract embedded OLE objects into files.Document doc = new Document(getMyDir() + "OLE spreadsheet.docm"); // The first shape will contain an OLE object Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true); // This object is a Microsoft Excel spreadsheet OleFormat oleFormat = shape.getOleFormat(); Assert.assertEquals(oleFormat.getProgId(), "Excel.Sheet.12"); // Our object is neither auto updating nor locked from updates Assert.assertFalse(oleFormat.getAutoUpdate()); Assert.assertEquals(oleFormat.isLocked(), false); // If we want to extract the OLE object by saving it into our local file system, this property can tell us the relevant file extension Assert.assertEquals(oleFormat.getSuggestedExtension(), ".xlsx"); // We can save it via a stream OutputStream stream = new FileOutputStream(getArtifactsDir() + "OLE spreadsheet extracted via stream" + oleFormat.getSuggestedExtension()); try { oleFormat.save(stream); } finally { if (stream != null) stream.close(); } // We can also save it directly to a file oleFormat.save(getArtifactsDir() + "OLE spreadsheet saved directly" + oleFormat.getSuggestedExtension());
public java.lang.String getSuggestedFileName()
Example:
Shows how to get suggested file name from the object.Document doc = new Document(getMyDir() + "OLE shape.rtf"); // Gets the file name suggested for the current embedded object if you want to save it into a file Shape oleShape = (Shape) doc.getFirstSection().getBody().getChild(NodeType.SHAPE, 0, true); String suggestedFileName = oleShape.getOleFormat().getSuggestedFileName(); Assert.assertEquals(suggestedFileName, "CSV.csv");
public byte[] getOleEntry(java.lang.String oleEntryName)
oleEntryName
- Case-sensitive name of the OLE data stream.Example:
Shows how to insert linked and unlinked OLE objects.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Embed a Microsoft Visio drawing as an OLE object into the document builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", false, false, new FileInputStream(getImageDir() + "Logo.jpg")); // Insert a link to the file in the local file system and display it as an icon builder.insertOleObject(getImageDir() + "Microsoft Visio drawing.vsd", "Package", true, true, new FileInputStream(getImageDir() + "Logo.jpg")); // Both the OLE objects are stored within shapes NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true); Assert.assertEquals(shapes.getCount(), 2); // If the shape is an OLE object, it will have a valid OleFormat property // We can use it check if it is linked or displayed as an icon, among other things Shape firstShape = (Shape) shapes.get(0); OleFormat oleFormat = firstShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), false); Assert.assertEquals(oleFormat.getOleIcon(), false); Shape secondShape = (Shape) shapes.get(1); oleFormat = secondShape.getOleFormat(); Assert.assertEquals(oleFormat.isLink(), true); Assert.assertEquals(oleFormat.getOleIcon(), true); // Get the name or the source file and verify that the whole file is linked Assert.assertTrue(oleFormat.getSourceFullName().endsWith("Images" + File.separatorChar + "Microsoft Visio drawing.vsd")); Assert.assertEquals(oleFormat.getSourceItem(), ""); Assert.assertEquals(oleFormat.getIconCaption(), "Microsoft Visio drawing.vsd"); doc.save(getArtifactsDir() + "Shape.OleLinks.docx"); // We can get a stream with the OLE data entry, if the object has this byte[] oleEntryBytes = oleFormat.getOleEntry("\u0001CompObj"); Assert.assertEquals(oleEntryBytes.length, 76);
public byte[] getRawData() throws java.lang.Exception
Example:
Shows how to get access to OLE object raw data.// Open a document that contains OLE objects Document doc = new Document(getMyDir() + "OLE objects.docx"); for (Node shape : (Iterable<Node>) doc.getChildNodes(NodeType.SHAPE, true)) { // Get access to OLE data OleFormat oleFormat = ((Shape) shape).getOleFormat(); if (oleFormat != null) { System.out.println("This is {(oleFormat.IsLink ? "); byte[] oleRawData = oleFormat.getRawData(); } }
public void save(java.io.OutputStream stream) throws java.lang.Exception
It is the responsibility of the caller to dispose the stream.
stream
- Where to save the object data.Example:
Shows how to extract embedded OLE objects into files.Document doc = new Document(getMyDir() + "OLE spreadsheet.docm"); // The first shape will contain an OLE object Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true); // This object is a Microsoft Excel spreadsheet OleFormat oleFormat = shape.getOleFormat(); Assert.assertEquals(oleFormat.getProgId(), "Excel.Sheet.12"); // Our object is neither auto updating nor locked from updates Assert.assertFalse(oleFormat.getAutoUpdate()); Assert.assertEquals(oleFormat.isLocked(), false); // If we want to extract the OLE object by saving it into our local file system, this property can tell us the relevant file extension Assert.assertEquals(oleFormat.getSuggestedExtension(), ".xlsx"); // We can save it via a stream OutputStream stream = new FileOutputStream(getArtifactsDir() + "OLE spreadsheet extracted via stream" + oleFormat.getSuggestedExtension()); try { oleFormat.save(stream); } finally { if (stream != null) stream.close(); } // We can also save it directly to a file oleFormat.save(getArtifactsDir() + "OLE spreadsheet saved directly" + oleFormat.getSuggestedExtension());
public void save(java.lang.String fileName) throws java.lang.Exception
fileName
- Name of the file to save the OLE object data.Example:
Shows how to extract embedded OLE objects into files.Document doc = new Document(getMyDir() + "OLE spreadsheet.docm"); // The first shape will contain an OLE object Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true); // This object is a Microsoft Excel spreadsheet OleFormat oleFormat = shape.getOleFormat(); Assert.assertEquals(oleFormat.getProgId(), "Excel.Sheet.12"); // Our object is neither auto updating nor locked from updates Assert.assertFalse(oleFormat.getAutoUpdate()); Assert.assertEquals(oleFormat.isLocked(), false); // If we want to extract the OLE object by saving it into our local file system, this property can tell us the relevant file extension Assert.assertEquals(oleFormat.getSuggestedExtension(), ".xlsx"); // We can save it via a stream OutputStream stream = new FileOutputStream(getArtifactsDir() + "OLE spreadsheet extracted via stream" + oleFormat.getSuggestedExtension()); try { oleFormat.save(stream); } finally { if (stream != null) stream.close(); } // We can also save it directly to a file oleFormat.save(getArtifactsDir() + "OLE spreadsheet saved directly" + oleFormat.getSuggestedExtension());