[Excel, C#2005] Getting Cell From CellName
I'm using the Excel Interop to input a number of strings into cells. The cells can change depending on the excel "template" I open.
The cell names are constant however: the template file will always have a number of input cells with specific names.
What I need to do (In Visual C#, 2005) is get the specific cell in the worksheet from a name I specify in the code, and change it's value.
So far I have the following set up:
Code:
Excel.Application oXLApp = new Excel.Application();
oXLApp.Visible = true;
Excel.Workbook oXLBook = oXLApp.Workbooks.Open(
Application.StartupPath + "\\Template1.xls",
openFileDialog1.FileName, 0, true, 5,
"", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,
0, true);
Excel.Worksheet oSht = (Excel.Worksheet)oXLBook.Worksheets.get_Item(1);
From there I'm not sure where to go. Any help would be appreciated.
Qu.
Re: [Excel, C#2005] Getting Cell From CellName
It's probably easier if you give us an example of what you mean by
Quote:
What I need to do (In Visual C#, 2005) is get the specific cell in the worksheet from a name I specify in the code, and change it's value.
what's the name you specify in the code? how is the name related to the worksheet?
Re: [Excel, C#2005] Getting Cell From CellName
i guess this should work, assuming the cell name is a defined named range
osht.Range("myname").Value = 123
1 Attachment(s)
Re: [Excel, C#2005] Getting Cell From CellName
Sorry guys: what I meant was something like this (see attachment).
Rather than specifying (in code) that I'd like to input a string into Cell[2,2], I'd like to specify Cell["INPUT1"].
"INPUT1" could be any cell in the file.
Re: [Excel, C#2005] Getting Cell From CellName
did you try the code i posted, it should do what you want, change "myname" to "input1"
Re: [Excel, C#2005] Getting Cell From CellName
See post #3 of my Office/C# FAQ:
http://www.vbforums.com/showthread.php?t=406639
I show how to access a specific cell (1, 1) in the example procedure "btnOpen_Click"