Export to Excel from Dataset

Author Topic
Suneela Nekkanti
Member

Joined: 22 Feb 2005
Country: India
Posts: 1

Posted: 02 Mar 2005 10:20:12

I want to Export Data to Excel from Dataset.
I am adding reference to Microsoft Excel object library 5.o, then i am getting only Excel dll to import. and when i am running Application i am getting "can't create ActiveX component" Message.

I have Microsoft Office Professional Edition 2003.

I write code link this way:

Imports Excel

Dim oXL As Excel.Application
Dim oBooks As Excel.Workbooks
Dim oBook As Excel.Workbook
Dim oSheets As Excel.Worksheets
Dim oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim iRow As Integer
Dim iCol As Integer

oXL = CreateObject("Excel.Application"
oBooks = oXL.Workbooks
oBook = oBooks.Item(1)
oSheets = oBook.Worksheets
oSheet = CType(oSheets.Item(1), Excel.Worksheet)
oCells = oSheet.Cells
oSheet = oXL.ActiveSheet()

With oSheet
For iCol = 0 To lobjDs.Tables(0).Columns.Count - 1
.Cells(1, iCol + 1) = lobjDs.Tables(0).Columns(iCol).ColumnName.ToString()
Next
For iRow = 0 To lobjDs.Tables(0).Rows.Count - 1
For iCol = 0 To lobjDs.Tables(0).Columns.Count - 1
.Cells(iRow + 2, iCol + 1) = lobjDs.Tables(0).Rows(iRow).Item(iCol) ---
-----in this line i am getting error description like this way "Expression is a value and therefore cannot be the target of an assignment."

Next iCol
Next iRow
End With
oXL.Workbooks.Close()
oXL.Quit()
oXL = Nothing

Please any one can help out for me.
I think in adding reference i am mistaken.
bare my poor english.
Thanks in advance.

I want to Export Data to Excel from Dataset.
I am adding reference to Microsoft Excel object library 5.o, then i am getting only Excel dll to import. and when i am running Application i am getting "can't create ActiveX component" Message.

I have Microsoft Office Professional Edition 2003.

I write code link this way:

Imports Excel

Dim oXL As Excel.Application
Dim oBooks As Excel.Workbooks
Dim oBook As Excel.Workbook
Dim oSheets As Excel.Worksheets
Dim oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim iRow As Integer
Dim iCol As Integer

oXL = CreateObject("Excel.Application"
oBooks = oXL.Workbooks
oBook = oBooks.Item(1)
oSheets = oBook.Worksheets
oSheet = CType(oSheets.Item(1), Excel.Worksheet)
oCells = oSheet.Cells
oSheet = oXL.ActiveSheet()

With oSheet
For iCol = 0 To lobjDs.Tables(0).Columns.Count - 1
.Cells(1, iCol + 1) = lobjDs.Tables(0).Columns(iCol).ColumnName.ToString()
Next
For iRow = 0 To lobjDs.Tables(0).Rows.Count - 1
For iCol = 0 To lobjDs.Tables(0).Columns.Count - 1
.Cells(iRow + 2, iCol + 1) = lobjDs.Tables(0).Rows(iRow).Item(iCol) ---
-----in this line i am getting error description like this way "Expression is a value and therefore cannot be the target of an assignment."

Next iCol
Next iRow
End With
oXL.Workbooks.Close()
oXL.Quit()
oXL = Nothing

Please any one can help out for me.
I think in adding reference i am mistaken.
bare my poor english.
Thanks in advance.
sheril sher
Member

Joined: 19 Apr 2008
Country:
Posts: 1

Posted: 19 Apr 2008 10:20:57

create an excel file through program and loop through dataset , then you can write in cell of excel
you can write in excel cells like this

xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1"
xlWorkSheet.Cells(1, 1) = "vb.net-informations.com"
xlWorkSheet.SaveAs("C:\vbexcel.xlsx"

look th following page for details

vb.net-informations.com/excel-2007/vb.net_excel_2007_tutorials.htm

shery

create an excel file through program and loop through dataset , then you can write in cell of excel
you can write in excel cells like this

xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1"
xlWorkSheet.Cells(1, 1) = "vb.net-informations.com"
xlWorkSheet.SaveAs("C:\vbexcel.xlsx"

look th following page for details

vb.net-informations.com/excel-2007/vb.net_excel_2007_tutorials.htm

shery
Filip Krnjić
Member

Joined: 13 Aug 2009
Homepage: link
Country: HR
Posts: 1

Posted: 19 Feb 2010 17:23:01

Hi,

here is how you can easily export DataSet to Excel with GemBox.Spreadsheet .NET Excel component.

For exporting DataTable you just need to call one method! Very easy to use!

Hi,

here is how you can easily export DataSet to Excel with GemBox.Spreadsheet .NET Excel component.

For exporting DataTable you just need to call one method! Very easy to use!

Follow us on twitter Subscribe to our RSS feed
Activate your free membership today | Login | Currency