免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
GridView中的數(shù)據(jù)導(dǎo)出到Excel方法(經(jīng)測試完整)

protected void Button2_Click(object sender, EventArgs e)
    {
        if (this.GridView1.Rows.Count == 0)
        {
            Response.Write("<script>alert('沒有查找到數(shù)據(jù),無法導(dǎo)出!')");
        }
        else
        {
            this.GridView1.AllowPaging = false; // 將有分頁的GridView中的數(shù)據(jù)全部導(dǎo)出到Excel
            gvBond();
            export("application/ms-excel", "工作人員.xls");
            // 換成 export("application/ms-word", "工作人員.doc"); 那么導(dǎo)出的就是Word格式的了.
            this.GridView1.AllowPaging = true;
            gvBond();
        }
    }
     public void export(string FileType, string FileName)
    {
        string style = @"<style>.text{mso-number-format:/@}</script>";//導(dǎo)入到excel時(shí),保存表里數(shù)字列中前面存在的 0 .
        Response.Clear();
        Response.Charset = "GB2312";
        Response.ContentEncoding = Encoding.UTF7;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        this.GridView1.AllowPaging = false;
        System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        this.GridView1.RenderControl(htw);
        Response.Write(style);
        Response.Write(sw.ToString());
        //Response.Write(dt.ToString());
        Response.End();
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        //在后臺(tái)中重載VerifyRenderingInServerForm()方法,否則報(bào)錯(cuò)為“類型"GridView"的控件"GridView1"必須放在具有 runat=server 的窗體標(biāo)記內(nèi)“
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[3].Attributes.Add("class", "text");//在數(shù)字列前存在的 0 的列中加入 class 樣式 以便保存 0
        }
    }

注:如果GricView中有分頁的話,導(dǎo)出到Excel時(shí)就會(huì)報(bào)錯(cuò).可通過修改頁文件可以修正這個(gè)問題:EnableEventValidation = "false".

<%@ Page Language="C#" EnableEventValidation="false" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
請選中你要保存的內(nèi)容,粘貼到此文本框
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
extjs 導(dǎo)出。借助gridview
GridView 導(dǎo)出為Excel或者Word
C#(asp.net)實(shí)現(xiàn)數(shù)據(jù)導(dǎo)出Excel表詳細(xì)代碼
GridView數(shù)據(jù)導(dǎo)入Excel/Excel數(shù)據(jù)讀入GridView?
asp.net導(dǎo)出excel并彈出保存提示框
c#中從網(wǎng)頁上gridview導(dǎo)出excel時(shí),如何將excel的列設(shè)置成文本類型(即保留...
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服