Question

2
Replies
1011
Views
Arun.Kothapalli Member since 2016 9 posts
BOS
Posted: 1 year ago
Last activity: 1 year 10 months ago
Closed

Generating Word document (docx format)

Hi All,

I have a requirement, where I need to read a word document from one server location update and save back to a different location on the server.

Reading a file from the server, I have no issues. But updating the word template document is not happing even after hardcoding the values. Need advice ASAP

I tried using the below methods, but unable to generate
1. Using Docx4J
2. Using Apache POI
3. Unable use Aspose (Due to some issue in importing, Aspose jar's classes are not exploded into prEngineClass.

Below is the sample codes,

Docx4J
org.docx4j.openpackaging.packages.WordprocessingMLPackage.createPackage();

try {
org.docx4j.openpackaging.packages.WordprocessingMLPackage wordPackage = org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(new java.io.FileInputStream(new java.io.File("Sample 1.docx")));
org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
org.docx4j.model.datastorage.migration.VariablePrepare.prepare(wordPackage);
// ClipboardPage NewPage=tools.findPage("pyWorkPage");
java.util.HashMap<String, String> variables = new java.util.HashMap<>();
variables.put("$LastModifiedDateTime»e", "20181119");
variables.put("$CaseID", "Test1234");
variables.put("$CaseTitle»", "Auto Loan Case");
variables.put("$CreationDateTime", "20181119");
mainDocumentPart.variableReplace(variables);
wordPackage.save(new java.io.File("Merge.docx"));
}
catch (Exception e)
{
oLog.error("Unable to read file.", e);
throw new PRRuntimeException("Unable to read file.", e);
}
***Edited by Moderator Marissa to update platform capability tags****
Pega Platform Low-Code App Development Data Integration Java and Activities Case Management
Moderation Team has archived post
Share this page LinkedIn