0
Answer

retrieving data from excel problem

d_hajee

d_hajee

19y
3.6k
1
I wrote an application in where I retrieve data from 4 different excel spreadsheets in the first I am able to get all the significant data in this way: Excel.Sheets sheets = theWorkbook.Worksheets; Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1); Excel.Range range = worksheet.get_Range("A1",Missing.Value); range = range.get_End(Excel.XlDirection.xlToRight); range = range.get_End(Excel.XlDirection.xlDown); string downAddress = range.get_Address( false, false, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing); range = worksheet.get_Range("A1", downAddress); object[,] sjaak = (object[,])range.Value2; when I tried this on the next I got all the empty cells too. so I retrieved the data in this way: Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open( openFileDialog1.FileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true,Missing.Value,Missing.Value); Excel.Sheets sheets = theWorkbook.Worksheets; Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1); Excel.Range ranger=(Excel.Range)ExcelObj.Selection; ranger.SpecialCells Excel.XlCellType.xlCellTypeLastCell,Missing.Value).Select(); int hier = ExcelObj.ActiveCell.Column; int daar = ExcelObj.ActiveCell.Row; in this way I can retrieve the individual cells by scrolling through the rows an columns. this also works fine, but the third one goed terribly wrong. Ik can try either way but when I try to retrieve data from the individual cells it places the data for a whole row in the first cell. even more strange cause when I wrote the application in VB6 several years ago, it all worked fine. I try to retrieve the data in this way: Excel.Range rngprod = worksheet.get_Range("F"+i,"F"+i); dr["prodcod"] = rngprod.Cells.Value2; //(to put it straight in a datarow) does anyone know what I do wrong here?