我能够创建一个旧格式的xls文件,即Microsoft Spreadsheet 97-2003,但我宁愿选择更新的东西。
如何创建更新的xlsx格式?
我使用javax.xml.transform
java包。
这是一段java代码
tFactory = TransformerFactory.newInstance();
transformer = tFactory.newTransformer(new StreamSource("file.xslt"));
transformer.transform(streamSource, new StreamResult(new FileOutputStream(filenameXls)));
我尝试使用不同的xsl样式表定义,但它没有帮助。
这是我的xlst文件。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:output method="html" encoding="utf-8" indent="yes" doctype-public="-//W3C//DTD XHTML 1.1 Strict//EN" version="1.0"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" xml:lang="pl" />
<xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."/>
<xsl:template match="/">
<Worksheet ss:Protected="0" ss:Name="Name">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
td {
margin:auto;
text-align:center;
vertical-align:middle;
}
table th h2 {
background-color:rgb(198,239,206);
}
th.important {
background-color:rgb(255,235,166);
}
</style>
</head>
<body>
<table border="1">
<tr><th>
<h2>Articles</h2>
</th></tr>
</table>
<table border="1">
<tr>
<th>Lp.</th>
<th class="important">Title</th>
<th class="important">Date</th>
<th class="important">Autors</th>
<th class="important">Afilliated</th>
<th class="important">Employed</th>
</tr>
<xsl:for-each select="works/article">
<tr>
<td><xsl:value-of select="lp"/></td>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="publication-date"/></td>
<td>
<ul>
<xsl:for-each select="./author">
<li>
<xsl:value-of select="given-names"/> <xsl:value-of select="family-name"/>
</li>
</xsl:for-each>
</ul>
</td>
<td>
<ul>
<xsl:for-each select="./author">
<li>
<xsl:value-of select="affiliated-to-unit"/>
</li>
</xsl:for-each>
</ul>
</td>
<td>
<ul>
<xsl:for-each select="./author">
<li>
<xsl:value-of select="employed-in-unit"/>
</li>
</xsl:for-each>
</ul>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</Worksheet>
</xsl:template>
</xsl:stylesheet>