excel-.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I want to develop a little application, which extracts some values of an
excel sheet and displays this values with a rectangle or a circle in a form.
Are there any example how to implement such things?

regards

mathon
 
Is it not possible to extract values from an excel sheet to display for
example in a DataGrid?? :(

regards

mathon
 
You could add a reference to Excel to your .Net project. Then either open
the file with an Excel in your code or get a reference to the workbook if it
is already open. Then you could use the nessesary objects to get your
values out of the spreadsheet and into your form.

Robby
 
You could check out the samples that come with the VB for Applications in
Excel. They should have something in there that shows you how to do it for
VBA. It should not be too hard to move that code to .Net.

Robby
 
¤ Hello,
¤
¤ I want to develop a little application, which extracts some values of an
¤ excel sheet and displays this values with a rectangle or a circle in a form.
¤ Are there any example how to implement such things?
¤

The following should get you started with Excel automation. I'm not really sure how you are trying
to present this data on your Windows Form.

How to automate Microsoft Excel from Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;301982


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Excel is an ISAM just like dBase. You can get at the data
using Excel automation or, if you don't have the full Excel installed but
have the Jet ISAM drivers on your user machine then you can open the sheets
just like opening a Jet file by using the OLEDB provider. There are some
limitations but getting the data for grid display (or INSERTs or UPDATES) is
pretty straight forward using Jet-SQL syntax and the special bracket syntax
as shown below for the Excel objects

The following shows very general proof of concept code, this opens the
connection and confirms that it is reading the data. Just use regular
ado.net to iterate and use the values to draw your shapes.

This example loads the values into a grid

The HDR=Yes in the connection string tells the provider that the first row
of the sheet has values that are used as "Column Names", if your sheet
doesn't have that then don't say Yes :)

Imports System.Data.Oledb
......

Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\mytests\book1.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes""")

Dim ds As New DataSet
Dim da As New OleDbDataAdapter("Select * from [Sheet1$]", cn)
cn.Open()
Try
da.Fill(ds)
MsgBox(ds.Tables.Count)
MsgBox(ds.Tables(0).Rows.Count)

grid1.DataSource = ds.Tables(0)

Catch ex As Exception
MsgBox(ex.ToString)
End Try

Hope that helps.

Robert Smith
Kirkland, WA
www.smithvoice.com
 
Back
Top