Calling Excel to run a page externally from c#

  • 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!!!!

Dean
 
Dean,

If you want this to run with a version of office that came before the
version you developed for, then you have a few options:

- Get the interop assemblies for the versions of Office that you are trying
to target, and then have switch statements everywhere which will determine
which references to call based on the version of Office that is installed on
the machine (tedious, to say the least).

- Use late bound calls to call the COM components directly. This would
probably be the best solution (which coincidentally, VB is better suited
for, if you have a lot of calls, as it handles all of the late bound calls
for you automatically).

Hope this helps.
 
Back
Top