I’m using the .Net framework’s XslCompiledTransform class as the XSLT processor (in other words Xslt 1.0).
My requirement is that I want to convert an XML file to an Excel file (xls file) using XSLT 1.0 and .Net [4.0].
For simplicity and since this is just test code, I’m just considering some simple hard-coding on my Xsl file.
Specifically, my two questions are:
- I’ve tried a bunch of things, yet I can’t see my Excel sheet’s worksheet named to “wAbc” which is what I’m trying to name it. I see the worksheet name as my file name. Additional worksheets are not generated as well. Below is my XSL file
-
Additionally, since this is test code, I can’t see the data outputted on different rows unless I use HTML tags . What I see is:
AbcNext lineinstead ofAbc
Nextline
So what am I doing wrong? Thank you in advance for your time and help.
I set the content type for my file response as
application/vnd.ms-excel
Here is my test Xsl file:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:template match="/">
<xsl:processing-instruction name="mso-application">progid='Excel.Sheet'</xsl:processing-instruction>
<Workbook>
<Worksheet ss:Name="wAbc">
<Table ss:ExpandedColumnCount="2" x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="15">
<Column ss:AutoFitWidth="20" ss:AutoWidth="65"></Column>
<Row>
<Cell>
<Data ss:Type="String">Abc</Data>
</Cell>
</Row>
<Row>
<Cell>
<Data ss:Type="String">Next line</Data>
</Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Header x:Margin="0.3"/>
<Footer x:Margin="0.3"/>
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
</PageSetup>
</WorksheetOptions>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>
Excel
XLSfiles use a Microsoft proprietary binary format – no way to generate that with an XSLT.The (relatively) new
XSLXformat is a set of XML files that are ZIPped together, so in principle you can generate these files with an XSLT, and then ZIP them to generate the final file – still not very easy. To see these files simply un-ZIP anXSLXfile.I suggest you generate a simpler format – either a CSV or an intermediate XML- and then import it into Excel.