我在 unix 環境中有幾個 excel 作業表。我的目標是將它們合并到 unix 環境中的一個作業簿中。
我找到了一個使用 xsltproc 的解決方案,它可以作業,但不能完全完成作業。(將多個 excel 檔案合并到一個 excel 作業簿中,但使用 bash 腳本將不同的作業表合并)
根據上述鏈接中提供的答案,這是我當前的作業流程:
- 將每個 *.xlsx 表轉換為 *.fods 檔案
soffice --headless --convert-to fods file*.xlsx
- 使用 xsltproc 一張一張地合并 *.fods 作業表,得到一個包含所有作業表的作業簿。
- 使用以下命令將 *.fods 作業簿轉換回 *.xlsx:
soffice --headless --convert-to xslx outputfile*.fods
我被卡住的地方是#2。鏈接中的原始答案提供了一個基于 xsltproc 的解決方案,它可以合并兩個作業表。我正在嘗試通過以下方法逐步擴展它:
xsltproc --stringparam secondfile file2.fods tablemerge.xsl file1.fods > int_2.fods
xsltproc --stringparam secondfile file3.fods tablemerge.xsl int_2.fods > final.fods
只要只合并2 張紙,它就可以完美運行,但是當我嘗試將 file3.fods 添加到中間檔案 int_2.fods 時,它的行為出乎意料。
我看到的問題是 final.fods 包含 file3.fods 中作業表的兩個副本。
我懷疑它的tablemerge.xsl 檔案有問題,該檔案最后包含一些 xml 語法(如下)。問題是我不知道 xml 是如何作業的,但語法似乎不是很復雜。任何建議在下面的代碼中需要進行哪些修改的幫助都將非常有幫助。提前致謝。
tablemerge.xsl:
<?xml version="1.0" ?>
<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:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
xmlns:ooo="http://openoffice.org/2004/office"
xmlns:ooow="http://openoffice.org/2004/writer"
xmlns:oooc="http://openoffice.org/2004/calc"
xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rpt="http://openoffice.org/2005/report"
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:grddl="http://www.w3.org/2003/g/data-view#"
xmlns:tableooo="http://openoffice.org/2009/table"
xmlns:drawooo="http://openoffice.org/2010/draw"
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
xmlns:css3t="http://www.w3.org/TR/css3-text/"
office:version="1.2"
office:mimetype="application/vnd.oasis.opendocument.spreadsheet">
<xsl:template match="table:table">
<!-- copy table:table from main file -->
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
<table:table
table:name="{document($secondfile)//table:table/@table:name}"
table:style-name="{document($secondfile)//table:table/@table:style-name}">
<!-- copy table:table from second file -->
<xsl:copy-of select="document($secondfile)//table:table/child::*" />
</table:table>
</xsl:template>
<!-- default template: identity transform -->
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
編輯1
不知道如何完整地描述我所看到的,但我會嘗試一下。
I manually created a workbook with two sheets, and saved it as xlsx, followed by conversion to *.fods. Then i compare this new fods to the one which is generated from single worksheet. It does seem to indicate to me what exactly i need.
Inside the fods file, i see the below :
#1. In fods from single sheet , I see only one table:table section :
....
<office:spreadsheet>
<table:calculation-settings table:case-sensitive="false" table:automatic-find-labels="false" table:use-regular-expressions="false" table:use-wildcards="true"/>
<table:table table:name="Sheet1" table:style-name="ta1">
........
</table:table>
<table:named-expressions/>
</office:spreadsheet>
...
#2. In *.fods from two sheets , I see only two table:table sections :
....
<office:spreadsheet>
<table:calculation-settings table:case-sensitive="false" table:automatic-find-labels="false" table:use-regular-expressions="false" table:use-wildcards="true"/>
<table:table table:name="Sheet1" table:style-name="ta1">
........
</table:table>
<table:table table:name="Sheet2" table:style-name="ta2">
.......
</table:table>
<table:named-expressions/>
</office:spreadsheet>
...
I guess what i'm looking for is a tablemerge.xsl which can help me to merge two *.fods as in #1, and get something similar to *.fods in #2. Ofcourse the complication is that one of the *.fods being input can contain multiple sheets, and the final output *.fods should just concatenate the table:table section from second file into the first *.fods.
uj5u.com熱心網友回復:
這主要是猜測,因為我們不知道 .fods 檔案的確切規范 - 而且您甚至沒有向我們展示完整的示例。嘗試也許:
XSLT 1.0
<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">
<xsl:param name="secondfile"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="office:spreadsheet">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:copy-of select="document($secondfile)//table:table" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
這可能會或可能不會起作用,具體取決于office:spreadsheet(即table:calculation-settings和table:named-expressions)的其他子元素在其中扮演的角色,以及我無法預測的其他因素。
我什至不確定如何可靠地測驗結果“有效”;您可能會從其他檔案中獲取作業表,但它們可能缺少某些功能。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/389379.html
