資源簡介
說明:
用C#實現“將Web網頁導出至Word文檔”^_^

代碼片段和文件信息
using?System;
using?System.Configuration;
using?System.Data;
using?System.Data.SqlClient;
using?System.IO;
using?System.Text;
using?System.Web;
using?System.Web.UI;
public?partial?class?_Default?:?Page
{
????protected?void?Page_Load(object?sender?EventArgs?e)
????{
????????if?(!IsPostBack)
????????{
????????????DataBind();
????????}
????}
????private?void?DataBind()
????{
????????string?strCon?=?ConfigurationManager.ConnectionStrings[“GoodsSell“].ConnectionString;
????????var?connection?=?new?SqlConnection(strCon);
????????connection.Open();
????????string?strSQL?=?“select?*?from?GoodsSell“;
????????var?adapter?=?new?SqlDataAdapter(strSQL?connection);
????????var?dataSet?=?new?DataSet();
????????adapter.Fill(dataSet);
????????GridView1.DataSource?=?dataSet;
????????GridView1.DataBind();
????}
????protected?void?btnPut_Click(object?sender?EventArgs?e)
????{
????????Response.AddHeader(“Content-Disposition“
???????????????????????????“attachment;filename=“?+?HttpUtility.UrlEncode(“商品銷售信息.doc“?Encoding.UTF8));
????????Response.ContentType?=?“application/ms-word“;
????????EnableViewState?=?false;
????????var?tw?=?new?StringWriter();
????????var?hw?=?new?HtmlTextWriter(tw);
????????GridView1.RenderControl(hw);
????????Response.Write(tw.ToString());
????????Response.End();
????}
????public?override?void?VerifyRenderingInServerForm(Control?control)
????{
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-11-24?07:35??Web2Word\
?????文件????????2100??2011-11-24?07:32??Web2Word\Default.aspx
?????文件????????1448??2011-11-24?07:32??Web2Word\Default.aspx.cs
?????文件?????????293??2011-11-24?07:32??Web2Word\Web.config
?????目錄???????????0??2011-11-24?07:35??Web2Word\數據庫腳本\
?????文件????????1240??2011-11-24?07:34??Web2Word\數據庫腳本\sc
評論
共有 條評論