Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export to excel and removing hyperlinks

Status
Not open for further replies.

nc297

Programmer
Apr 7, 2010
162
US
My export to excel works fine but now I'm trying to remove the hyperlink when it exports to excel. Here's the info:

Protected Sub BtnExportExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

Response.Clear()

Response.Buffer = True

Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls")
Response.Charset = ""

Response.ContentType = "application/vnd.ms-excel"

Dim sw As New IO.StringWriter()
Dim hw As New HtmlTextWriter(sw)

GridView1.AllowPaging = False

GridView1.DataBind()

'adding a title for the Excel Spreadsheet
'adding spaces to the left and right of the title

GridView1.Caption = "DDS Listings"


'Change the Header Row back to white color
GridView1.HeaderRow.Attributes.Add("style", "font-size:10px")
GridView1.HeaderRow.BackColor = Drawing.Color.Cornsilk



For i As Integer = 0 To GridView1.Rows.Count - 1

Dim row As GridViewRow = GridView1.Rows(i)


'Change Color back to white
row.BackColor = System.Drawing.Color.White


'Apply text style to each Row
row.Attributes.Add("style", "font-size:10px")
row.Attributes.Add("style", "font-style:arial")

row.Attributes.Add("class", "textmode")


'Apply style to Individual Cells of Alternating Row

If i Mod 2 <> 0 Then

row.Cells(0).Style.Add("background-color", "cornsilk")
row.Cells(1).Style.Add("background-color", "Cornsilk")


End If

Next


GridView1.RenderControl(hw)

'style to format numbers to string

Dim style As String = "<style>.textmode{mso-number-format:\@;}</style>"

Response.Write(style)

Response.Output.Write(sw.ToString())

Response.Flush()

Response.End()

End Sub

I added this but it's not doing anything.

Private Shared Sub PrepareControlForExport(ByVal control As Control)
For i As Integer = 0 To control.Controls.Count - 1
Dim current As Control = control.Controls(i)
If TypeOf current Is HyperLink Then
control.Controls.Remove(current)
control.Controls.AddAt(i, New LiteralControl(TryCast(current, HyperLink).Text))
End If

'If current.HasControls() Then
' GridView1.PrepareControlForExport(current)
'End If
Next
End Sub

Here's the gridview:

<asp:GridView >

<Columns>
<asp:BoundField DataField="Doc" HeaderText="DDS" SortExpression="Doc" />
<asp:TemplateField HeaderText="Total Pending" SortExpression="cnt">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# "PendingDDS.aspx?doc=" & Eval("doc") %>'
Text='<%# Eval("cnt") %'></asp:HyperLink>
</ItemTemplate>

<HeaderStyle Wrap="False" />
</asp:TemplateField>
</Columns>
</asp:GridView>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top