Convert Calc(Excel) Data in XML in OpenOffice

强颜欢笑 提交于 2019-11-30 21:38:52

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() &gt; 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.

Roman Badiornyi

You can download OpenXmlSDK Open XML SDK It contains Productivity Tools which could help you to discover structure of excel documents, for example:

And then use any available XSLT tutorial to find out about approaches of conversion one XML structure to another

Tutorial 1

Java tutorial

And also this might help you:

https://github.com/foglcz/xsl-excel-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!