Computing.Net > Forums > Programming > export to excel VB.NET 2

export to excel VB.NET 2

Reply to Message Icon

Original Message
Name: bexm
Date: March 31, 2006 at 07:03:13 Pacific
Subject: export to excel VB.NET 2
OS: xp
CPU/Ram: 512
Comment:

Hello

I am trying to export a datagrid to an excel file using VB.NET.
I can do it in ASP.net like this:
Dim oDS As DataSet = reports.GetDataset(StoredProcedure, oparams)
Dim DG As New DataGrid
DG.DataSource = oDS
DG.DataBind()
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
DG.RenderControl(htmlWrite)
reports.WriteFile(stringWrite.ToString, FileName)

(where reports contains all my functions)

but this method doesnt work in VB.NET as these two lines cannot be used in VB.NET:
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
DG.RenderControl(htmlWrite)

Does any one know of an alternative cos I'm stuck!


Thanx

Bex


Report Offensive Message For Removal

Response Number 1
Name: bexm
Date: April 3, 2006 at 07:03:37 Pacific
Subject: export to excel VB.NET 2
Reply: (edit)

Ok.. worked it out... did not realise I could reference the system.web namespace in a vb.net app... I can use the code listed above! duh!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: export to excel VB.NET 2

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software