I have to complete this task: I’m given a xml file which is exported from an application, I need to make an xlsx file out of it containing table hierarchy make changes to the xlsx file using excel then make it back to xml having all these changes. All this using Java. I’m aware of apache poi library. For xlsx you have to use XSSF instead of HSSF. I checked out their examples manipulating excel but I’m struggling around one point. Examples in the official poi websites are showing how to create xlsx file containing tables, cells containing various data but where goes the XML part and reading of XML file? I need xlsx file to look according to XML.
Any help or pointers into right direction would be greatly appreciated.
My XML example file:
<?xml version="1.0" encoding="utf-8" ?>
<data type="data">
<title>Duomenų suvedimo formos pavadinimas</title>
<fields>
<item id="org" label="Institucija/Įstaiga" valueField="orgId" labelField="orgLabel" tooltipField="orgTooltip" type="dim" />
<item id="R1" label="R1 pavadinimas" group="Katalogo pavadinimas" valueField="value1" type="value" inputEnabled="1" valueType="numeric"/>
<item id="R2" label="R2 pavadinimas" group="Katalogo pavadinimas" valueField="value2" type="value" inputEnabled="1" valueType="numeric"/>
<item id="R3" label="R3 išvestinis" group="Katalogo pavadinimas" valueField="value3" type="value" inputEnabled="0" valueType="numeric" formula="[R1]/12 + [R2]"/>
</fields>
<dataItems>
<item orgId="ins1" orgLabel="Institucija 1" orgTooltip="Institucija 1" grp="2" value1="10" value2="20" value3="" isval="1" edit="1" />
<item orgId="ins2" orgLabel="Institucija 2" orgTooltip="Institucija 2" grp="3" value1="15" value2="25" value3="" isval="1" edit="1" />
</dataItems>
</data>
There are two components to your problem –
You are right about the second part to use Apache POI. For the first part, you would need an XML parser and should plug it in before feeding data to XLSX generation program – try checking out JAXB or a simple parser example http://www.java-samples.com/showtutorial.php?tutorialid=152.
Post any specific issues. An XML sample of what you are trying to parse may help.