tags:

views:

779

answers:

3

I'm facing a strange issue when trying to open an excel sheet through a C# application. it uses something like the following while the templatePath is "C:\template.xls" for example.

Workbook excel_workbook = this.excel.Workbooks.Open(templatePath,
mMissingValue, false, mMissingValue, mMissingValue, mMissingValue, mMissingValue,
mMissingValue, mMissingValue, mMissingValue, mMissingValue,
mMissingValue, mMissingValue, mMissingValue, mMissingValue);

then it involves the excel_workbook object in some operations. the problem is that excel_workbook.name = template1 not template which results in displaying the save as dialog box when clicking on save. this behavior breaks the workflow from the business prespective.

would anyone help in this? noting that other sheets are working correctly.

A: 

I am not sure how to force Excel not to display the dialog, but you might try using SpreadsheetGear for .NET or another .NET component rather than Excel automation to avoid issues like this - and most likely get some performance improvement as well.

You can see live ASP.NET samples here and download a free trial here if you want to try it out.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson
thanx for responding but this is not exaclty what i'm asking for. the problem is that the workbook opened has the same name of the sheet prodived in the path but with a suffix 1. which means it is a different instance and that cause the pop up of the save dialog box when clicking on save (not save as...) instead of saving the file silently.
Developer
A: 

There is no way to prevent Excel (or other Office application) from displaying dialog windows. Actually, Microsoft does not recommend using Office application in server-side scenarios. There are great 3rd party components in the market that do the same job (or even better). From a comparison testing I performed about a year ago Spire.XLS for .NET is the best from the following perspectives: 1. Read/Write of excel 2. Support of embedding images 3. Size of result Excel file is very small 4. Convenient API and very similar to Office's one 5. Multi-threaded and multi-process support

Read more: http://www.e-iceblue.com/xls/xlsintro.htm

Boris Modylevsky
A: 

You are explicitly passing in 'false' for the 'ReadOnly' parameter, so this behavior is odd.

I have two ideas here:

(1) Are you sure that your workbook is a .XLS file and not a .XLT? if it is a .XLT, as in "C:\template.xlt" instead of "C:\template.xls", then the behavior you are seeing is NORMAL, because your workbook is being opened as a template. Change the extension to ".XLS" and you will get the behavior that you want.

(2) If you cannot get it to behave the way you want, then change your procedure to call 'Workbooks.Open', then immediately call 'Workbooks.SaveAs' and set the workbook name and/or file path location to whatever location you want. Thereafter, any call to 'Save' by the user (or via code) would save the workbook without opening the Save As dialog box.

Update

Ok, other thoughts:

You should try opening the workbook manually and then try to save it. Do you get the same problem? Does this happen when this workbook is the only workbook that is open, or only when others are open as well? Does renaming the workbook help?

The bottom line, though, is that it really does sound like some sort of bizarre corruption. If none of the above yield anything interesting -- or probably even if they do -- you would probably want to start over with a new workbook. Beginning with a blank workbook, give it the same name and putting it in the same location. Does it work now (at least in terms of opening and saving). Then try adding your data and other aspects to it. It will be work, but you should be able to re-build this workbook and get it working.

-- Mike

Mike Rosenblum
Thanks Mike(1) It is .XLS not .XLT(2) I'm afraid that the application has been already deployed to a number of users and it not that easy to change in the code a redeploy a new version. the strange thing is that it is working correctly for other sheet. so I'm wondering what is the root cause of the issue and is there a workaround to fix it in the sheet itself of whithout changing the code?
Developer
This is really bizarre behavior; it really does sound like a corruption of some sort. I don't have any brilliant ideas here, but I've put in a few more ideas within the "Update" section, above.
Mike Rosenblum