473,394 Members | 1,748 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,394 software developers and data experts.

Create application to extract data from excel sheet

I have an excel sheet that has several lines. Each line is an order. Example:

1 Paper 10
2 Pencils 20
etc...

When the excel sheet is filled out I want the user to press a button and
then the data from orderlines is extracted and placed in a seperate file.
This seperate file and the original excel sheet should be placed in a temp
dir and then an executeble is going to be started to import both into another
application.

My question is:

Should I create a solution based on Visual Studio Tools for Office 2005 or
is creating an Add-In for excel the best way to go?
Mar 6 '06 #1
17 9853
Hi Philip,

WE can use ado.net to retrieve the data from excel as a datasource.
316934 How To Use ADO.NET to Retrieve and Modify Records in an Excel
Workbook With Visual Basic .NET
http://support.microsoft.com/default...b;EN-US;316934
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 6 '06 #2
Thank you for your quick response.

The KB article you referred to is very helpful. However this is a windows
forms application. I want the user to use the functionality from within Excel.

What is the best way to go? Add-In for excel or Visual Studio Tools for
Office 2005?

""Peter Huang" [MSFT]" wrote:
Hi Philip,

WE can use ado.net to retrieve the data from excel as a datasource.
316934 How To Use ADO.NET to Retrieve and Modify Records in an Excel
Workbook With Visual Basic .NET
http://support.microsoft.com/default...b;EN-US;316934
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 6 '06 #3
That uses the Microsoft Jet OLEDB driver. Isn't the current recommended
way to do it is with the Microsoft Excel Driver?

Mar 6 '06 #4
You need to specify the xls file in the connectionstring. But I do not know
how the xls file is saved or where. Anyway around this?

"za***@construction-imaging.com" wrote:
That uses the Microsoft Jet OLEDB driver. Isn't the current recommended
way to do it is with the Microsoft Excel Driver?

Mar 6 '06 #5
Hi Philip,

To access to the Excel data, we have two approaches.
1. Using the Microsoft Jet engine, So we can use the ADO in Legacy
application(vb6,vba) or ADO.NET in .NET application.
2. Using Excel Object Modal which is somewhat less efficient for block of
data than above.

But either methods, we need to know where the xls file is, because we need
to load the file so that we can retrieve the data.
If I have any misunderstanding, can you describe your scenario more
detailed?

Thanks!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 7 '06 #6

"Philip Wagenaar" <ph*************@online.nospam> wrote in message
news:33**********************************@microsof t.com...
I have an excel sheet that has several lines. Each line is an order.
Example:

1 Paper 10
2 Pencils 20
etc...

When the excel sheet is filled out I want the user to press a button and
then the data from orderlines is extracted and placed in a seperate file.


What sort of file?

Mar 8 '06 #7
flat text file. Tab delimited

"Homer J Simpson" wrote:

"Philip Wagenaar" <ph*************@online.nospam> wrote in message
news:33**********************************@microsof t.com...
I have an excel sheet that has several lines. Each line is an order.
Example:

1 Paper 10
2 Pencils 20
etc...

When the excel sheet is filled out I want the user to press a button and
then the data from orderlines is extracted and placed in a seperate file.


What sort of file?

Mar 9 '06 #8
Hi Philip,

Have you tried my suggestion?
If you means a plain text which is Tab delimited, you may try to import it
into excel as a xls file and then use the ADO or ADO.NET to retrieve the
data.

If you still have any concern, please feel free to post here.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 9 '06 #9

"Philip Wagenaar" <ph*************@online.nospam> wrote in message
news:01**********************************@microsof t.com...
flat text file. Tab delimited


I can't imagine doing anything but writing this in Excel VBA. Piece of cake
and exactly what it is meant for.

Just record a macro of doing this by hand then go in and tweak it to make it
more general.

Mar 9 '06 #10
I do not want to use VBA. I want to program this is vb.net. Maybe this is
very simple, but I want to start simple ;-)

"Homer J Simpson" wrote:

"Philip Wagenaar" <ph*************@online.nospam> wrote in message
news:01**********************************@microsof t.com...
flat text file. Tab delimited


I can't imagine doing anything but writing this in Excel VBA. Piece of cake
and exactly what it is meant for.

Just record a macro of doing this by hand then go in and tweak it to make it
more general.

Mar 10 '06 #11
I have the following code behind a button I placed on the excel sheet:

Private Sub btnOrder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOrder.Click

Globals.ThisWorkbook.Save()

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=" & Globals.ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=NO"""
Dim queryString As String = "select * from [OrderLines]"
Using connection As New OleDbConnection(connectionString)
Dim command As New OleDbCommand(queryString, connection)

connection.Open()

Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
MsgBox(reader(0).ToString())
End While
reader.Close()
End Using

