MS Excel XML to CSV
XSLT file excel2csv.xsl
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mso="urn:schemas-microsoft-com:office:spreadsheet" version="1.0">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:for-each select="mso:Workbook/mso:Worksheet/mso:Table/mso:Row">
<xsl:for-each select="mso:Cell">
<xsl:value-of select="mso:Data"/>
<xsl:if test="position()!=last()">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Important: you may replace 4 spaces in "<xsl:text> </xsl:text>" to single tabulation (or any other delimiter)!
Use as
cat file.xls | xsltproc excel2csv.xsl - > file.csv
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mso="urn:schemas-microsoft-com:office:spreadsheet" version="1.0">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:for-each select="mso:Workbook/mso:Worksheet/mso:Table/mso:Row">
<xsl:for-each select="mso:Cell">
<xsl:value-of select="mso:Data"/>
<xsl:if test="position()!=last()">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Important: you may replace 4 spaces in "<xsl:text> </xsl:text>" to single tabulation (or any other delimiter)!
Use as
cat file.xls | xsltproc excel2csv.xsl - > file.csv
Comments