Click here to Skip to main content
15,890,438 members
Home / Discussions / C#
   

C#

 
GeneralHave no node selected or Hide Tree view first Node Pin
tejas_kan23-Nov-04 20:45
tejas_kan23-Nov-04 20:45 
GeneralRe: Have no node selected or Hide Tree view first Node Pin
Daniel Turini24-Nov-04 1:04
Daniel Turini24-Nov-04 1:04 
GeneralRe: Have no node selected or Hide Tree view first Node Pin
Anonymous24-Nov-04 1:11
Anonymous24-Nov-04 1:11 
QuestionDoes Font.Height or Font.GetHeight() return correct font height? Pin
sachinkalse23-Nov-04 19:08
sachinkalse23-Nov-04 19:08 
AnswerRe: Does Font.Height or Font.GetHeight() return correct font height? Pin
Heath Stewart24-Nov-04 6:11
protectorHeath Stewart24-Nov-04 6:11 
GeneralQuick question on hotkeys Pin
Flack23-Nov-04 16:27
Flack23-Nov-04 16:27 
GeneralRe: Quick question on hotkeys Pin
benjymous23-Nov-04 22:32
benjymous23-Nov-04 22:32 
GeneralNeed help accessing an Excel range of cells Pin
Flack23-Nov-04 16:25
Flack23-Nov-04 16:25 
Im new to using Excel with C# and I ccant seem to get this seemingly simple task done.

What I want to do is get a range of cells from an Excel sheet and put the resulting cell values in a string array. (I know that the values are all strings).

The code I have that gets the job done is this:
<br />
string workbookPath = fileName_;<br />
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,0,true,5,"","",true,Excel.XlPlatform.xlWindows,"",false,false,0,true,false,false);<br />
Excel.Sheets excelSheets = excelWorkbook.Worksheets;<br />
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(1);<br />
Excel.Range excelCells = (Excel.Range)excelWorksheet.get_Range("A1","H1");<br />
System.Object[,] result = (System.Object[,])excelCells.EntireRow.Value2;<br />


Now, this code gives me a two-dimensional array with all of the values included, along with every other null item in that row (giving me an array with a second dimension length of 256).

I tried doing:
<br />
System.String[] result = (System.String[])excelCells.Value2;<br />

because I can see that excelCells.Value2 is an array. Unfortunately, this line gives me an invalid cast exception.

Is this way the only way I can get an Excel row into an array (without going through each cell manually, getting its value, and adding it to an array)?

How about if I wanted to multiple rows, like ("A1","H7")?

Thanks,
-Flack
GeneralRe: Need help accessing an Excel range of cells Pin
Heath Stewart24-Nov-04 6:04
protectorHeath Stewart24-Nov-04 6:04 
GeneralVB to C# Pin
npqk23-Nov-04 16:17
npqk23-Nov-04 16:17 
GeneralRe: VB to C# Pin
Nick Parker23-Nov-04 16:34
protectorNick Parker23-Nov-04 16:34 
GeneralRe: VB to C# Pin
Dave Wengier23-Nov-04 17:09
Dave Wengier23-Nov-04 17:09 
GeneralRe: VB to C# Pin
npqk23-Nov-04 17:47
npqk23-Nov-04 17:47 
GeneralRe: VB to C# Pin
Daniel Turini24-Nov-04 0:57
Daniel Turini24-Nov-04 0:57 
GeneralRe: VB to C# Pin
Heath Stewart24-Nov-04 5:58
protectorHeath Stewart24-Nov-04 5:58 
Generalremote ip Pin
Pyro Joe23-Nov-04 15:41
Pyro Joe23-Nov-04 15:41 
GeneralRe: remote ip Pin
Stefan Troschuetz23-Nov-04 22:48
Stefan Troschuetz23-Nov-04 22:48 
Questioncan I assign custom shortcuts to MenuItem.ShortCut? Pin
Anonymous23-Nov-04 14:06
Anonymous23-Nov-04 14:06 
AnswerRe: can I assign custom shortcuts to MenuItem.ShortCut? Pin
benjymous23-Nov-04 22:08
benjymous23-Nov-04 22:08 
GeneralRe: can I assign custom shortcuts to MenuItem.ShortCut? Pin
Heath Stewart24-Nov-04 5:53
protectorHeath Stewart24-Nov-04 5:53 
AnswerRe: can I assign custom shortcuts to MenuItem.ShortCut? Pin
Heath Stewart24-Nov-04 5:45
protectorHeath Stewart24-Nov-04 5:45 
QuestionWhat would the c# equivalent of make_pair be Pin
PaleyX23-Nov-04 11:13
PaleyX23-Nov-04 11:13 
AnswerRe: What would the c# equivalent of make_pair be Pin
Heath Stewart23-Nov-04 13:24
protectorHeath Stewart23-Nov-04 13:24 
GeneralRe: What would the c# equivalent of make_pair be Pin
PaleyX23-Nov-04 14:05
PaleyX23-Nov-04 14:05 
AnswerRe: What would the c# equivalent of make_pair be Pin
Nick Parker23-Nov-04 13:25
protectorNick Parker23-Nov-04 13:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.