473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C# Simplest way to read values from Excel file

2
I'm doing some basic programing in C# and want to read two numeric values from an Excel file.

Hope I'm in the right forum. The C# code is compiled and used within a vendor's charting application.

So confused I don't know where to start. Is there a simple way?

Thanks for your help.
Aug 27 '07 #1
2 1912
you can connect to an excel file using a OleDBConnection and run a sql query to get the data from it.

Expand|Select|Wrap|Line Numbers
  1. string sql = "SELECT  * FROM [WORKBOOKNAME$]";
  2.  
  3. string strConn = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + fileName + ";Extended Properties=Excel 8.0;";
  4. OleDbConnection objConn = new OleDbConnection(strConn);
  5. OleDbCommand objCmd = new OleDbCommand(sql, objConn);
  6. OleDbDataAdapter objAdp = new OleDbDataAdapter(objCmd);
  7.  
  8. DataSet data = new DataSet();
  9. objConn.Open();
  10. objAdp.Fill(data);
  11.  
Aug 29 '07 #2
rvon
2
Thank you for replying. Clearly this is beyond my experience. It appears that the numbers are imported as strings. How do I access them and how do I get them to be type double?
Sep 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Daniel Chartier | last post by:
Hello, all. I found a bit of code that lets me read an Excel file from and to a specifi range. See the code below. But what if I only want to specify the STARTING position and simply want it...
2
by: Bertrand | last post by:
Hello, I am trying to archieve the following: - copy an excel file present on the server - insert values into named ranges of the copy I am using Excel97 on my PC, the server does not have...
4
by: see_mun_lee | last post by:
I use asp to develop a web page to read an excel file containing Chinese Character then display it in the web page. Unfortunately, I cant display it!!! it will display (?????????). <META...
3
by: Sobhan | last post by:
Hi all, I am writing a program in C in which I need to read a data file and export to the excel.The Data in the file in CSV format. Values in the .txt file are as follows: "a","b","c" 10,20,30...
4
by: Hardy Wang | last post by:
Hi all, I have following code to read Excel content into a DataSet string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel...
12
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the...
1
by: colleen1980 | last post by:
Hi:Can any one please tell me how to convert excel file into a text file thru VB6 Program? Also is it possible that i read the values from the converted text file of any column one by one thru do...
1
by: ashok0866 | last post by:
I had created a macro to read data from an excel sheet and write the values to a text file. I had used "ActiveSheet.Range("GB" & k).Value" command to read the values from the excel. The issue...
0
by: mohaaron | last post by:
I am finding that when a GridView is export to Excel by changing the ContentType of the page the Excel file is not readable by OleDb or SQL Server DTS. I also tried using a Excel Reader that I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.