Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to pass through a value in a cell in excel into a variable in a textbox. How can I do that?

For Example (simple) I have the following code in a textbox, the date appears in cell "A1" on different worksheet in excel. I am look for something that will pass through the new date I enter in cell "A1" (e.g. 4/30/2011) without me having to change the code.

SQL
SELECT
	ReportingRegion,
	CRLLT,
	CRLLD,	

FROM
	RetailReporting

WHERE
	date = 3/31/2011 

Thanks,
Posted
Updated 26-May-11 15:14pm
v2

1 solution

I think you are asking how to retrieve cell values from an Excel document so that they can be used in your application, such as for populating form controls.

1. Use a component to read excel files. There are many examples of this on this site for both modern OpenXml and the legacy BIFF format.

2. Use Interop to control an instance of Excel[^] in order to retrieve the values you're interested in.

3. Use an ADO.NET data provider.[^] This will allow you to query the spreadsheet with SQL-like syntax such as in your example.

I could also interpret your question as to how you can link an Excel document to your application so that changes to the source document are automatically updated in your application.

4. This is accomplished using OLE, a subset of COM+,[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900