473,395 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Excel Reports in VB.NET

Hi,

I am trying to generate Excel sheet using
Provider=Microsoft.Jet.OLEDB.4.0;

I am always getting the error while inserting data into any cell other
than A.

An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll

I am greatful to you if anyone could correct this. Also appreciate if
you can give me info about this kind of excel report generation in
VB.NET.

My OS id windows XP pro, using Excel 2000.

Here is my code:
I am using c:\temp\show.xml which is blank excel file with excel sheet
name iPOS. And also created a folder c:\temp\iPOSReports

Pls help to resolve this issue.

Imports System.Data.OleDb
Imports System.IO

Module Module1

Private excelConn As OleDbConnection
Private excelComm As OleDbCommand
Private excelConnStr As String
Private fso As File
Private desPath As String

Sub Main()
Dim sqlStr As String
Dim des As String = "show" & Now.Month & Now.Day & Now.Year &
Now.Hour & Now.Minute & Now.Second & ".xls"
desPath = "c:\temp\iPOSReports\" & des
fso.Copy("c:\temp\show.xls", desPath)
fso = Nothing
Dim cnt As Integer
For cnt = 0 To 10
sqlStr = "Insert Into [iPOS$A" & cnt & ":A" & cnt & "]
Values ('Kiran here');"
executeSql(sqlStr)
Next
Return
End Sub

Private Sub InitializeConnection()
excelConn = New OleDbConnection
excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & desPath & ";Extended
Properties=""Excel 8.0;HDR=YES"""
End Sub
Private Sub EstablishConnection()
excelConn.ConnectionString = excelConnStr
excelConn.Open()
End Sub
Private Sub executeSql(ByVal sqlStr As String)
InitializeConnection()
EstablishConnection()
excelComm = New OleDbCommand
excelComm.CommandType = CommandType.Text
excelComm.CommandText = sqlStr
excelComm.Connection = excelConn
excelComm.ExecuteNonQuery()
MsgBox(sqlStr)
closeConnection()
End Sub
Private Sub closeConnection()
excelComm.Dispose()
excelComm = Nothing
excelConn.Close()
excelConn = Nothing
End Sub

End Module

Nov 21 '05 #1
3 4998
You are trying to put data into a sheet?? The way you got it looks like more
trouble than what you need. Or is it that you get data from this sheet as
well? Here is a way to just put it into the sheet.

'Sets up the Excel Interop
Dim NewForm27 As New Excel.Application
Dim WSheet As Excel.Worksheet

'Opens the Form27 Excel document
NewForm27.Workbooks.Open("C:\Program
Files\97CS\SelfInspect\NewForm27.xls")

'Puts stuff into the form
WSheet = NewForm27.Workbooks.Item(1).Worksheets("Sheet1")
WSheet.Cells(2, 5) = txtCheckList.Text
WSheet.Cells(3, 2) = txtQuestion.Text
WSheet.Cells(5, 2) = cmbAnswer.Text
WSheet.Cells(2, 12) = txtNumber.Text
WSheet.Cells(2, 2) = txtDateInspected.Text
WSheet.Cells(6, 2) = txtComments.Text
WSheet.Cells(9, 2) = txtRootCause.Text
WSheet.Cells(11, 1) = txtRevDate1.Text

'Save and close excel sheet.
WSheet.SaveAs("C:\Program Files\97CS\SelfInspect\Form27s\" &
txtCheckList.Text & ".xls")
NewForm27.Quit()
"kr*********@gmail.com" wrote:
Hi,

I am trying to generate Excel sheet using
Provider=Microsoft.Jet.OLEDB.4.0;

I am always getting the error while inserting data into any cell other
than A.

An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll

I am greatful to you if anyone could correct this. Also appreciate if
you can give me info about this kind of excel report generation in
VB.NET.

My OS id windows XP pro, using Excel 2000.

Here is my code:
I am using c:\temp\show.xml which is blank excel file with excel sheet
name iPOS. And also created a folder c:\temp\iPOSReports

Pls help to resolve this issue.

Imports System.Data.OleDb
Imports System.IO

Module Module1

Private excelConn As OleDbConnection
Private excelComm As OleDbCommand
Private excelConnStr As String
Private fso As File
Private desPath As String

Sub Main()
Dim sqlStr As String
Dim des As String = "show" & Now.Month & Now.Day & Now.Year &
Now.Hour & Now.Minute & Now.Second & ".xls"
desPath = "c:\temp\iPOSReports\" & des
fso.Copy("c:\temp\show.xls", desPath)
fso = Nothing
Dim cnt As Integer
For cnt = 0 To 10
sqlStr = "Insert Into [iPOS$A" & cnt & ":A" & cnt & "]
Values ('Kiran here');"
executeSql(sqlStr)
Next
Return
End Sub

Private Sub InitializeConnection()
excelConn = New OleDbConnection
excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & desPath & ";Extended
Properties=""Excel 8.0;HDR=YES"""
End Sub
Private Sub EstablishConnection()
excelConn.ConnectionString = excelConnStr
excelConn.Open()
End Sub
Private Sub executeSql(ByVal sqlStr As String)
InitializeConnection()
EstablishConnection()
excelComm = New OleDbCommand
excelComm.CommandType = CommandType.Text
excelComm.CommandText = sqlStr
excelComm.Connection = excelConn
excelComm.ExecuteNonQuery()
MsgBox(sqlStr)
closeConnection()
End Sub
Private Sub closeConnection()
excelComm.Dispose()
excelComm = Nothing
excelConn.Close()
excelConn = Nothing
End Sub

