I have a requirement to convert OpenOffice Excel data into XML . I have Apache OpenOffice 4.1.1 in my machine (not MS- Office).
Sample Data. (First Row is of Tags )
CustData FirstName MiddleName LastName EMail PhoneNumber
abe x Park [email protected] 2323232323
poppy y Kaith [email protected] 2323232323
Need Result as :
<CustData>
<FirstName>abe</FirstName>
<MiddleName>x</MiddleName>
<LastName>Park</LastName>
<EMail>[email protected]</EMail>
<PhoneNumber>2323232323</PhoneNumber>
</CustData>
<CustData>
<FirstName>poppy</FirstName>
<MiddleName>y</MiddleName>
<LastName>Kaith</LastName>
<EMail>[email protected] </EMail>
<PhoneNumber>2323232323</PhoneNumber>
</CustData>
Openoffice and Libreoffice Calc is able transforming its XML via XSLT
with Export Filters
. To do so with your example data, do the following:
At first create the following XSL file and save it as SampleDataExportFilter.xsl
:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" exclude-result-prefixes="office table text">
<xsl:template match="/">
<root>
<xsl:apply-templates select="/*/office:body" />
</root>
</xsl:template>
<xsl:template match="office:body">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="office:spreadsheet">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="office:spreadsheet/table:table">
<xsl:for-each select="table:table-row[position() > 1]">
<CustData>
<FirstName><xsl:value-of select="table:table-cell[2]/text:p" /></FirstName>
<MiddleName><xsl:value-of select="table:table-cell[3]/text:p" /></MiddleName>
<LastName><xsl:value-of select="table:table-cell[4]/text:p" /></LastName>
<EMail><xsl:value-of select="table:table-cell[5]/text:p" /></EMail>
<PhoneNumber><xsl:value-of select="table:table-cell[6]/text:p" /></PhoneNumber>
</CustData>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Now open Calc and select Tools
- XML Filter Settings
:
Select New
and fill the dialog General
:
In the register Transformation
select the SampleDataExportFilter.xsl
as XSLT for export
:
Confirm with OK
and the XML Filter Settings with Close
.
Now create the following Calc file:
With File
- Export
you shold now be able to export the spreadsheet data using the File type
CustData (.xml)
as XML.