Page 1 of 1

Replace variables in XLSX

PostPosted: Wed Dec 17, 2014 7:50 pm
by soldjer
Hi,

im trying to replace variables in a simple XSLX file (attached) but I'm getting a UnmarshalException. I'm using Word 2010 on Win 8.1. Please advise.

Code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
File inputFile = new File("C:/Temp/sample2.xlsx");
File outputFile = new File("C:/Temp/sample2_output.xlsx");
               
SpreadsheetMLPackage opcPackagepkg = SpreadsheetMLPackage.load(inputFile);
WorksheetPart sheet = (WorksheetPart) opcPackagepkg.getParts().get(new PartName("/xl/worksheets/sheet1.xml"));
               
HashMap<String, String> mappings = new HashMap<String, String>();
mappings.put("title1", "This is a title");

sheet.variableReplace(mappings);
opcPackagepkg.save(outputFile);
 
Parsed in 0.016 seconds, using GeSHi 1.0.8.4


Log and stacktrace:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
[main] INFO org.xlsx4j.jaxb.Context - Using JAXB Reference Implementation
[main] INFO org.xlsx4j.jaxb.Context - Not using MOXy.
[main] INFO org.docx4j.openpackaging.packages.SpreadsheetMLPackage - Set shortcut for WorkbookPart
[main] INFO org.docx4j.openpackaging.io3.Load3 - package read;  elapsed time: 4324 ms
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - Lazily unmarshalling /xl/worksheets/sheet1.xml
[main] WARN org.docx4j.jaxb.JaxbValidationEventHandler - [(non)FATAL_ERROR] : unexpected element (uri:"http://schemas.openxmlformats.org/spreadsheetml/2006/main", local:"worksheet"). Expected elemen
[main] INFO org.docx4j.jaxb.JaxbValidationEventHandler - continuing (with possible element/attribute loss)
Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.openxmlformats.org/spreadsheetml/2006/main", local:"worksheet"). Expected elements are <{urn:schemas-microsoft-com:office:excel}ClientData>,<{http://schemas.microsoft.com/office/2006/coverPageProps}CoverPageProperties>,<{urn:schemas-microsoft-com:office:office}OLEObject>,<{http://opendope.org/SmartArt/DataHierarchy}SmartArtDataHierarchy>,<{http://schemas.openxmlformats.org/officeDocument/2006/bibliography}Sources>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}abstractNum>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}alias>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}altChunk>,<{http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing}anchor>,<{urn:schemas-microsoft-com:office:word}anchorlock>,<{http://opendope.org/conditions}and>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}annotationRef>,<{http://opendope.org/answers}answer>,<{http://opendope.org/answers}answers>,<{http://schemas.microsoft.com/office/word/2012/wordml}appearance>,<{urn:schemas-microsoft-com:vml}arc>,<{urn:schemas-microsoft-com:vml}background>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bibliography>,<{http://schemas.openxmlformats.org/drawingml/2006/main}blip>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}body>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkStart>,<{urn:schemas-microsoft-com:office:word}borderbottom>,<{urn:schemas-microsoft-com:office:word}borderleft>,<{urn:schemas-microsoft-com:office:word}borderright>,<{urn:schemas-microsoft-com:office:word}bordertop>,<{urn:schemas-microsoft-com:office:office}bottom>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}br>,<{urn:schemas-microsoft-com:office:office}callout>,<{http://schemas.openxmlformats.org/drawingml/2006/chart}chart>,<{http://schemas.openxmlformats.org/drawingml/2006/chart}chartSpace>,<{http://schemas.microsoft.com/office/word/2012/wordml}chartTrackingRefBased>,<{http://schemas.microsoft.com/office/word/2010/wordml}checkbox>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}citation>,<{urn:schemas-microsoft-com:office:office}clippath>,<{http://schemas.microsoft.com/office/word/2012/wordml}collapsed>,<{http://schemas.microsoft.com/office/word/2012/wordml}color>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}color>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}colorsDef>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}colorsDefHdr>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}colorsDefHdrLst>,<{urn:schemas-microsoft-com:office:office}column>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentReference>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}comments>,<{http://schemas.microsoft.com/office/word/2012/wordml}commentsEx>,<{urn:schemas-microsoft-com:office:office}complex>,<{http://opendope.org/components}components>,<{http://opendope.org/conditions}condition>,<{http://opendope.org/conditions}conditionref>,<{http://opendope.org/conditions}conditions>,<{http://schemas.microsoft.com/office/word/2010/wordml}conflictMode>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}continuationSeparator>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}cr>,<{urn:schemas-microsoft-com:vml}curve>,<{http://schemas.microsoft.com/office/word/2010/wordml}customXmlConflictDelRangeEnd>,<{http://schemas.microsoft.com/office/word/2010/wordml}customXmlConflictDelRangeStart>,<{http://schemas.microsoft.com/office/word/2010/wordml}customXmlConflictInsRangeEnd>,<{http://schemas.microsoft.com/office/word/2010/wordml}customXmlConflictInsRangeStart>,<{http://schemas.microsoft.com/office/word/2012/wordml}dataBinding>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}dataBinding>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}dataModel>,<{http://schemas.microsoft.com/office/drawing/2008/diagram}dataModelExt>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}dayLong>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}dayShort>,<{http://schemas.microsoft.com/office/word/2010/wordml}defaultImageDpi>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}del>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}delText>,<{urn:schemas-microsoft-com:office:office}diagram>,<{http://schemas.microsoft.com/office/word/2010/wordml}discardImageEditingData>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}docDefaults>,<{http://schemas.microsoft.com/office/word/2010/wordml}docId>,<{http://schemas.microsoft.com/office/word/2012/wordml}docId>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}document>,<{http://schemas.microsoft.com/office/drawing/2008/diagram}drawing>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}drawing>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}endnoteRef>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}endnotes>,<{http://schemas.microsoft.com/office/word/2010/wordml}entityPicker>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}equation>,<{urn:schemas-microsoft-com:office:office}extrusion>,<{urn:schemas-microsoft-com:office:office}fill>,<{urn:schemas-microsoft-com:vml}fill>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fldChar>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fldSimple>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fonts>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}footerReference>,<{http://schemas.microsoft.com/office/word/2012/wordml}footnoteColumns>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}footnoteRef>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}footnotes>,<{urn:schemas-microsoft-com:vml}formulas>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ftr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}glossaryDocument>,<{http://schemas.openxmlformats.org/drawingml/2006/main}graphic>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}group>,<{urn:schemas-microsoft-com:vml}group>,<{urn:schemas-microsoft-com:vml}handles>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}hdr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}headerReference>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}highlight>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}hyperlink>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}id>,<{urn:schemas-microsoft-com:vml}image>,<{http://opendope.org/SmartArt/DataHierarchy}imageRef>,<{urn:schemas-microsoft-com:vml}imagedata>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ind>,<{urn:schemas-microsoft-com:office:office}ink>,<{http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing}inline>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ins>,<{urn:schemas-microsoft-com:office:powerpoint}iscomment>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}jc>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}lastRenderedPageBreak>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}layoutDef>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}layoutDefHdr>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}layoutDefHdrLst>,<{urn:schemas-microsoft-com:office:office}left>,<{http://schemas.openxmlformats.org/drawingml/2006/compatibility}legacyDrawing>,<{urn:schemas-microsoft-com:vml}line>,<{http://opendope.org/SmartArt/DataHierarchy}list>,<{http://opendope.org/SmartArt/DataHierarchy}listItem>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}lock>,<{urn:schemas-microsoft-com:office:office}lock>,<{http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas}lockedCanvas>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}lvlOverride>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}mathPr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}monthLong>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}monthShort>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}noBreakHyphen>,<{http://opendope.org/conditions}not>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}numPicBullet>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}numPr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}numbering>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMath>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMathPara>,<{http://opendope.org/conditions}or>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}outlineLvl>,<{urn:schemas-microsoft-com:vml}oval>,<{http://opendope.org/SmartArt/DataHierarchy}p>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}p>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}pBdr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}pPr>,<{urn:schemas-microsoft-com:vml}path>,<{http://schemas.microsoft.com/office/word/2012/wordml}people>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}pgNum>,<{http://schemas.openxmlformats.org/drawingml/2006/picture}pic>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}pict>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}picture>,<{urn:schemas-microsoft-com:vml}polyline>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}proofErr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ptab>,<{http://opendope.org/questions}question>,<{http://opendope.org/questions}questionnaire>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}r>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rFonts>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rPr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rStyle>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}recipients>,<{urn:schemas-microsoft-com:vml}rect>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}relIds>,<{http://opendope.org/answers}repeat>,<{http://schemas.microsoft.com/office/word/2012/wordml}repeatingSection>,<{http://schemas.microsoft.com/office/word/2012/wordml}repeatingSectionItem>,<{http://opendope.org/questions}response>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}richText>,<{urn:schemas-microsoft-com:office:office}right>,<{urn:schemas-microsoft-com:vml}roundrect>,<{http://schemas.openxmlformats.org/schemaLibrary/2006/main}schemaLibrary>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sdt>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sdtContent>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sdtPr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sectPr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}separator>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}settings>,<{urn:schemas-microsoft-com:vml}shadow>,<{urn:schemas-microsoft-com:vml}shape>,<{urn:schemas-microsoft-com:office:office}shapedefaults>,<{urn:schemas-microsoft-com:office:office}shapelayout>,<{urn:schemas-microsoft-com:vml}shapetype>,<{http://opendope.org/SmartArt/DataHierarchy}sibTransBody>,<{urn:schemas-microsoft-com:office:office}signatureline>,<{urn:schemas-microsoft-com:office:office}skew>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}smartTag>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}softHyphen>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}spacing>,<{urn:schemas-microsoft-com:vml}stroke>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}style>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}styleDef>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}styleDefHdr>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}styleDefHdrLst>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}styles>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sym>,<{http://schemas.openxmlformats.org/drawingml/2006/diagram}t>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}t>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tab>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tabs>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tag>,<{http://schemas.openxmlformats.org/drawingml/2006/main}tbl>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tbl>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tblGrid>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tblPr>,<{http://schemas.openxmlformats.org/drawingml/2006/main}tblStyleLst>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tc>,<{http://opendope.org/SmartArt/DataHierarchy}textBody>,<{urn:schemas-microsoft-com:vml}textbox>,<{urn:schemas-microsoft-com:office:powerpoint}textdata>,<{urn:schemas-microsoft-com:vml}textpath>,<{http://schemas.openxmlformats.org/drawingml/2006/main}theme>,<{http://schemas.openxmlformats.org/drawingml/2006/main}themeManager>,<{http://schemas.openxmlformats.org/drawingml/2006/main}themeOverride>,<{urn:schemas-microsoft-com:office:office}top>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}txbxContent>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}u>,<{http://schemas.openxmlformats.org/drawingml/2006/chart}userShapes>,<{http://schemas.microsoft.com/office/word/2006/wordml}vbaSuppData>,<{http://schemas.microsoft.com/office/word/2012/wordml}webExtensionCreated>,<{http://schemas.microsoft.com/office/word/2012/wordml}webExtensionLinked>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}webSettings>,<{urn:schemas-microsoft-com:office:word}wrap>,<{http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing}wsDr>,<{}xml>,<{http://opendope.org/xpaths}xpath>,<{http://opendope.org/conditions}xpathref>,<{http://opendope.org/xpaths}xpaths>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}yearLong>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}yearShort>
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642)
        at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:254)
        at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:249)
        at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1049)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:478)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
        at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:379)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:605)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:125)
        at org.docx4j.XmlUtils.unmarshalString(XmlUtils.java:433)
        at org.docx4j.XmlUtils.unmarshallFromTemplate(XmlUtils.java:482)
        at org.docx4j.XmlUtils.unmarshallFromTemplate(XmlUtils.java:475)
        at org.docx4j.openpackaging.parts.JaxbXmlPart.variableReplace(JaxbXmlPart.java:252)
        at hr.evolva.util.xlsx.SampleReplaceTokens.main(SampleReplaceTokens.java:28)
 