End Module

Nov 21 '05 #2
But I don't want to go for Excel Interop.

Pls assist.

brix_zx2 wrote:
You are trying to put data into a sheet?? The way you got it looks like more trouble than what you need. Or is it that you get data from this sheet as well? Here is a way to just put it into the sheet.

'Sets up the Excel Interop
Dim NewForm27 As New Excel.Application
Dim WSheet As Excel.Worksheet

'Opens the Form27 Excel document
NewForm27.Workbooks.Open("C:\Program
Files\97CS\SelfInspect\NewForm27.xls")

'Puts stuff into the form
WSheet = NewForm27.Workbooks.Item(1).Worksheets("Sheet1")
WSheet.Cells(2, 5) = txtCheckList.Text
WSheet.Cells(3, 2) = txtQuestion.Text
WSheet.Cells(5, 2) = cmbAnswer.Text
WSheet.Cells(2, 12) = txtNumber.Text
WSheet.Cells(2, 2) = txtDateInspected.Text
WSheet.Cells(6, 2) = txtComments.Text
WSheet.Cells(9, 2) = txtRootCause.Text
WSheet.Cells(11, 1) = txtRevDate1.Text

'Save and close excel sheet.
WSheet.SaveAs("C:\Program Files\97CS\SelfInspect\Form27s\" &
txtCheckList.Text & ".xls")
NewForm27.Quit()
"kr*********@gmail.com" wrote:
Hi,

I am trying to generate Excel sheet using
Provider=Microsoft.Jet.OLEDB.4.0;

I am always getting the error while inserting data into any cell other than A.

An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll

I am greatful to you if anyone could correct this. Also appreciate if you can give me info about this kind of excel report generation in
VB.NET.

My OS id windows XP pro, using Excel 2000.

Here is my code:
I am using c:\temp\show.xml which is blank excel file with excel sheet name iPOS. And also created a folder c:\temp\iPOSReports

Pls help to resolve this issue.

Imports System.Data.OleDb
Imports System.IO

Module Module1

Private excelConn As OleDbConnection
Private excelComm As OleDbCommand
Private excelConnStr As String
Private fso As File
Private desPath As String

Sub Main()
Dim sqlStr As String
Dim des As String = "show" & Now.Month & Now.Day & Now.Year & Now.Hour & Now.Minute & Now.Second & ".xls"
desPath = "c:\temp\iPOSReports\" & des
fso.Copy("c:\temp\show.xls", desPath)
fso = Nothing
Dim cnt As Integer
For cnt = 0 To 10
sqlStr = "Insert Into [iPOS$A" & cnt & ":A" & cnt & "]
Values ('Kiran here');"
executeSql(sqlStr)
Next
Return
End Sub

Private Sub InitializeConnection()
excelConn = New OleDbConnection
excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & desPath & ";Extended
Properties=""Excel 8.0;HDR=YES"""
End Sub
Private Sub EstablishConnection()
excelConn.ConnectionString = excelConnStr
excelConn.Open()
End Sub
Private Sub executeSql(ByVal sqlStr As String)
InitializeConnection()
EstablishConnection()
excelComm = New OleDbCommand
excelComm.CommandType = CommandType.Text
excelComm.CommandText = sqlStr
excelComm.Connection = excelConn
excelComm.ExecuteNonQuery()
MsgBox(sqlStr)
closeConnection()
End Sub
Private Sub closeConnection()
excelComm.Dispose()
excelComm = Nothing
excelConn.Close()
excelConn = Nothing
End Sub

End Module


Nov 21 '05 #3
But I don't want to go for Excel Interop.

Pls assist.

brix_zx2 wrote:
You are trying to put data into a sheet?? The way you got it looks like more trouble than what you need. Or is it that you get data from this sheet as well? Here is a way to just put it into the sheet.

'Sets up the Excel Interop
Dim NewForm27 As New Excel.Application
Dim WSheet As Excel.Worksheet

'Opens the Form27 Excel document
NewForm27.Workbooks.Open("C:\Program
Files\97CS\SelfInspect\NewForm27.xls")

'Puts stuff into the form
WSheet = NewForm27.Workbooks.Item(1).Worksheets("Sheet1")
WSheet.Cells(2, 5) = txtCheckList.Text
WSheet.Cells(3, 2) = txtQuestion.Text
WSheet.Cells(5, 2) = cmbAnswer.Text
WSheet.Cells(2, 12) = txtNumber.Text
WSheet.Cells(2, 2) = txtDateInspected.Text
WSheet.Cells(6, 2) = txtComments.Text
WSheet.Cells(9, 2) = txtRootCause.Text
WSheet.Cells(11, 1) = txtRevDate1.Text

'Save and close excel sheet.
WSheet.SaveAs("C:\Program Files\97CS\SelfInspect\Form27s\" &
txtCheckList.Text & ".xls")
NewForm27.Quit()
"kr*********@gmail.com" wrote:
Hi,

I am trying to generate Excel sheet using
Provider=Microsoft.Jet.OLEDB.4.0;

I am always getting the error while inserting data into any cell other than A.

An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll

I am greatful to you if anyone could correct this. Also appreciate if you can give me info about this kind of excel report generation in
VB.NET.

My OS id windows XP pro, using Excel 2000.

Here is my code:
I am using c:\temp\show.xml which is blank excel file with excel sheet name iPOS. And also created a folder c:\temp\iPOSReports

Pls help to resolve this issue.

Imports System.Data.OleDb
Imports System.IO

Module Module1

Private excelConn As OleDbConnection
Private excelComm As OleDbCommand
Private excelConnStr As String
Private fso As File
Private desPath As String

Sub Main()
Dim sqlStr As String
Dim des As String = "show" & Now.Month & Now.Day & Now.Year & Now.Hour & Now.Minute & Now.Second & ".xls"
desPath = "c:\temp\iPOSReports\" & des
fso.Copy("c:\temp\show.xls", desPath)
fso = Nothing
Dim cnt As Integer
For cnt = 0 To 10
sqlStr = "Insert Into [iPOS$A" & cnt & ":A" & cnt & "]
Values ('Kiran here');"
executeSql(sqlStr)
Next
Return
End Sub

Private Sub InitializeConnection()
excelConn = New OleDbConnection
excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & desPath & ";Extended
Properties=""Excel 8.0;HDR=YES"""
End Sub
Private Sub EstablishConnection()
excelConn.ConnectionString = excelConnStr
excelConn.Open()
End Sub
Private Sub executeSql(ByVal sqlStr As String)
InitializeConnection()
EstablishConnection()
excelComm = New OleDbCommand
excelComm.CommandType = CommandType.Text
excelComm.CommandText = sqlStr
excelComm.Connection = excelConn
excelComm.ExecuteNonQuery()
MsgBox(sqlStr)
closeConnection()
End Sub
Private Sub closeConnection()
excelComm.Dispose()
excelComm = Nothing
excelConn.Close()
excelConn = Nothing
End Sub

End Module


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Al | last post by:
Here is my problem....I have a web site that genrates reports which are displayed in a page called Reports.asp and the user can open multiple reports at once all generated by Reports.asp. The results...
5
by: Matthew Shaw | last post by:
We have a web-based reporting application written in J2EE that writes out to excel using response.setContentType ("application/vnd.ms-excel; ")…. The problem is that where we have any special...
2
by: Bryan Harrington | last post by:
Hello all.. I'm working on some reports, and have added the ability to "download" the reports to excel. Not a big deal, fairly straight forward. However, PHB wants to be able to create some pivot...
1
by: Steven Stewart | last post by:
I have a user who has been using Excel for a while to keep statistics and print reports. She finds using it cumbersome because of long formulas and a lot of copying and pasting. I have designed...
1
by: srinivas | last post by:
Hi , I am a dotnet developer.I am working on crystal reports.My requirement is like this I have an excel sheet with some values.I need to read the excel values from excel sheet and need...
5
by: sulemanzia | last post by:
hi. i am working first time with query and reports. i have created a database. i have reports and query. i have a button in my form by the name of (View reports) if a user clicks on that button it...
1
by: badwal | last post by:
One of the requirements of our ASP.NET 2.0 web application (developed with visual studio 2005) is to create reports in form of excel spreadsheets with data coming from Sql Server 2005 database. ...
6
by: DeniseY | last post by:
I have an Access report that is created on the fly by the user selecting the fields to be included. The Access report comes out fine, but I want it to automatically output to an Excel spreadsheet....
10
by: dancer | last post by:
How can I save the results of a fill-in form to a Microsoft Excel spreadsheet? I can insert the results into an Access table, but the reports are so tedious to make from Access. Reports are very...
15
by: =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= | last post by:
Hi All, We are in the process of Upgrade Excel 2003 (Office 2003) to Excel 2007 (Office 2007) for one of web application. This web application is using Excel (Pivot Table) reports. With Excel...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.