Exforsys

Free Training

communicating with excel

This is a discussion on communicating with excel within the Visual Basic Tutorials forums, part of the Articles and Tutorials category; I want to know basically how to talk with excel thro' VB.net...

Go Back   Exforsys > Articles and Tutorials > Visual Basic Tutorials

Exforsys.com


Visual Basic Tutorials Visual Basic Tutorials Discussions.

Reply

 

LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 12-30-2006, 01:36 PM
Junior Member
 
Join Date: Dec 2006
Posts: 1
ramskkk is on a distinguished road
communicating with excel

I want to know basically
how to talk with excel thro' VB.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-08-2007, 05:31 AM
Junior Member
 
Join Date: Jan 2007
Posts: 1
kamal patel is on a distinguished road
you can communicate with excel through VB editor.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-08-2007, 03:13 AM
Junior Member
 
Join Date: May 2007
Posts: 1
Vijay.Tomar is on a distinguished road
Connection to Excel using Jet Engine

To connect to Excel, one can use OleDb objects that will treat Excel as a database, and then the required information can be easily fetched by using SQL queries. The important steps that have to be considered while connecting to Excel are as follows:

* Connection String:

The connection string should be set to the OleDbConnection object. This is very critical as Jet Engine might not give a proper error message if the appropriate details are not given.

Syntax: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<Full Path of Excel File>; Extended Properties="Excel 8.0; HDR=No; IMEX=1".
* Definition of Extended Properties:
o Excel = <No>

One should specify the version of Excel Sheet here. For Excel 2000 and above, it is set it to Excel 8.0 and for all others, it is Excel 5.0.
o HDR= <Yes/No>

This property will be used to specify the definition of header for each column. If the value is ‘Yes’, the first row will be treated as heading. Otherwise, the heading will be generated by the system like F1, F2 and so on.
o IMEX= <0/1/2>

IMEX refers to IMport EXport mode. This can take three possible values.
+ IMEX=0 and IMEX=2 will result in ImportMixedTypes being ignored and the default value of ‘Majority Types’ is used. In this case, it will take the first 8 rows and then the data type for each column will be decided.
+ IMEX=1 is the only way to set the value of ImportMixedTypes as Text. Here, everything will be treated as text.

For more info regarding Extended Properties, check this out.
Loading of data in to Dataset

After successfully connecting to Excel using Jet Engine, it is easy to the load the data in to DataSet. One has to write a query similar to ANSI-92 with the only changes being that each Excel sheet will be treated as a table and the table name will be the sheet name with “$”. The range can also be specified after the “$” sign.
Collapse



Public Function ImportAttendence(ByVal PrmPathExcelFile As String, ByVal DataGrid1 As DataGrid)

Dim MyConnection As System.Data.OleDb.OleDbConnection

Try

''''''' Fetch Data from Excel

Dim DtSet As System.Data.DataSet

Dim MyCommand As System.Data.OleDb.OleDbDataAdapter



MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & _

"data source='" & PrmPathExcelFile & " '; " & "Extended Properties=Excel 8.0;")

' Select the data from Sheet1 of the workbook.

MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", MyConnection)



MyCommand.TableMappings.Add("Table", "Attendence")

DtSet = New System.Data.DataSet

MyCommand.Fill(DtSet)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

DataGrid1.DataSource = DtSet.Tables(0)

MyConnection.Close()

Catch ex As Exception

MyConnection.Close()

End Try

End Function


'**************
May be this code will help u.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Import EXCEL Data into QTP Global Data Table venkata krishnamurthy t Software Testing 7 12-09-2007 11:59 PM
How to convert the excel file to text file or rev file with user specified delimiters kvp_vivek Visual Basic Tutorials 2 12-04-2006 09:34 PM
DTS export to Excel Paulw88 SQL Server 1 04-20-2006 07:33 PM
Saving a data in excel sheet....Using QTP oracleraju Testing Tutorials 3 09-02-2005 06:20 AM
Oracle : Create an Excel Report from Several Oracle Databases Using Apache Jakarta POI techguru Oracle Tutorials 0 08-27-2005 09:30 PM


All times are GMT -4. The time now is 06:04 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.