日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

.net导出到Excel与Word中(带上下标)

發(fā)布時間:2023/11/27 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .net导出到Excel与Word中(带上下标) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//輸出到excel的函數(shù),可直接copy到?cs頁面
????private?void?OutExcel(GridView?dg,?string?name)
????
{
????????dg.Visible?
=?true;
????????Response.Clear();
????????Response.Buffer?
=?true;
????????Response.Charset?
=?"GB2312";
????????name?
=?"attachment;filename="?+?name;
????????Response.AppendHeader(
"Content-Disposition",?name);
????????Response.ContentEncoding?
=?System.Text.Encoding.GetEncoding("GB2312");
????????Response.ContentType?
=?"application/ms-excel";
????????dg.EnableViewState?
=?false;
????????System.IO.StringWriter?oStringWriter?
=?new?System.IO.StringWriter();
????????System.Web.UI.HtmlTextWriter?oHtmlTextWriter?
=?new?System.Web.UI.HtmlTextWriter(oStringWriter);
????????dg.RenderControl(oHtmlTextWriter);
????????Response.Write(oStringWriter.ToString());
????????Response.End();
????}

????
//輸出到word的函數(shù),可直接copy到?cs頁面
????private?void?OutWord(GridView?dg,?string?name)
????
{
????????dg.Visible?
=?true;
????????Response.Clear();
????????Response.Buffer?
=?true;
????????Response.Charset?
=?"GB2312";
????????name?
=?"attachment;filename="?+?name;
????????Response.AppendHeader(
"Content-Disposition",?name);
????????Response.ContentEncoding?
=?System.Text.Encoding.GetEncoding("GB2312");
????????Response.ContentType?
=?"application/ms-word";
????????dg.EnableViewState?
=?false;
????????System.IO.StringWriter?oStringWriter?
=?new?System.IO.StringWriter();
????????System.Web.UI.HtmlTextWriter?oHtmlTextWriter?
=?new?System.Web.UI.HtmlTextWriter(oStringWriter);
????????dg.RenderControl(oHtmlTextWriter);
????????Response.Write(oStringWriter.ToString());
????????Response.End();
????}

????
//重載VerifyRenderingInServerForm方法,調(diào)用頁面必須加入否則會提示錯誤
???public?override?void?VerifyRenderingInServerForm(Control?control)
????
{?
????}

????
//調(diào)用方法?OutWord(Student,?"File?name.doc");
????protected?void?Button1_Click(object?sender,?EventArgs?e)
????
{???????
????????OutWord(Student,?
"File?name.doc");

????}

????
//調(diào)用方法?OutExcel(Student,?"File?name.xls");?
????protected?void?Button2_Click(object?sender,?EventArgs?e)
????
{
????????OutExcel(Student,?
"File?name.xls");????????
????}

原網(wǎng)址:http://hi.baidu.com/sharp528108/blog/item/03217012279e3c52f819b884.html
為了避免標頭出現(xiàn)亂碼
用下邊代碼對標題進行編碼
System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8)+".xls";

轉(zhuǎn)載于:https://www.cnblogs.com/sunheyubo/archive/2008/03/27/1124903.html

總結(jié)

以上是生活随笔為你收集整理的.net导出到Excel与Word中(带上下标)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。