473,507 Members | 2,504 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.Application()
Dim oWorksheet As Excel.Worksheet
Dim i As Integer = 0

Try
With oExcelApp
.Visible = False
.ScreenUpdating = False
End With
oExcelApp.Workbooks.Open(FilePath)

For Each oWorksheet In oExcelApp.Worksheets
Debug.WriteLine(oWorksheet.Name)
Debug.WriteLine(oWorksheet.Columns.Count - 1)
For i = 0 To oWorksheet.Columns.Count
Debug.WriteLine("Column " & i & ":" &
oWorksheet.Columns.Item(1, i).ToString)
Next
Next
Catch ex As Exception
MsgBox(ex.Message)
Finally
oExcelApp.Workbooks.Close() : oExcelApp.Quit()
End Try
Nov 20 '05 #1
1 1658
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
3791
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....
6
12468
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#...
17
6302
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
2443
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...
2
5608
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...
2
8901
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...
3
6221
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...
3
5365
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...
6
1584
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
7223
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,...
0
7314
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
7372
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...
1
7030
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...
0
7482
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...
0
5623
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,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.