直接将页面导出
html
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2"
ValidateRequest="false" %>
<!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>无标题页</title>
<script language="javascript" type="text/javascript">
function ToExcel()
{
var html=document.getElementById("txt_html");
var val=document.getElementById("div_repeat1").innerHTML;
html.value=val;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id='div_repeat1'>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
aa</td>
<td>
<table>
<tr>
<td>
bbb</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" OnClientClick="javascript:ToExcel(this)" /></div>
</div>
<asp:TextBox ID="txt_html" runat="server" Style="display: none"></asp:TextBox>
</form>
</body>
</html>
===cs
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.IO;
using System.Text.RegularExpressions;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string mm = "ASAAAAAAAAAAAAAAAAAAAAVEWR";
Repeater1.DataSource = mm.ToCharArray();
Repeater1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Report.xls");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.Write(Regex.Replace(txt_html.Text , @"(<(a|A)(.*)>)(.*)(<\/(a|A)>)", "$4").Replace("\"GridView1\"", "\"GridView1\" border=1"));
HttpContext.Current.Response.End();
}
}
2.利用这个导出。不用安装EXCEL。支持合并
页面有必要一定用导的吧。生成一个excel文件不久得了,就像生成xml差不多,省得麻烦