russellmunday
Technical User
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
7").Value = sw.ToString
xlbook.SaveAs("c:\ruswon.xls")
xlbook.Saved = True
xlapp.Quit()
xlapp = Nothing
xlbook = Nothing
xlsheet = Nothing
End Sub
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
xlbook.SaveAs("c:\ruswon.xls")
xlbook.Saved = True
xlapp.Quit()
xlapp = Nothing
xlbook = Nothing
xlsheet = Nothing
End Sub