HI,
I need to export some xml data to an excel file. I've found a few ways of doing this on the web, but none of them quite fit what I want, and my knowledge of xml manipulation is not fantastic. The problem is:
I have some existing code in a web application which used to work but which now redirects you to a new page (as it should) with the title for the excel and the excel cells on it (as it should), but no data (as it shouldn't).
Two constraints are that
1. I need to open up the excel file in a web browser instead of the excel application itself
2. The xml input comes from a custom object, which returns an xml string. Because I'm working with an existing application, this can't be changed. So as I understand it, I need to work with xml data that is in memory rather than in a file.
I'm happy to consider changing the way the code works, but I need to stay within the contraints I just mentioned.....
Any help would be greatly appreciated.
The vb code is:
Response.Clear()
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
xmlTransform.TransformSource = "excel.xslt"
xmlTransform.DocumentContent = [custom object returning valid xml string]
xmlTransform.DataBind()
And excel.xslt is:
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns
="urn:schemas-microsoft-com
ffice
ffice"
xmlns:x="urn:schemas-microsoft-com
ffice:excel"
xmlns:ss="urn:schemas-microsoft-com
ffice:spreadsheet" >
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns
="urn:schemas-microsoft-com
ffice
ffice"
xmlns:x="urn:schemas-microsoft-com
ffice:excel"
xmlns:ss="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:apply-templates/>
</Workbook>
</xsl:template>
<xsl:template match="/*">
<Worksheet>
<xsl:attribute name="ss:Name">
<xsl:value-of select="local-name(/*/*)"/>
</xsl:attribute>
<Table x:FullColumns="1" x:FullRows="1">
<Row>
<xsl:for-each select="*[position() = 1]/*">
<Cell><Data ss:Type="String">
<xsl:value-of select="local-name()"/>
</Data></Cell>
</xsl:for-each>
</Row>
<xsl:apply-templates/>
</Table>
</Worksheet>
</xsl:template>
<xsl:template match="/*/*">
<Row>
<xsl:apply-templates/>
</Row>
</xsl:template>
<xsl:template match="/*/*/*">
<Cell><Data ss:Type="String">
<xsl:value-of select="."/>
</Data></Cell>
</xsl:template>
</xsl:stylesheet>
thanks!!
I need to export some xml data to an excel file. I've found a few ways of doing this on the web, but none of them quite fit what I want, and my knowledge of xml manipulation is not fantastic. The problem is:
I have some existing code in a web application which used to work but which now redirects you to a new page (as it should) with the title for the excel and the excel cells on it (as it should), but no data (as it shouldn't).
Two constraints are that
1. I need to open up the excel file in a web browser instead of the excel application itself
2. The xml input comes from a custom object, which returns an xml string. Because I'm working with an existing application, this can't be changed. So as I understand it, I need to work with xml data that is in memory rather than in a file.
I'm happy to consider changing the way the code works, but I need to stay within the contraints I just mentioned.....
Any help would be greatly appreciated.
The vb code is:
Response.Clear()
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
xmlTransform.TransformSource = "excel.xslt"
xmlTransform.DocumentContent = [custom object returning valid xml string]
xmlTransform.DataBind()
And excel.xslt is:
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns
xmlns:x="urn:schemas-microsoft-com
xmlns:ss="urn:schemas-microsoft-com
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com
xmlns
xmlns:x="urn:schemas-microsoft-com
xmlns:ss="urn:schemas-microsoft-com
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:apply-templates/>
</Workbook>
</xsl:template>
<xsl:template match="/*">
<Worksheet>
<xsl:attribute name="ss:Name">
<xsl:value-of select="local-name(/*/*)"/>
</xsl:attribute>
<Table x:FullColumns="1" x:FullRows="1">
<Row>
<xsl:for-each select="*[position() = 1]/*">
<Cell><Data ss:Type="String">
<xsl:value-of select="local-name()"/>
</Data></Cell>
</xsl:for-each>
</Row>
<xsl:apply-templates/>
</Table>
</Worksheet>
</xsl:template>
<xsl:template match="/*/*">
<Row>
<xsl:apply-templates/>
</Row>
</xsl:template>
<xsl:template match="/*/*/*">
<Cell><Data ss:Type="String">
<xsl:value-of select="."/>
</Data></Cell>
</xsl:template>
</xsl:stylesheet>
thanks!!