C# works with Excel 2002 but not Excel 2000?

  • Thread starter Thread starter Dean Bortell
  • Start date Start date
D

Dean Bortell

This code runs fine on win xp and office xp:

string sheetPassword = "Senior1993";
string sheetToOpen = "NewRpt1c.xls";
Excel.Application excelApp = new Excel.Application();
excelApp.Visible=true;
object spreadsheetFileName = Environment.CurrentDirectory
+ "\\" + sheetToOpen;
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open
(Convert.ToString(spreadsheetFileName), 0,false,
Type.Missing, sheetPassword, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
excelApp.Visible=true;
Application.Exit();

However, on Windows 2000 (.net framework 1.1 installed)
with office 2000 installed it does not work! I need this
to work with office 2000. Am I doing it wrong? Please
give code examples on how to work with excel 2000
workbooks (already exist in the application folder) with
c#. Please Help!!!!
 
Hi Dean,

I think you need different (primary) interop assemblies for different office
application versions.
"Currently, Microsoft provides PIAs for Office XP (and newer versions) only"
from MS website"
That makes that you have to import Excell's 2000 dll manually as normal
ActiveX library.
 
¤ This code runs fine on win xp and office xp:
¤
¤ string sheetPassword = "Senior1993";
¤ string sheetToOpen = "NewRpt1c.xls";
¤ Excel.Application excelApp = new Excel.Application();
¤ excelApp.Visible=true;
¤ object spreadsheetFileName = Environment.CurrentDirectory
¤ + "\\" + sheetToOpen;
¤ Excel.Workbook excelWorkbook = excelApp.Workbooks.Open
¤ (Convert.ToString(spreadsheetFileName), 0,false,
¤ Type.Missing, sheetPassword, Type.Missing, Type.Missing,
¤ Type.Missing, Type.Missing, Type.Missing, Type.Missing,
¤ Type.Missing, Type.Missing, Type.Missing, Type.Missing);
¤ Excel.Sheets excelSheets = excelWorkbook.Worksheets;
¤ excelApp.Visible=true;
¤ Application.Exit();
¤
¤ However, on Windows 2000 (.net framework 1.1 installed)
¤ with office 2000 installed it does not work! I need this
¤ to work with office 2000. Am I doing it wrong? Please
¤ give code examples on how to work with excel 2000
¤ workbooks (already exist in the application folder) with
¤ c#. Please Help!!!!

You need to identify what isn't working (line of code, error message?)

You may also want to consider using late binding (declare as Object).


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Your project needs to reference the _oldest_ version of Excel that you
intend to support. As Miha notes, if you want to support Excel 2000 and
higher, it must reference the Excel 9 type library. (There isn't a primary
interop assembly available for older versions of office, but VS will create
an interop assembly if you reference the library.)

The app will then be compatible with Excel 2000, Excel XP and Excel 2003.


 
Back
Top