XML结合XSLT生成Excel(导入到多个Worksheet)
2008-08-05 22:12
435 查看
1、.aspx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnExport" runat="server" OnClick="btnExport_Click" Text="Export" /></div>
</form>
</body>
</html>
2、code-behide
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text;
public partial class ExportAsExcel : System.Web.UI.Page
3、ExcelBuilder
using System;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Data;
using System.IO;
public class ExcelBuilder
4、XSLT(demo.xsl)
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
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">
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<ActiveSheet>1</ActiveSheet>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center"/>
<Borders/>
<Font ss:FontName="Arial" x:CharSet="134" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s67">
<Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:Indent="1"/>
<Font ss:FontName="Arial" x:CharSet="134" ss:Size="11" ss:Color="#000000"
ss:Bold="1"/>
<NumberFormat ss:Format="@"/>
</Style>
<Style ss:ID="s68">
<Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:Indent="1"/>
<NumberFormat ss:Format="@"/>
</Style>
</Styles>
<Worksheet ss:Name="employee">
<Table ss:ExpandedColumnCount="2" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="13.5">
<Column ss:StyleID="s68" ss:Width="85.5"/>
<Column ss:StyleID="s68" ss:Width="99"/>
<Row>
<Cell ss:StyleID="s67">
<Data ss:Type="String">employeeId</Data>
</Cell>
<Cell ss:StyleID="s67">
<Data ss:Type="String">title</Data>
</Cell>
</Row>
<xsl:for-each select="NewDataSet/Table">
<Row>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="employeeId" />
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="title" />
</Data>
</Cell>
</Row>
</xsl:for-each>
</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>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="sale">
<Table ss:ExpandedColumnCount="2" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="13.5">
<Column ss:StyleID="s68" ss:Width="85.5"/>
<Column ss:StyleID="s68" ss:Width="99"/>
<Row>
<Cell ss:StyleID="s67">
<Data ss:Type="String">productId</Data>
</Cell>
<Cell ss:StyleID="s67">
<Data ss:Type="String">productName</Data>
</Cell>
</Row>
<xsl:for-each select="NewDataSet/Table1">
<Row>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="productId" />
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="productName" />
</Data>
</Cell>
</Row>
</xsl:for-each>
</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>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnExport" runat="server" OnClick="btnExport_Click" Text="Export" /></div>
</form>
</body>
</html>
2、code-behide
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text;
public partial class ExportAsExcel : System.Web.UI.Page
3、ExcelBuilder
using System;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Data;
using System.IO;
public class ExcelBuilder
4、XSLT(demo.xsl)
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
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">
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<ActiveSheet>1</ActiveSheet>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center"/>
<Borders/>
<Font ss:FontName="Arial" x:CharSet="134" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s67">
<Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:Indent="1"/>
<Font ss:FontName="Arial" x:CharSet="134" ss:Size="11" ss:Color="#000000"
ss:Bold="1"/>
<NumberFormat ss:Format="@"/>
</Style>
<Style ss:ID="s68">
<Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:Indent="1"/>
<NumberFormat ss:Format="@"/>
</Style>
</Styles>
<Worksheet ss:Name="employee">
<Table ss:ExpandedColumnCount="2" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="13.5">
<Column ss:StyleID="s68" ss:Width="85.5"/>
<Column ss:StyleID="s68" ss:Width="99"/>
<Row>
<Cell ss:StyleID="s67">
<Data ss:Type="String">employeeId</Data>
</Cell>
<Cell ss:StyleID="s67">
<Data ss:Type="String">title</Data>
</Cell>
</Row>
<xsl:for-each select="NewDataSet/Table">
<Row>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="employeeId" />
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="title" />
</Data>
</Cell>
</Row>
</xsl:for-each>
</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>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="sale">
<Table ss:ExpandedColumnCount="2" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="13.5">
<Column ss:StyleID="s68" ss:Width="85.5"/>
<Column ss:StyleID="s68" ss:Width="99"/>
<Row>
<Cell ss:StyleID="s67">
<Data ss:Type="String">productId</Data>
</Cell>
<Cell ss:StyleID="s67">
<Data ss:Type="String">productName</Data>
</Cell>
</Row>
<xsl:for-each select="NewDataSet/Table1">
<Row>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="productId" />
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="productName" />
</Data>
</Cell>
</Row>
</xsl:for-each>
</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>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>
相关文章推荐
- 使用.NET生成XML时导入XSLT
- Excel 数据导入SQL XML 自动生成表头
- Struts2中定义新的返回类型---返回XML字符串并结合XSLT生成HTML
- 使用XML数据结合XSLT导出Excel
- JAVA使用HSSFWorkbook生成导入Excel 的用法
- 将Excel生成SQL语句完成数据库导入
- 利用XML生成Excel
- 结合AnyChart做报表:一个生成AnyChart图形XML数据的工具类
- Python实现将xml导入至excel
- java 将 txt、excel 、xml 文档导入数据库
- Excel组件Spire.XLS 教程:将Excel导出到XML和XML导入Excel
- asp.net中利用XML描述文件和Excel模板相结合的方法生成Excel报表
- spring里结合POI生成EXCEL
- js将load xml xslt文件生成html
- 分析SQL server表数据结构生成XML数据字典+XSLT生成可视文档
- Java 使用poi导入excel,结合xml文件进行数据验证的例子(增加了jar包)
- (转)ASP.NET读出XML数据生成Excel
- 学习笔记 --- XML、生成Excel、XML加密解密
- php与XML、XSLT、Mysql的结合运用实现代码
- 通过excel可识别的xml结构直接生成xls文件收藏