473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Calling Excel to run a page externally from c#

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
Nov 15 '05 #1
1 1365
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dean Bortell" <bo******@cdfainc.com> wrote in message
news:03****************************@phx.gbl...
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

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marc | last post by:
Hi all, I have a problem with managing the interchange between COM/Excel and Python if the user closes the workbook externally. Everything works fine as long as the user only uses the exit...
12
by: guy lateur | last post by:
Hi all, I am trying to write some code (macro's, if you like) to glue together our Office applications (mainly Word, Excel and Outlook). We have a lot of different projects going on...
4
by: Mark C | last post by:
I currently have an Excel spreadsheet with numerous text boxes and check boxes that I want to populate with data from an Access 97 database. I have used Excel automation in Access before but only...
3
by: Oscar F | last post by:
Hello, To create a excel report from ASP.NET I do the folowing steps: -Create a HTML document. -Use Response.ContentType = "application/vnd.ms-excel" Everything works fine and the excel...
7
by: Stu | last post by:
Hi, I have a web service which returns a record set and works well integrated with an asp dot net page. However if I decided to develop a unix app will i be able to read the dataset as it is...
4
by: Eric W | last post by:
I am converting an EXCEL VBA application to Visual Basic (2003). I am not having much luck finding how to convert statements containing references to things like ThisWorkbook.Sheets("sheetname")....
1
by: balaji | last post by:
Hi all, Is there a way to use .Net remoting via Excel macros?. I want to do is if a particular cells in the excel file changes, my .Net applicaiton need to be notified about this. Is there any...
6
by: emorgoch | last post by:
Hi there. I'm currently working on a project involving rebuilding our local intranet site. The site was originally developed using frames, defining a header, sidebar, and content area, which...
3
by: Shawn T | last post by:
I have an application with a page that has a web user control When I call that page that has this user control, locally (http:// localhost/ApplicationX/default.aspx) and also externally ie...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.