該方法只是把ASP.Net頁面保存成Html頁面只是把後綴改為xlc不過Excel可以讀取,接下連我看看還有別的方式能導出數據,並利用模版生成。
下面是代碼
縣新建一個ASP.ne的tweb應用程序把代碼粘貼進去就好了
Html頁面代碼
<%@ Page language="c#" Codebehind="OutExcel.ASPx.cs" AutoEventWireup="false" Inherits="eMeng.Exam.OutPutExcel" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD Html 4.0 Transitional//EN" >
<Html>
<HEAD>
<title>OutPutExcel</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<ASP:datagrid id="DataGrid1" runat="server">
<Columns>
<asp:BoundColumn></ASP:BoundColumn>
</Columns>
</ASP:datagrid>
<P>
<asp:Label id="Label1" runat="server">文件名:</ASP:Label>
<asp:TextBox id="TextBox1" runat="server"></ASP:TextBox>
<asp:button id="Button1" runat="server" Text="輸出到Excel"></ASP:button></P>
</form>
</body>
</Html>
接下來是cs頁面裡的代碼
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClIEnt;
namespace eMeng.Exam
{
/// <summary>
/// OutPutExcel 的摘要說明。
/// </summary>
public class OutPutExcel : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label1;
private DataSet myDS =new DataSet();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
if(!Page.IsPostBack)
{
Data_Load();//調用方法填充表格
}
}
/// <summary>
/// 創建數據源
/// </summary>
/// <returns&