loffredo

loffredo

  • NA
  • 1
  • 0

c# vs. excel

Aug 27 2004 5:30 AM
Hi, I have a problem while reading an Excel workbook. I mean, I succeed in opening and reading the workbook but it seems that the worksheet casting doesn't ocuur correctly so I cannot access any method or attribute of a worksheet object. See the example below: ....... Excel.Application excelApp=null; try { excelApp = new Excel.Application(); if (excelApp == null) return null; excelApp.Visible = false; excelApp.DisplayAlerts = false; Excel.Workbook excelWorkbook = (Excel.Workbook) excelApp.Workbooks.Open(strFileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true); if (excelWorkbook == null) { excelApp.Quit(); excelApp = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp); return null; } Excel.Sheets excelSheets = (Excel.Sheets) excelWorkbook.Worksheets; Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets[1]; ................ I have a couple of questions to submit: 1) Could it depend on the Excel version (I have Office 2000)? 2) If so, is there any way to access excel worksheet no matter the xls file format and the excel version ? Thanks in advance, Mario.