Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2005, 04:24 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Import Multiple Unknown Excel Spreadsheets in .Net

I am trying to create an application that can read multiple sheets out of an Excel Workbook. Opening the connection and reading the data out of a known sheet is no problem. I am running into a wall when trying to extract the data from an unknown sheet and multiple sheets. I want to be able to read the data from all of the sheets in a workbook. Here is the code i am currently using:

MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=" & FileLoadName & "; " & _
"Extended Properties=Excel 8.0;")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter( _
"select * from [Sheet1$]", MyConnection)

DS = New System.Data.DataSet
MyCommand.Fill(DS)

'######################################
'Populate grid on GUI
'######################################
DataGrid1.DataSource = DS.Tables(0).DefaultView

This brings in all of the data on Sheet1, but doesn't display Sheet2 or Sheet3!!! Any help would be appreciated.
 
Old January 31st, 2005, 04:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You'll probably need to use the Excel API to find the sheet number, and the number of columns (fields won't be the same). If you know there is three, you can union the results, only if the fields are the same.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
import Excel File to C#.net DataGridView therese C# 11 March 5th, 2010 05:28 AM
Extracting data from excel spreadsheets Neil1234567 Access VBA 2 October 16th, 2007 07:28 AM
Import spreadsheets for Sarbanes-Oxley reporting makkerc Excel VBA 6 August 29th, 2007 08:03 AM
Import Excel to VB.Net stealthdevil Visual Basic 2005 Basics 4 June 6th, 2007 01:10 PM
How to import from excel to database(sql) in .net jvraman General .NET 1 May 18th, 2006 05:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.