LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default unable to read first cell from 2nd row

I am trying to load a spreadsheet into a DataTable and have code to read one
cell at a time. When I try to read the first cell of the 2nd row (A2), the
value returned is always null. Do I need to call Select() somewhere? My
spreadsheet has 21 columns and 2 rows.

Here's my code:

workbook = app.Workbooks.Open(fileName,
Type.Missing, true, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);

worksheet = (Excel.Worksheet) workbook.Worksheets[1];
range = worksheet.get_Range("A1", Type.Missing);

Excel.Range rangeTemp = range.get_End(Excel.XlDirection.xlToRight);
sheetColumns = rangeTemp.Column;

rangeTemp = range.get_End(Excel.XlDirection.xlDown);
sheetRows = rangeTemp.Row;

string cell;
for (int rowCount = 0; rowCount < sheetRows; rowCount++)
{
if (repRow == null)
repRow = repList.NewRow();
for (int columnCount = 0; columnCount < sheetColumns; columnCount++)
{
cell = Convert.ToString((char)('A' + columnCount)) +
Convert.ToString(rowCount + 1);
range = worksheet.get_Range(cell, Type.Missing);
value = range.Value2 == null ? "" : range.Value2.ToString();
...
}
...
}

Thanks,
Jerry


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to read file ! Tufail Excel Programming 0 June 5th 06 01:17 PM
unable to read file phrenchie Excel Discussion (Misc queries) 0 January 16th 06 07:59 PM
unable to read file R.VENKATARAMAN Excel Discussion (Misc queries) 3 May 20th 05 10:42 AM
unable to read file Dave Hall Excel Discussion (Misc queries) 0 December 20th 04 10:58 AM
Unable to read file rake Excel Programming 0 September 29th 04 07:48 PM


All times are GMT +1. The time now is 02:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"