C# Excel 2010 Workbook Open error - c#

We recently upgraded from Excel 2007 to Excel 2010, and we have found that existing code started failing.
Exception Message:
Office has detected a problem with this file. To help protect your
computer this file cannot be opened.
We have traced this to the line where we open the file
excelApp.Workbooks.Open
Even when opening the file manually, the Protected View Messagebox comes up.
How can we work arround this using C#.

Have a look at using Application.FileValidation Property (Excel) before your Open statement.
Returns or sets how Excel will validate files before opening them.
Read/write
Files that do not pass validation will be opened in a Protected View
window. If you set the FileValidation property, that setting will
remain in effect for the entire session the application is open.
You can set it to one of the enum values in MsoFileValidationMode Enumeration
msoFileValidationDefault
msoFileValidationSkip
if you set it to msoFileValidationSkip before the Open statement, it should bypass the check.
Something like
excelApp.FileValidation = MsoFileValidationMode.msoFileValidationSkip;
before the open statement.

Late to the game here, but this is a common annoyance: you need to define a 'Trusted Location'.
You're not the only developers encountering this problem when your code tries to open a spreadsheet file, and "Office has detected a problem with this file. To help protect your computer this file cannot be opened." is an extremely unhelpful error message.
Look up the Trusted Location code published by Daniel Pineault on DevHut.net in 2010:
DevHut code example: Trusted Location using VBScript
I'll get downvoted to hellandgone for posting VBA in a C# forum, so I'd better not post my implementation of Daniel's code (yes, I'm a VBA developer, bashing out VBA macros all day, not a real coder working with pointy things and curly braces). If you really want to see the VBA, it's in a reply to another post:
https://stackoverflow.com/questions/2962728/office-trusted-locations/28115700#28115700
I believe the proper salutation is 'Share and Enjoy'.
Do, please, put an acknowledgement of the original author, Daniel Pineault, if you reuse the code: it's been widely published without attribution on 'Expert' sites, and that's rather rude.

We had the same issue. Our SSIS package at SQL server uses Excel.Interop to parse files. One day we installed Office 2010 x64 on new server and for some files started getting error:
Office has detected a problem with this file. To help protect your computer this file cannot be opened.
At the same time, other servers work good. We found distinguish in versions of Excel: 14.04763.1000 doesn't work, but 14.0.7015.1000 works for us. The last version number belong to Office 2010 SP2. Eventually we downloaded SP2 and installed it,as result, the error has gone.

Related

Microsoft Excel is waiting for another application to complete an OLE action Error

I frequently receive ok-only prompts while automating add-ins in Excel, stating that Microsoft Excel is waiting for another application to complete an OLE action Error. How to use Interop.dll to show a custom message and handle this error programmatically. Before receiving the promptenter link description here
While You possibly can catch these exceptions depending on your automation framework and do something with it - these type of errors typically comes from not closing the files properly when changing from one to another.
Make sure you dispose all that can be disposed and close all which can be closed in reverse order obviously and it should go away.
If You need more details do post your code for opening and closing looks like a bug there which will make it not coming up.
You do not technically have to use interop, could you consider using a more modern package for interacting with excel?
If you are using google drive / file stream then this may be the problem. Turn off "Real Time Presence in Microsoft Office" then the messages go away.

Unrecognized database format when opening Access file inside Visual Studio - Why?

I have recently taken a project for a client which involves working with their Microsoft Access database programmatically with C# in Visual Studio 2015/2017.
The database opens in my 64-bit version of Microsoft Access 2010 just fine, and I can use/alter all tables/queries perfectly fine. However, when trying to open this .accdb database in Visual Studio, I am getting the dreaded "Unrecognized database format". Now, I do have the Microsoft Office Access database engine for 2007 and 2010 installed, and I am able to open/work with other databases created in Access.
I believe the database was created in Access 2007, as when I open it up, the title of the window contains "(Access 2007 - 2010)", so I'm not sure if that would cause the error or not?
One interesting thing I found was, because I do not need every table in the database, I copied one by one the tables I need into a new database file and checked if I could open this new Access database in Visual Studio. Out of 6 tables that I needed, the last one I needed caused the file to become "unrecognizable" inside Visual Studio.
Why? I have no idea. The table is just like any other, contains lots of columns which either have text, numbers or dates.
My question is, has anybody had a similar experience with this? Could it be the fact that it was made from Access 2007? Why would copying and pasting to a new database then cause that database to be corrupt?
Thanks a lot.
There's a difference in the formats. The older format (..2007) is MDB and the later ones (2010...) are ACCDB. If you used any features only available in ACCDB, like attachments, you cannot convert back to MDB and neither will ANY current Microsoft tool other than Access open it. Strange but true.
Painful is to exclude those tables or forms that use the new features and then do the conversion.....sigh.....

