Question

2
Replies
1168
Views
Arun Kumar (Arun.Kothapalli)
BOS
Application Development Specialist
BOS
SG
Arun.Kothapalli Member since 2016 12 posts
BOS
Posted: November 20, 2018
Last activity: November 20, 2018
Posted: 20 Nov 2018 7:20 EST
Last activity: 20 Nov 2018 16:26 EST
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, This thread is closed to future replies. Content and links will no longer be updated. If you have the same/similar Question, please write a new Question.