473,769 Members | 8,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading in an Excel file.

I need to import an Excel file. For reasons I won't get into, I cannot
just link to the file or do an import specification, so I need to do it
via code.

I know of two ways of doing this - via a recordset and using the Excel
file as a datasource and also as setting up an Excel object and
stepping through that object's collections. (cells, rows, etc)

Can anyone tell me which one is better and why? They both seem to
work. Or perhaps, there is even a better way?

Long and short, we are getting a data file - in Excel - from a vendor -
and need to import it into our system. Stepping through the rows is
ideal to allow us to add business rules to the data.

Thanks
Brian

Nov 2 '06 #1
4 3128
"BerkshireG uy" <bd*****@yahoo. comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
>I need to import an Excel file. For reasons I won't get into, I cannot
just link to the file or do an import specification, so I need to do it
via code.

I know of two ways of doing this - via a recordset and using the Excel
file as a datasource
This would require you to link to it using the linked table method so ...
and also as setting up an Excel object and
stepping through that object's collections. (cells, rows, etc)
.... this is your only option isn't it?
>
Can anyone tell me which one is better and why? They both seem to
work. Or perhaps, there is even a better way?
I've used both and there's not much to choose between them, performance
wise, as far as I can tell at any rate. I only moved to manipulating Excel
using code because I had to *write* data to Excel, and with SP2 on Office
this is no longer supported via the linked table method.

HTH - Keith.
www.keithwilby.com
Nov 2 '06 #2
Keitth - Actually I can access the Excel workbook as a recordset
without a linked table. I do so by creating and ADODB connection and
use Excel as the DSN.

I can provide air code if you'd like.

-Brian

Keith Wilby wrote:
"BerkshireG uy" <bd*****@yahoo. comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
I need to import an Excel file. For reasons I won't get into, I cannot
just link to the file or do an import specification, so I need to do it
via code.

I know of two ways of doing this - via a recordset and using the Excel
file as a datasource

This would require you to link to it using the linked table method so ...
and also as setting up an Excel object and
stepping through that object's collections. (cells, rows, etc)

... this is your only option isn't it?

Can anyone tell me which one is better and why? They both seem to
work. Or perhaps, there is even a better way?

I've used both and there's not much to choose between them, performance
wise, as far as I can tell at any rate. I only moved to manipulating Excel
using code because I had to *write* data to Excel, and with SP2 on Office
this is no longer supported via the linked table method.

HTH - Keith.
www.keithwilby.com
Nov 2 '06 #3
"BerkshireG uy" <bd*****@yahoo. comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Keitth - Actually I can access the Excel workbook as a recordset
without a linked table. I do so by creating and ADODB connection and
use Excel as the DSN.

I can provide air code if you'd like.
Ah, ADO ... it is evil and must be stopped ;-) Just kidding. Yes I'm always
keen to learn new stuff and I've never used ADO, please do post your code.

Regards,
Keith.
Nov 2 '06 #4
Here it is:

Feel free to comment everyone. Good method?

Dim cn As New ADODB.Connectio n, RS As New ADODB.Recordset
Dim i As Integer
Dim strSourcePath, strSQL As String
strSourcePath = "C:\ExcelDo cs\"
'---note: need semicolon at end of .xls; for ADO to Excel
strSourcePath = strSourcePath & "Book1.xls; "
RS.CursorLocati on = adUseClient
'cn.Mode = adModeReadWrite
cn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=" & strSourcePath & _
"Extended Properties=""Ex cel 8.0;HDR=NO;"""

strSQL = "SELECT * FROM [Sheet1$]"
RS.Open strSQL, cn, adOpenDynamic, adLockPessimist ic
i = 3
With RS
.MoveFirst
.AbsolutePositi on = i
Do While Not .EOF

'Other Code here
.MoveNext
Loop
End With
RS.Close
cn.Close

Keith Wilby wrote:
"BerkshireG uy" <bd*****@yahoo. comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Keitth - Actually I can access the Excel workbook as a recordset
without a linked table. I do so by creating and ADODB connection and
use Excel as the DSN.

I can provide air code if you'd like.

Ah, ADO ... it is evil and must be stopped ;-) Just kidding. Yes I'm always
keen to learn new stuff and I've never used ADO, please do post your code.

Regards,
Keith.
Nov 4 '06 #5

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

Similar topics

0
2135
by: David Alliet | last post by:
Hello, I'm having a bit of a problem with ASP and Excel. A client has developed his own program, which calculates alot of financial stuff, in excel. I'm doing his websites and he has requested the ability to do the same thing his program does, but through the website. Because his excel program is a dozen worksheets (all packed with endless rows of formulas) long, i thought it'd use excel as backbone of the webprogram (don't worry, the...
1
4692
by: mail2atulmehta | last post by:
Hi, I do not know if this is right place for this, but i need some help. I have a text file, whose values are seprated by a delimiter. I want to open this file in excel, ( not import it) . I have written the driver prg in c#. The code opens the file, but it is not writting the values from text file into excel file. I can not figure out the problem here. This is my code: StreamReader dataFileReader = null; FileInfo file = null;...
1
2034
by: Turner, GS \(Geoff\) | last post by:
> -----Original Message----- > From: siliconwafer > Posted At: 19 August 2005 15:20 > Posted To: c > Conversation: reading an excel file in C? > Subject: reading an excel file in C? > > > Hi All, > I want to know,How can one read an Excel file into C,cell by cell?
4
5209
by: Phoebe. | last post by:
Hi, Good Day! Reading 1 excel file into a dataset is fine. How can I read multiple excel with the same data structure into 1 dataset? How can I append those data? Can someone help? Thanks in advanced. rgds,
5
8958
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column headers). I used ODBC in my VB.NET program to read that spreadsheet into a dataset, to make it easy to manipulate. The code I use to read it is as the bottom of this posting.
9
22503
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What namespaces and classes should I use and how? -- dba123
3
8029
by: Brad | last post by:
I'm having a problem reading data from an Excel file into a dataset. Can anybody give me an idea of what's happening? I've included the problematic source and the error message to the end of this message. TIA Brad Here's a snippet of my source code:
3
36044
by: Bharathi | last post by:
Hi, I got strucked with reading date value from excel file using C#.NET. For Jan-2000 the value I am getting is 36526.0. For all other dates also I am getting some double value like this. Is there any manipulation so that I can find out the date entered in
1
4702
by: sachinkale123 | last post by:
Hi, I am reading excel file and reading values from that I am using provider As : "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + Filename + ";Extended Properties=\"Excel 8.0;Hdr=No;IMEX=1\""; Column Name 'Sol 1' and 'Sol 2' is missing even though it is reading the readings. Just not able to read column names. I am not sure about what is exact problem. so please help me in solving this. Thanx in advance.
1
3619
by: ndedhia1 | last post by:
I was reading in a log file like this that had no milliseconds: QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 601650761 block size QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 606887631 block size QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 154517966 block size QuoteBlockTiming exceeded 1 ms: 1...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
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
9865
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
8876
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
7413
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
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
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.