473,395 Members | 1,458 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,395 software developers and data experts.

Excel connection

Hi,

How can I make a connection to an Excel file, and I can select the specific
fields? For example in sheet1:

A B C
1 20 change good
2 short return 50
3 order shipped 3

How can I get the value of "C2" in ASP? I want to the the connection and the
select statement.
Thanks for any help.
--
Andrew

Jul 19 '05 #1
6 3758
Andrew,

Look into "Named Ranges" in Excel. Once you have created a named range, for
the ranges of values, you can query Excel as if it were a table.

Considering you will have a header row, the following is a connection
string:

connString = "Provider=Microsoft.JET.OLEDB.4.0;Extended Properties=""Excel
8.0;HDR=YES;"";Data Source=C:\Myfile.xls"

Set conn = Server.CreateObject("adodb.connection")
Conn.Open connString

' Considering C is the header name for third column
Set Rs = conn.Execute("select C from MyNamedRange")
Rs will now contain the data, the question is how to get the second row. You
can either specifically get the second row with your query ("select C from
where A=2")

Hope that helps.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Andrew" <du******@yahoo.com> wrote in message
news:u6*****************@news04.bloor.is.net.cable .rogers.com...
Hi,

How can I make a connection to an Excel file, and I can select the specific fields? For example in sheet1:

A B C
1 20 change good
2 short return 50
3 order shipped 3

How can I get the value of "C2" in ASP? I want to the the connection and the select statement.
Thanks for any help.
--
Andrew

Jul 19 '05 #2
Manohar,

A, B, C... is the Column is the worksheets1(no column name), and 1, 2, 3 ...
is the row. Actually I want the values of more than one field, like A2, B1,
C2 and so on.
Can you help? Thanks anyway.

--
Andrew
"Manohar Kamath [MVP]" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Andrew,

Look into "Named Ranges" in Excel. Once you have created a named range, for the ranges of values, you can query Excel as if it were a table.

Considering you will have a header row, the following is a connection
string:

connString = "Provider=Microsoft.JET.OLEDB.4.0;Extended Properties=""Excel
8.0;HDR=YES;"";Data Source=C:\Myfile.xls"

Set conn = Server.CreateObject("adodb.connection")
Conn.Open connString

' Considering C is the header name for third column
Set Rs = conn.Execute("select C from MyNamedRange")
Rs will now contain the data, the question is how to get the second row. You can either specifically get the second row with your query ("select C from
where A=2")

Hope that helps.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Andrew" <du******@yahoo.com> wrote in message
news:u6*****************@news04.bloor.is.net.cable .rogers.com...
Hi,

How can I make a connection to an Excel file, and I can select the

specific
fields? For example in sheet1:

A B C
1 20 change good
2 short return 50
3 order shipped 3

How can I get the value of "C2" in ASP? I want to the the connection and

the
select statement.
Thanks for any help.
--
Andrew


Jul 19 '05 #3
You could use HDR=No, and for column names use 1, 2, 3 instead of A, B, C.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Andrew" <du******@yahoo.com> wrote in message
news:UV****************@news04.bloor.is.net.cable. rogers.com...
Manohar,

A, B, C... is the Column is the worksheets1(no column name), and 1, 2, 3 .... is the row. Actually I want the values of more than one field, like A2, B1, C2 and so on.
Can you help? Thanks anyway.

--
Andrew
"Manohar Kamath [MVP]" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Andrew,

Look into "Named Ranges" in Excel. Once you have created a named range,

for
the ranges of values, you can query Excel as if it were a table.

Considering you will have a header row, the following is a connection
string:

connString = "Provider=Microsoft.JET.OLEDB.4.0;Extended Properties=""Excel 8.0;HDR=YES;"";Data Source=C:\Myfile.xls"

Set conn = Server.CreateObject("adodb.connection")
Conn.Open connString

' Considering C is the header name for third column
Set Rs = conn.Execute("select C from MyNamedRange")
Rs will now contain the data, the question is how to get the second row.

You
can either specifically get the second row with your query ("select C from where A=2")

Hope that helps.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Andrew" <du******@yahoo.com> wrote in message
news:u6*****************@news04.bloor.is.net.cable .rogers.com...
Hi,

How can I make a connection to an Excel file, and I can select the

specific
fields? For example in sheet1:

A B C
1 20 change good
2 short return 50
3 order shipped 3

How can I get the value of "C2" in ASP? I want to the the connection
and the
select statement.
Thanks for any help.
--
Andrew



Jul 19 '05 #4
This is a VERY bad way of programming - names ranges are unreliable as the size of the data is liable to change, and then some of it will fall outside of the named range. Additionally if data is removed the named range will include rows of nulls which will inevitably make the database fall over.
Jul 19 '05 #5
Instantiate an instance of Excel (CreateObject("Excel.Application")) and use the Cells(row, column) property of a worksheet object.
Jul 19 '05 #6
My answer was specific to this problem... of course you can instantiate
Excel objects, but these are not multi-user friendly and take a ton of
memory. Actually, you can set the named range to be the entire worksheet
(although I have not tried querying this).

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Bonj" <an*******@discussions.microsoft.com> wrote in message
news:AC**********************************@microsof t.com...
This is a VERY bad way of programming - names ranges are unreliable as

the size of the data is liable to change, and then some of it will fall
outside of the named range. Additionally if data is removed the named range
will include rows of nulls which will inevitably make the database fall
over.
Jul 19 '05 #7

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

Similar topics

0
by: acharyaks | last post by:
Hi life saver, I am using excel component for the development. The purpose is to connect to excel through the odbc connection string. Then through the connection extract data into a dataset and...
1
by: Mike P | last post by:
I'm trying to take some data from an Excel spreadsheet, put it into a dataset, and then update a SQL table with the data. I'm not 100% sure I'm doing this right, can somebody tell me what I'm...
4
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: DrewYK | last post by:
I have the project that may never end in front of me. I am creating a routine that will take SpreadSheets from Excel and bring them into Access. I am not using any "DoCmd"s because the goal...
7
Merlin1857
by: Merlin1857 | last post by:
Its great producing data for users to look at in your web pages and generally that is sufficient for their needs but sometimes you may want to supply your user with the data in a form they can...
1
by: =?Utf-8?B?ZmhpbGxpcG8=?= | last post by:
We have a code snippet that downloads data to Excel. it is writing row by row. This causes a performance issue. Any ideas on how to speed this up will be appreciated. Please find below an...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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
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...

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.