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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to remove the html code from exported data

Status
Not open for further replies.

russellmunday

Technical User
Jul 24, 2003
87
GB
I Have to export the contents of a datagrid to an excel template(see code below) the problem is when i open the worksheet i can see all the html code is there an easy way filter this out.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' the do button
'bind the datagrid
SqlDataAdapter1.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()

'launch the excel application and load te template file
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
xlapp = CreateObject("excel.application")
xlbook = xlapp.Workbooks.open("c:\ord.xlt")
'set as the active sheet
xlsheet = xlbook.ActiveSheet
xlsheet = xlapp.ActiveSheet

Dim sw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(sw)

DataGrid1.RenderControl(hw)

xlsheet.Range("A7:D7").Value = sw.ToString

xlbook.SaveAs("c:\ruswon.xls")
xlbook.Saved = True
xlapp.Quit()

xlapp = Nothing
xlbook = Nothing
xlsheet = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top