Only when I place data in the named range the message boxes that pop up are
always empty :-(

End Sub

""Peter Huang" [MSFT]" wrote:
Hi Philip,

Have you tried my suggestion?
If you means a plain text which is Tab delimited, you may try to import it
into excel as a xls file and then use the ADO or ADO.NET to retrieve the
data.

If you still have any concern, please feel free to post here.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 10 '06 #12
Hi Philip,

Based on my test, it seems that I can not reproduce the problem.
You may have a try.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim rg As Excel.Range = NamedRange2.Cells(1, 1)
rg.Value = "1"
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Globals.ThisWorkbook.Save()

Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Globals.ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=NO"""
Dim queryString As String = "select * from [Sheet1$]"
Using connection As New OleDb.OleDbConnection(connectionString)
Dim command As New OleDb.OleDbCommand(queryString, connection)

connection.Open()

Dim reader As OleDb.OleDbDataReader = command.ExecuteReader()
While reader.Read()
MsgBox(reader(0).ToString())
End While
reader.Close()
End Using
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 13 '06 #13
How can I make this work with a named range?

""Peter Huang" [MSFT]" wrote:
Hi Philip,

Based on my test, it seems that I can not reproduce the problem.
You may have a try.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim rg As Excel.Range = NamedRange2.Cells(1, 1)
rg.Value = "1"
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Globals.ThisWorkbook.Save()

Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Globals.ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=NO"""
Dim queryString As String = "select * from [Sheet1$]"
Using connection As New OleDb.OleDbConnection(connectionString)
Dim command As New OleDb.OleDbCommand(queryString, connection)

connection.Open()

Dim reader As OleDb.OleDbDataReader = command.ExecuteReader()
While reader.Read()
MsgBox(reader(0).ToString())
End While
reader.Close()
End Using
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 14 '06 #14
aaaah!!!

I was starting my project from visual studio debug/run and I could not get
the data I entered in a cell after compile. I was able to get it after I
started the excel sheet outside visual studio

"Philip Wagenaar" wrote:
How can I make this work with a named range?

""Peter Huang" [MSFT]" wrote:
Hi Philip,

Based on my test, it seems that I can not reproduce the problem.
You may have a try.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim rg As Excel.Range = NamedRange2.Cells(1, 1)
rg.Value = "1"
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Globals.ThisWorkbook.Save()

Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Globals.ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=NO"""
Dim queryString As String = "select * from [Sheet1$]"
Using connection As New OleDb.OleDbConnection(connectionString)
Dim command As New OleDb.OleDbCommand(queryString, connection)

connection.Open()

Dim reader As OleDb.OleDbDataReader = command.ExecuteReader()
While reader.Read()
MsgBox(reader(0).ToString())
End While
reader.Close()
End Using
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 14 '06 #15
Hi Philip,

From your description, I understand that when you input a value in the
cell(e.g. cell(2,2)), after you press F5 to run the VSTO project in Debug
mode, you will find that the value in Cell(2,2) is empty.

If I have any misunderstanding, please feel free to post here.

Based on my test, I can not reproduce the problem.

So far I suggest you create a new VSTO project and input a value in
Cell(2,2) and then press F5 to run the Project to see if the value in
cell(2,2)exists.

Also due to the IDE will try to load many symbols for VSTO projects, after
you press F5, please wait until the cursor is not busy.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 15 '06 #16
Is it possible but that the location where Globals.ThisWorkbook.Save saves
its file is diffrent from Globals.ThisWorkbook.FullName in Visual Studio
debug mode?

The code I am using:

Private Sub btn_bestellen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_bestellen.Click
Try
Globals.ThisWorkbook.Save()
Catch ex As Exception
MsgBox("Some error message in dutch")
Exit Sub
End Try

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=" & Globals.ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=NO"""

Dim ExcelConnection As New
System.Data.OleDb.OleDbConnection(connectionString )
ExcelConnection.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from " &
orderRange, ExcelConnection)
Dim ds As New DataSet
da.Fill(ds, "Order")
ds.WriteXml("c:\test2.xml")
ExcelConnection.Close()

End Sub

""Peter Huang" [MSFT]" wrote:
Hi Philip,

From your description, I understand that when you input a value in the
cell(e.g. cell(2,2)), after you press F5 to run the VSTO project in Debug
mode, you will find that the value in Cell(2,2) is empty.

If I have any misunderstanding, please feel free to post here.

Based on my test, I can not reproduce the problem.

So far I suggest you create a new VSTO project and input a value in
Cell(2,2) and then press F5 to run the Project to see if the value in
cell(2,2)exists.

Also due to the IDE will try to load many symbols for VSTO projects, after
you press F5, please wait until the cursor is not busy.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 15 '06 #17
Hi Philip,

Based on my test, Globals.ThisWorkbook.Save() will save the change back
into the original path.
e.g. C:\workbook.xls

Then after changed, the Globals.ThisWorkbook.Save() will save the change to
C:\workbook.xls

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 16 '06 #18

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

Similar topics

14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
2
by: surekhads | last post by:
Hi all, I have developed a project for extracting data from a HTML file and export that data to a excel sheet. I am storing that extracted data to the db. And then I am exporting that data...
1
by: pvenu | last post by:
Hi, I know basic perl (regular expressions, pattern matching, string manipulation, reading writing into text files). Yet, my requirement is to read an input text file -> process this input file...
1
by: manishabh77 | last post by:
I will be obliged if anybody can help me with this problem: I am trying to extract data from an excel sheet that matches IDs given in column 4 of the excel sheet.I have stored those query IDs in an...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
6
by: Gilbert Tordeur | last post by:
Hello ! My web application generates an Excel sheet on the server. Then I would like to generate a pdf file from this Excel sheet. How can I do ? Thank you for your help, Gilbert
0
by: todubhai | last post by:
I am using the following code to extract the sheet names from excel: (See attached code) private String GetExcelSheetNames(string sConnectionString) { OleDbConnection objConn...
1
by: PeacefulSoul | last post by:
Hello, I have a lot of excel sheets which columns are slightly different, i want to import all of these sheets (one at a time) into ONE SQL TABLE. I'll give an example : Say ive written the...
0
by: putt73 | last post by:
In order to create styles for an excel sheet like applying border, background color, font what is the common function used? Is there any function to get the styles (format) of an existing 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.