Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Unable to read file ! | Excel Programming | |||
unable to read file | Excel Discussion (Misc queries) | |||
unable to read file | Excel Discussion (Misc queries) | |||
unable to read file | Excel Discussion (Misc queries) | |||
Unable to read file | Excel Programming |