473,654 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve excel column data using Microsoft office pias?

Is it just me or is there no easy way to open an excel file, and get
the column names that are usually in the 1st row? I would like to be
able to do this for a import tool im writing in vb.net and c#. I need
to be able to list what columns are available in the excel file, so
the user can map these to a ms sql table.

Dim oExcelApp As New Excel.Applicati on()
Dim oWorksheet As Excel.Worksheet
Dim i As Integer = 0

Try
With oExcelApp
.Visible = False
.ScreenUpdating = False
End With
oExcelApp.Workb ooks.Open(FileP ath)

For Each oWorksheet In oExcelApp.Works heets
Debug.WriteLine (oWorksheet.Nam e)
Debug.WriteLine (oWorksheet.Col umns.Count - 1)
For i = 0 To oWorksheet.Colu mns.Count
Debug.WriteLine ("Column " & i & ":" &
oWorksheet.Colu mns.Item(1, i).ToString)
Next
Next
Catch ex As Exception
MsgBox(ex.Messa ge)
Finally
oExcelApp.Workb ooks.Close() : oExcelApp.Quit( )
End Try
Nov 20 '05 #1
1 1665
Hi Murl,

Look at the following artilces for various sample codes:

311731 HOW TO: Query and Display Excel Data by Using ASP.NET, ADO.NET, and
http://support.microsoft.com/?id=311731

306022 HOW TO: Transfer Data to an Excel Workbook by Using Visual Basic .NET
http://support.microsoft.com/?id=306022

301982 HOWTO: Automate Microsoft Excel from Visual Basic .NET
http://support.microsoft.com/?id=301982

The field-names that you are looking for are part of Range object not in the
column object.
Excel wokbook has fixed columns and rows and you will need to loop through all
columns using cells(1, x) in the first row yourself until you find an empty
cell assuming that they are always in the first row.

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.

Nov 20 '05 #2

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

Similar topics

6
3796
by: Juan Sanchez | last post by:
Hi there, I have a VB.NET application using EXCEL it run fine in some computers but now in a specific one I receive the error QueryInterface for interface Excel._Application failed. interop.Excel. Some body can help me ?
6
12488
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C# application. It seems simple enough, but the problem I'm encountering is as follows: In order for the user to select the cell from Excel, they must first click once on the Excel window to give it focus and then their second click is what changes the cell...
17
6331
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
4
2456
by: Maileen | last post by:
Hi, I'm new to VB.NET and i have a little trouble with a small task regarding use of Excel files. My VB application should be able to open an Excel file, extract some data, create another Excel file, create inside this new Excel file some table and write extracted data there. Nothing special...
2
5614
by: James | last post by:
I am doing some Excel 2000 automaton using Vb 2005. I am referencing the Excel 9.0 COM Object Library. The following code was working fine: Dim xlApp as new Excel.Application Dim xlWb as Excel.Workbook Dim xlSheet as Excel.Worksheet xlWb = xlApp.Workbooks.Add
2
8908
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages BuildVersion="1,5,0815,0 " CountryName="Afghanistan" > <Language locale="English">
3
6241
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" ...
3
5387
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office"...
6
1590
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
8375
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8482
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
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
7306
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 project—planning, coding, testing, and deployment—without 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
6161
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
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.