当前位置:编程学习 > C#/ASP.NET >>

这个导出到excel函数,怎么不把超链接导出来?

static public void ExportExcelFromDataGrid(Page page, string filename, System.Web.UI.WebControls.DataGrid ToExcelGrid)
        {
            HttpResponse Response = page.Response;

            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "utf-8";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + page.Server.UrlEncode(filename) + ".xls");
            Response.ContentEncoding = System.Text.Encoding.UTF7;//.GetEncoding("utf-8");   
            Response.ContentType = "application/ms-excel";

            page.EnableViewState = false;

            System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
            StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
            HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

            ToExcelGrid.RenderControl(oHtmlTextWriter);
            Response.Write(oStringWriter.ToString());
            Response.End();
        } --------------------编程问答-------------------- 帮吧了忙。但是可以帮你顶! --------------------编程问答-------------------- 因为指定了ContentType。不过你说的“把超链接导出来”是什么意思? --------------------编程问答-------------------- 导出到Excel后,Excel里面还是有DataGrid的超链接 --------------------编程问答-------------------- 导出来是页面上一样的格式,有链接是正常的,但你的题目好像是说链接没导出来 --------------------编程问答-------------------- mark --------------------编程问答-------------------- 顶下 --------------------编程问答-------------------- Private Sub DisableControls(ByVal gv As Control)
        Dim lb As LinkButton = New LinkButton()
        Dim l As Literal = New Literal()
        Dim name As String = String.Empty

        Dim i As Integer
        For i = 0 To gv.Controls.Count - 1

            If (TypeOf gv.Controls(i) Is LinkButton) Then
                l.Text = CType(gv.Controls(i), LinkButton).Text
                gv.Controls.Remove(gv.Controls(i))
                gv.Controls.AddAt(i, l)
            ElseIf (TypeOf gv.Controls(i) Is DropDownList) Then
                l.Text = CType(gv.Controls(i), DropDownList).SelectedItem.Text
                gv.Controls.Remove(gv.Controls(i))
                gv.Controls.AddAt(i, l)
            ElseIf (TypeOf gv.Controls(i) Is HyperLink) Then
                l.Text = CType(gv.Controls(i), HyperLink).Text
                gv.Controls.Remove(gv.Controls(i))
                gv.Controls.AddAt(i, l)
            End If


            If (gv.Controls(i).HasControls()) Then
                DisableControls(gv.Controls(i))
            End If

        Next
    End Sub





    Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Me.DisableControls(OTDetail)
        Response.ClearContent()
        Response.AddHeader("content-disposition", "attachment; filename=OTFormNotApprove.xls")
        Response.ContentType = "application/excel"
        Dim sw As StringWriter = New StringWriter()
        Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
        OTDetail.RenderControl(htw)
        Response.Write(sw.ToString())
        Response.End()

    End Sub --------------------编程问答-------------------- 导出之前先把DataGrid DisableControls一下就好了
--------------------编程问答-------------------- up --------------------编程问答-------------------- 遇到同样的问题!!
不知道楼用JavaScript如何实现???
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,