Parsed in 0.021 seconds, using GeSHi 1.0.8.4



Thanks,
Daniel

Re: Replace variables in XLSX

PostPosted: Thu Dec 18, 2014 1:58 pm
by jason
Hi Daniel

Please see

https://github.com/plutext/docx4j/commi ... 4d388034c5

for necessary patch and working example.

You can of course build it yourself, or wait until later for a nightly build.

cheers .. Jason

Re: Replace variables in XLSX

PostPosted: Sat Dec 20, 2014 12:28 am
by soldjer
Great! Thanks.



Daniel

Re: Replace variables in XLSX

PostPosted: Sat Apr 14, 2018 2:47 am
by Frederic
Hi,

I don't success to use VariableReplace.java.
I tried with the example and with this code :

Code: Select all
final Parts parts = opcPackagepkg.getParts();

final Set<PartName> keySet = parts.getParts().keySet();

HashMap<String, String> mappings = new HashMap<String, String>();
mappings.put("title1", "mon titre 1");
mappings.put("subtitle1", "mon sous-titre 1");
mappings.put("title2", "mon titre 2");
mappings.put("subtitle2", "mon sous-titre 2");

for (PartName partName : keySet) {
   if (parts.get(partName) instanceof JaxbSmlPart) {

      JaxbSmlPart smlPart = (JaxbSmlPart) parts.get(partName);

      smlPart.variableReplace(mappings);

      break;

   }
}

opcPackagepkg.save(new File(outputfilepath));


But no change.

Thanks

Re: Replace variables in XLSX

PostPosted: Sat Apr 14, 2018 9:31 am
by jason
I guess your variables are in the SharedStrings part

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
public class SharedStrings  extends JaxbSmlPart<CTSst> {
       
        public SharedStrings(PartName partName) throws InvalidFormatException {
                super(partName);
                init();
        }

        public SharedStrings() throws InvalidFormatException {
                super(new PartName("/xl/sharedStrings.xml"));
                init();
        }
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


Try .variableReplace on that.

If it doesn't work, you should unzip your xlsx and look in both parts to see how your variable is represented. Please post the XML here.

Re: Replace variables in XLSX

PostPosted: Mon Apr 16, 2018 6:44 pm
by Frederic
It's ok.
I forgot to put ${blabla} for my variables.