模板代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductExportTemplate.aspx.cs" Inherits="ETOT.WebUI.Temp.ProductExportTemplate" %>
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="ProgId" content="Excel.Sheet">
    <meta name="Generator" content="Microsoft Excel 14">
    <link rel="File-List" href="Book1_files/filelist.xml">
    <style id="Book1_18375_Styles">
    ...
    </style>
</head>
<body>
    <div>
        <table>
            <tr><th>产品名称</th><th>产品规格</th>...</tr>
                <%foreach (var o in products){%>
                <tr>
                   <td>o.Name</td><td>o.Spec</td>...</tr>
                <%}%>
        </table>
    </div>
</body>
后台Page_Load事件中会获取products 列表对象。
而且加入了这两句
protected void Page_Load(object sender, EventArgs e)
{
    Response.AppendHeader("Content-Description", "attachment;filename=ProductImprotTemplate.xls");
    Response.ContentType = "application/vnd.ms-excel";
    products = .....
}
然后在一个页面上通过<a href="ProductExportTemplate.aspx?productId=0001">导出数据</a>
如此可以将Excel导出。可是当导出的数据进行修改后保存,就会在Excel文件所在位置出现 文件名_file的文件夹。而且Excel的样式、数据被保存到这个文件夹下的xml里面去了。一个整体的Excel文件被分成几个文件了。不知道这个问题如果解决,还有就是如何以这种方式改变导出文件的名称,请各位不舍赐教。