Export to Excel not working on Main server

Hie guys I am in a bit of a Problem here regarding Export to Excel in asp.net where I am Exporting the Webgrid data to the Excel Sheet and it is working fine on localHost but not on the main server even when it is deployed on the Main server.
I am using Microsoft.Office.Interop.Excel.Application to genrate excel sheet.
When I click on the button for genrating Excel on the main server I get the following error-
Failed to Export-Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the
following error: 80040154.**Class Not registered
I googled for the solution bbut couldnt found one which can solver my problem I read it somewhere that I need to install Excel on my Main server too to get this functionality working. Is this is the solution or is their any Plugin which can help In order to solve this problem and export to excel work on the MainServer..
Please help
I recommend you read server-side Automation of Office.
It is not good idea to acess excel data from main server. I would suggest you use Open XML instead.
You can also take a look at third parties tool's such as
EPPlus
Short answer is – yes it’s necessary.
Long answer is that this is not recommended practice. Your web server is run by network service or some other limited privileges account that doesn’t even have permissions to run excel.
Extending those privileges to running excel may result in reduced security and potential damage to your server is something bad gets into your excel document (such as malicious macro or something like that).
Link Kyle provided is an excellent resource to find out more about this.
If possible try to move to OpenXML or some other library.

Error 1001 An error occured in sending the command to the application

COM Excel AddIn, C#, VS2008
The error happens occasionally when I install/uninstall my AddIn.
sometimes I see Error 1001 the specified file can not be found
Anyone know what causes these and how to fix? thanks
I use windows installer
http://msdn.microsoft.com/en-us/library/2w2fhwzz%28v=VS.90%29.aspx says if use [TARGETDIR], it should be like "[TARGETDIR]\" or "[TARGETDIR] ". I simply use /filepath = "[TARGETDIR]myinstallfile" in CustomActionData
What I do not understand is it works almost all time and fails occasionally
Also even if I change this to including space or backslash, I can't tell if that fixes issue since the issue does not happen every time. Anyone has experience? thanks
I found this and it fixes the issue though I am not sure I ever use DDE in my program
http://sympmarc.com/2010/02/04/microsoft-excel-error-there-was-a-problem-sending-the-command-to-the-program/
Then I found this http://www.opendylan.org/documentation/opendylan/interop2/inte_278.htm
It talks about COM Server
so I went to cmd, type in "Excel.exe /RegServer", then the error disappears.
I am not really not sure if this solution works for all cases.
In fact, I am concerned that I miss sth in installer.
Here is a Microsoft Support page related to an issue which looks quite similar to yours. So for me it looks like a bug in Excel rather than in your installer.
The article is quite large, but it boils down to making sure that:
your Excel app is not running with elevated rights
advanced setting "Ignore other applications that use Dynamic Data Exchange (DDE)" is unchecked
Other than that you might try to repair Excel installation or follow the advice given in this thread of ASP.NET forums to fix the registry for Excel installation.
I hope it helps someone facing similar issues.
If you get this type of error when uninstalling a VS setup project MSI, then the most likely reason is that TARGETDIR is not preserved between the install and the uninstall, therefore it has no value, and attempts to use it in an uninstall custom action will result in failure to find the file. The easiest solution (apart from always installing to known locations such as common files etc) is to save TARGETDIR to the registry and retrieve it later. In the VS IDE you can create a registry item with the value [TARGETDIR] to have it resolved at install time.

Operation Not Implemented Exporting Excel (Data Only) Crystal Reports 2008

I'm trying to deploy an application to a client's server, but export to Excel (Data Only) is not working, giving me the "Operation Not Implemented" error. It isn't a problem with the report, because I have over 50 reports with standard fonts, some of them very simple, and the export fails for all of them.
I have the feeling the incorrect version of exportmodeller.dll and crtslv.dll are being used, because the client seems to have some sort of logon script which appears to copy a CR8.5 version of the crystal reports libraries and register them with COM.
I attempted to automatically make a manifest file for my main executable to force it to use the correct version, but this didn't change anything.
Might I have missed something, or do you think I'm completely on the wrong track?
I narrowed the problem down to being related to a format issue with the report. It just happens to not affect my Windows 7 dev machine.
On the Windows Server 2003 R2 (x64) machine, if I remove the Print Date and Print Time special fields, it will export to xls (Data Only) successfully.
I did also notice that the process loads ATL.DLL on the Windows 7 box, but not the Windows Server box. I gather that could somehow be related.
So, a solution to my problem is to remove those fields. Full points if anyone can offer some advice which would prevent me from having to edit all of my reports.
Update: If I use a specific date/time format in my reports instead of "System Default Format" it also works.

Categories

Resources