473,657 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel Reports in VB.NET

Hi,

I am trying to generate Excel sheet using
Provider=Micros oft.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.Ol eDb.OleDbExcept ion'
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.xm l which is blank excel file with excel sheet
name iPOS. And also created a folder c:\temp\iPOSRep orts

Pls help to resolve this issue.

Imports System.Data.Ole Db
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\iPOSRe ports\" & des
fso.Copy("c:\te mp\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(sqlS tr)
Next
Return
End Sub

Private Sub InitializeConne ction()
excelConn = New OleDbConnection
excelConnStr = "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=" & desPath & ";Extended
Properties=""Ex cel 8.0;HDR=YES"""
End Sub
Private Sub EstablishConnec tion()
excelConn.Conne ctionString = excelConnStr
excelConn.Open( )
End Sub
Private Sub executeSql(ByVa l sqlStr As String)
InitializeConne ction()
EstablishConnec tion()
excelComm = New OleDbCommand
excelComm.Comma ndType = CommandType.Tex t
excelComm.Comma ndText = sqlStr
excelComm.Conne ction = excelConn
excelComm.Execu teNonQuery()
MsgBox(sqlStr)
closeConnection ()
End Sub
Private Sub closeConnection ()
excelComm.Dispo se()
excelComm = Nothing
excelConn.Close ()
excelConn = Nothing
End Sub

End Module

Nov 21 '05 #1
3 5021
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.Applicati on
Dim WSheet As Excel.Worksheet

'Opens the Form27 Excel document
NewForm27.Workb ooks.Open("C:\P rogram
Files\97CS\Self Inspect\NewForm 27.xls")

'Puts stuff into the form
WSheet = NewForm27.Workb ooks.Item(1).Wo rksheets("Sheet 1")
WSheet.Cells(2, 5) = txtCheckList.Te xt
WSheet.Cells(3, 2) = txtQuestion.Tex t
WSheet.Cells(5, 2) = cmbAnswer.Text
WSheet.Cells(2, 12) = txtNumber.Text
WSheet.Cells(2, 2) = txtDateInspecte d.Text
WSheet.Cells(6, 2) = txtComments.Tex t
WSheet.Cells(9, 2) = txtRootCause.Te xt
WSheet.Cells(11 , 1) = txtRevDate1.Tex t

'Save and close excel sheet.
WSheet.SaveAs(" C:\Program Files\97CS\Self Inspect\Form27s \" &
txtCheckList.Te xt & ".xls")
NewForm27.Quit( )
"kr*********@gm ail.com" wrote:
Hi,

I am trying to generate Excel sheet using
Provider=Micros oft.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.Ol eDb.OleDbExcept ion'
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.xm l which is blank excel file with excel sheet
name iPOS. And also created a folder c:\temp\iPOSRep orts

Pls help to resolve this issue.

Imports System.Data.Ole Db
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\iPOSRe ports\" & des
fso.Copy("c:\te mp\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(sqlS tr)
Next
Return
End Sub

Private Sub InitializeConne ction()
excelConn = New OleDbConnection
excelConnStr = "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=" & desPath & ";Extended
Properties=""Ex cel 8.0;HDR=YES"""
End Sub
Private Sub EstablishConnec tion()
excelConn.Conne ctionString = excelConnStr
excelConn.Open( )
End Sub
Private Sub executeSql(ByVa l sqlStr As String)
InitializeConne ction()
EstablishConnec tion()
excelComm = New OleDbCommand
excelComm.Comma ndType = CommandType.Tex t
excelComm.Comma ndText = sqlStr
excelComm.Conne ction = excelConn
excelComm.Execu teNonQuery()
MsgBox(sqlStr)
closeConnection ()
End Sub
Private Sub closeConnection ()
excelComm.Dispo se()
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.Applicati on
Dim WSheet As Excel.Worksheet

'Opens the Form27 Excel document
NewForm27.Workb ooks.Open("C:\P rogram
Files\97CS\Self Inspect\NewForm 27.xls")

'Puts stuff into the form
WSheet = NewForm27.Workb ooks.Item(1).Wo rksheets("Sheet 1")
WSheet.Cells(2, 5) = txtCheckList.Te xt
WSheet.Cells(3, 2) = txtQuestion.Tex t
WSheet.Cells(5, 2) = cmbAnswer.Text
WSheet.Cells(2, 12) = txtNumber.Text
WSheet.Cells(2, 2) = txtDateInspecte d.Text
WSheet.Cells(6, 2) = txtComments.Tex t
WSheet.Cells(9, 2) = txtRootCause.Te xt
WSheet.Cells(11 , 1) = txtRevDate1.Tex t

'Save and close excel sheet.
WSheet.SaveAs(" C:\Program Files\97CS\Self Inspect\Form27s \" &
txtCheckList.Te xt & ".xls")
NewForm27.Quit( )
"kr*********@gm ail.com" wrote:
Hi,

I am trying to generate Excel sheet using
Provider=Micros oft.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.Ol eDb.OleDbExcept ion'
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.xm l which is blank excel file with excel sheet name iPOS. And also created a folder c:\temp\iPOSRep orts

Pls help to resolve this issue.

Imports System.Data.Ole Db
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\iPOSRe ports\" & des
fso.Copy("c:\te mp\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(sqlS tr)
Next
Return
End Sub

Private Sub InitializeConne ction()
excelConn = New OleDbConnection
excelConnStr = "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=" & desPath & ";Extended
Properties=""Ex cel 8.0;HDR=YES"""
End Sub
Private Sub EstablishConnec tion()
excelConn.Conne ctionString = excelConnStr
excelConn.Open( )
End Sub
Private Sub executeSql(ByVa l sqlStr As String)
InitializeConne ction()
EstablishConnec tion()
excelComm = New OleDbCommand
excelComm.Comma ndType = CommandType.Tex t
excelComm.Comma ndText = sqlStr
excelComm.Conne ction = excelConn
excelComm.Execu teNonQuery()
MsgBox(sqlStr)
closeConnection ()
End Sub
Private Sub closeConnection ()
excelComm.Dispo se()
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.Applicati on
Dim WSheet As Excel.Worksheet

'Opens the Form27 Excel document
NewForm27.Workb ooks.Open("C:\P rogram
Files\97CS\Self Inspect\NewForm 27.xls")

'Puts stuff into the form
WSheet = NewForm27.Workb ooks.Item(1).Wo rksheets("Sheet 1")
WSheet.Cells(2, 5) = txtCheckList.Te xt
WSheet.Cells(3, 2) = txtQuestion.Tex t
WSheet.Cells(5, 2) = cmbAnswer.Text
WSheet.Cells(2, 12) = txtNumber.Text
WSheet.Cells(2, 2) = txtDateInspecte d.Text
WSheet.Cells(6, 2) = txtComments.Tex t
WSheet.Cells(9, 2) = txtRootCause.Te xt
WSheet.Cells(11 , 1) = txtRevDate1.Tex t

'Save and close excel sheet.
WSheet.SaveAs(" C:\Program Files\97CS\Self Inspect\Form27s \" &
txtCheckList.Te xt & ".xls")
NewForm27.Quit( )
"kr*********@gm ail.com" wrote:
Hi,

I am trying to generate Excel sheet using
Provider=Micros oft.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.Ol eDb.OleDbExcept ion'
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.xm l which is blank excel file with excel sheet name iPOS. And also created a folder c:\temp\iPOSRep orts

Pls help to resolve this issue.

Imports System.Data.Ole Db
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\iPOSRe ports\" & des
fso.Copy("c:\te mp\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(sqlS tr)
Next
Return
End Sub

Private Sub InitializeConne ction()
excelConn = New OleDbConnection
excelConnStr = "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=" & desPath & ";Extended
Properties=""Ex cel 8.0;HDR=YES"""
End Sub
Private Sub EstablishConnec tion()
excelConn.Conne ctionString = excelConnStr
excelConn.Open( )
End Sub
Private Sub executeSql(ByVa l sqlStr As String)
InitializeConne ction()
EstablishConnec tion()
excelComm = New OleDbCommand
excelComm.Comma ndType = CommandType.Tex t
excelComm.Comma ndText = sqlStr
excelComm.Conne ction = excelConn
excelComm.Execu teNonQuery()
MsgBox(sqlStr)
closeConnection ()
End Sub
Private Sub closeConnection ()
excelComm.Dispo se()
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
1419
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 of the report can be outputed to Excel within Internet Explorer using the HTTP Content Type application/vnd.ms-excel. When I generate multiple reports I get an error saying I cannot open two documents with the same name I am running IE6 SP1 with...
5
10435
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 characters in our report result set E.g umlauts and accents ( ASCII values 128 to 165 ) this data is corrupted, and does not appear correctly. The standard font family used throughout our Web Reports
2
1805
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 tables from said reports (again.. no biggie) and when he goes to save the file, Excel wants to save the file as a web page instead of and Excel spreadsheet. Now.. I know the simple thing here is to just pick Excel from the drop down box in the...
1
17403
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 a database for her which is intended to make things a lot easier; however, I don't have a lot of experience with Access and I find that designing the reports in Access is tedious. I want to be able to print the reports (which are simply based on...
1
2554
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 to show the values in crystal reports using c#.what i can do for populating the excel values into crystal reports.
5
1989
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 opens another form with 3 options 1) Problems all report 2) problems resolved 3) Problems not resolved Now what i really want is when a user clicks on Problems all report it should go directly into excel worksheet based on my query which i have...
1
1377
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. Some points are as follows: 1) User should be able to filter data included in reports like choose among cycles, cars etc or all of them (I.e. Sql query is generated dynamically based on user choice) 2) Data is retrieved from database and...
6
5220
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. Again, I have this part working. But the fields in the resulting spreadsheet are in a different order than the Access report. (Example: The fields in the Access report might go FirstName, LastName,Address,City--in the Excel spreadsheet, they come up...
10
1671
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 easy to make using Excel as the data source. Since there will not be multiple tables or queries, I don't really need Access.
15
5342
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 2003 application (Reports) works ok. But when Office 2003 is upgraded to Office 2007 Excel reports stops working. It Log the error “Exception from HRESULT: 0x800A03EC.” In database.
0
8402
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8315
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.