在 OpenOffice 中将 Calc(Excel) 数据转换为 XML [英] Convert Calc(Excel) Data in XML in OpenOffice

查看:23
本文介绍了在 OpenOffice 中将 Calc(Excel) 数据转换为 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 OpenOffice Excel 数据转换为 XML .我的机器上装有 Apache OpenOffice 4.1.1(不是 MS-Office).

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      abe@mail.com       2323232323
           poppy     y          Kaith     Poppy@mail.com     2323232323

需要结果为:

<CustData>
        <FirstName>abe</FirstName>  
        <MiddleName>x</MiddleName>
        <LastName>Park</LastName>   
        <EMail>abe@mail.com</EMail>             
        <PhoneNumber>2323232323</PhoneNumber>
</CustData>
<CustData>
       <FirstName>poppy</FirstName>  
       <MiddleName>y</MiddleName>
       <LastName>Kaith</LastName>   
        <EMail>Poppy@mail.com </EMail>             
        <PhoneNumber>2323232323</PhoneNumber>
</CustData>

推荐答案

Openoffice 和 Libreoffice Calc 能够通过 XSLTExport Filters 转换其 XML.要使用您的示例数据执行此操作,请执行以下操作:

Openoffice and Libreoffice Calc is able transforming its XML via XSLT with Export Filters. To do so with your example data, do the following:

首先创建以下XSL文件并保存为SampleDataExportFilter.xsl:

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>

现在打开Calc并选择Tools - XML Filter Settings:

Now open Calc and select Tools - XML Filter Settings:

选择New并填充对话框General:

在寄存器Transformation中选择SampleDataExportFilter.xsl作为XSLT for export:

使用 OK 确认,使用 Close 确认 XML 过滤器设置.

Confirm with OK and the XML Filter Settings with Close.

现在创建以下 Calc 文件:

Now create the following Calc file:

使用 File - Export 您现在可以使用 File type CustData (.xml) 导出电子表格数据 作为 XML.

With File - Export you shold now be able to export the spreadsheet data using the File type CustData (.xml) as XML.

这篇关于在 OpenOffice 中将 Calc(Excel) 数据转换为 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