Hello,
I am working on a project (in java) using aspose.words library (and i have liscence).
i am trying to create a function that gets as a parameter a document (more specifically a .docx file) run all over the ole objects that it contains and modify several ole objects like images or ooxml files.
I am using this function:
NodeCollection<Shape> shapes = document.getChildNodes(NodeType.SHAPE, true);
for (Shape shape : shapes)
{
if (shape.getOleFormat() != null)
{
String progId = shape.getOleFormat().getProgId();
if (progId.equals("Word.Document.12"))
{
// take the shape convert it into a .docx file.
// run a function that adds data to the file.
// convert the file back to a shape.
// swap between the old shape and the new shape.
}
}
}
the main problem is that i couldn’t find any helpful code that will help me implement my wish.
this is the code that i currently have:
DocumentBuilder builder = new DocumentBuilder(document);
Path path = Paths.get("/home/gal/Desktop/second.docx");
byte[] data = Files.readAllBytes(path);
InputStream stream = new ByteArrayInputStream(data);
InputStream representingImage = new FileInputStream("/home/gal/Desktop/word_icon.ico");
Shape shape = builder.insertOleObject("/home/gal/Desktop/second.docx", "Package",
false,false, representingImage);
OlePackage setOlePackage = shape.getOleFormat().getOlePackage();
setOlePackage.setFileName("file1.docx");
setOlePackage.setDisplayName("word.docx");
the problem with this code that it inserts the internal file as an clickable icon an then when i open the external file i can click on the icon insisde the external file and it would open the internal file but i dont want to have an icon i want it to look like createing a docx file inside docx file using Microsoft Office application.
in addition to this problem there is another problem that the internal file is being saved as a binary file and not as a docx file (probably because i am using oleobjects).
therefore i have tried to use DocumentBuilder.insertDocument
and Document.appendDocument
but it only copies the data from the internal file and pastes it in the external file (yet not what i am trying to reach.
my main idea is to this this not onlly with docx inside docx but also with images inside docx and other file types.
i would like to have some help with the code.
thanks.