茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    asp.net(c#)將數(shù)據(jù)導(dǎo)出到word或excel
    來源:易賢網(wǎng) 閱讀:886 次 日期:2014-10-24 14:56:57
    溫馨提示:易賢網(wǎng)小編為您整理了“asp.net(c#)將數(shù)據(jù)導(dǎo)出到word或excel”,方便廣大網(wǎng)友查閱!

    最簡單的方法是把頁面上所有的東西都導(dǎo)出

    在載入時調(diào)用,注意頁面里不能有其它控件,包括按鈕

    void converttoexcel()

    {

    response.clear();

    response.buffer = true;

    response.charset = gb2312;

    response.appendheader(content-disposition, attachment;filename= + datetime.now.tostring(yyyymmddhhmmss) + .xls);

    response.contentencoding = system.text.encoding.getencoding(gb2312);

    response.contenttype = application/ms-excel;

    this.page.enableviewstate = false;

    system.io.stringwriter ostringwriter = new system.io.stringwriter();

    system.web.ui.htmltextwriter ohtmltextwriter = new system.web.ui.htmltextwriter(ostringwriter);

    this.page.rendercontrol(ohtmltextwriter);

    response.write(ostringwriter.tostring());

    response.end();

    }

    asp.net(c#)將數(shù)據(jù)導(dǎo)出到word或excel

    命名空間:

    using system.io;

    using system.text;

    將datagrid的數(shù)據(jù)導(dǎo)出到excel

    string excelname=excel文件名;

    httpcontext.current.response.charset = gb2312;

    httpcontext.current.response.contentencoding = encoding.utf8;

    httpcontext.current.response.contenttype = application/ms-excel;

    httpcontext.current.response.appendheader(content-disposition, attachment;filename= + excelname + .xls);

    dr1.page.enableviewstate = false;

    stringwriter sw = new stringwriter();

    htmltextwriter tw = new htmltextwriter(sw);

    dr1.rendercontrol(tw);

    httpcontext.current.response.write(sw.tostring());

    httpcontext.current.response.end();

    將datagrid的數(shù)據(jù)導(dǎo)出到word

    string excelname=word文件名;

    httpcontext.current.response.charset = gb2312;

    httpcontext.current.response.contentencoding = encoding.utf8;

    httpcontext.current.response.contenttype = application/ms-winword;

    httpcontext.current.response.appendheader(content-disposition, attachment;filename= + excelname + .doc);

    dr1.page.enableviewstate = false;

    stringwriter sw = new stringwriter();

    htmltextwriter tw = new htmltextwriter(sw);

    dr1.rendercontrol(tw);

    httpcontext.current.response.write(sw.tostring());

    httpcontext.current.response.end();

    asp.net 2.0,c#----利用gridview控件導(dǎo)出其他文件(導(dǎo)出excel,導(dǎo)出word文件)

    // 注意,在visual studio2005平臺下,如果使用gridview導(dǎo)出文件,

    //就必須重載verifyrenderinginserverform方法

    public override void verifyrenderinginserverform(control control)

    {

    }

    ///

    /// 導(dǎo)出到文件的方法,

    ///

    /// model=1:導(dǎo)出為execl,model=2:導(dǎo)出為word

    private void tofiles(int model)

    {

    string strfilename = datetime.now.tostring(yyyymmdd-hhmmss);

    system.web.httpcontext hc = system.web.httpcontext.current;

    hc.response.clear();

    hc.response.buffer = true;

    hc.response.contentencoding = system.text.encoding.utf8;//設(shè)置輸出流為簡體中文

    if (model == 1)

    {

    //---導(dǎo)出為excel文件

    hc.response.addheader(content-disposition, attachment;filename= +httputility.urlencode(strfilename, system.text.encoding.utf8) + .xls);

    hc.response.contenttype = application/ms-excel;//設(shè)置輸出文件類型為excel文件。

    }

    else

    {

    //--- 導(dǎo)出為word文件

    hc.response.addheader(content-disposition, attachment;filename= +httputility.urlencode(strfilename, system.text.encoding.utf8) + .doc);

    hc.response.contenttype = application/ms-word;//設(shè)置輸出文件類型為word文件。

    }

    system.io.stringwriter sw = new system.io.stringwriter();

    system.web.ui.htmltextwriter htw = new system.web.ui.htmltextwriter(sw);

    this.gridview1.rendercontrol(htw);

    hc.response.write(sw.tostring());

    hc.response.end();

    }

    //-導(dǎo)出為excel文件

    protected void toexecl_click(object sender, eventargs e)

    {

    tofiles(1);

    }

    //-導(dǎo)出為word文件

    protected void button1_click(object sender, eventargs e)

    {

    tofiles(2);

    }

    from:http://hi.baidu.com/jg_%b3%c2/blog/item/4f0edf188851c50135fa41ce.html

    c#操作word[轉(zhuǎn)]

    導(dǎo)入com庫:microsoft word 11.0 object library.

    更多信息請查看IT技術(shù)專欄

    更多信息請查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:asp.net(c#)將數(shù)據(jù)導(dǎo)出到word或excel
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報班

    • 報班類型
    • 姓名
    • 手機(jī)號
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)