Opening password protected .xls file - epplus

Can I use EPplus to open password protected .xls files?
My current method only works for .xlsx files
Dim oFileInfo As New FileInfo("C:\Temp\test.xlsx")
Dim oPackage As New ExcelPackage(oFileInfo, "test")
For Each oSheet As ExcelWorksheet In oPackage.Workbook.Worksheets
If oSheet.Name = "Alles" Then
Debug.Print(oSheet.Cells("A1").Value)
Exit For
End If
Next

EPPlus is only able to open .xlsx files; it cannot open .xls files.
To open .xls files you should automate Excel.
Note: You should not automate Excel from a service (or any non-interactive user); as Excel can appear to spontaneously lock up if a dialog box appears and there's no user to click it.
Microsoft specifically warns against trying to automate Office application from non-interactive session (e.g. services, web-servers, scheduled tasks).
Considerations for server-side Automation of Office đź•—
All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

The NPOI.dll library can interact .xls as well as .xlsx files, and you'd program with it similarly to EPPlus. (worked at a significant company that used it in a web app to pull data out of uploaded .xls as well as .xlsx files)
I don't know how up-to-date it is with .Net Core, etc.
It is a port to .Net of the Java POI library.

Related

Javascript in Office

I am trying to understand how to develop add-ins/macros in JS for Office, do I need VSTO for it or does it run from Office somewhere?
I did understood that Microsoft is making the first steps toward replacing VBa with JS and impemented an API to develop macros in Office.Js simmilar to the one Google has for it's Docs. But where can I find a development enviroment for Office.js?
The new web-based add-ins are basically a web application executed in the context of the Office application, either on the Desktop (by embedding a browser, IE11 at the moment) or in the browser (Office Online) where everything is web-based already.
The add-in can be hosted on any web resource you like. You just need to specify a source location URI.
Settings and metadata of the add-in are defined in a manifest file. The article Office Add-ins platform overview describes it very well.
Development can be done in any editor or IDE suitable for coding web apps. There is no Alt+F11 VBA IDE anymore, but you may try the Script Lab add-in, a Microsoft Garage project that allows you to try out some code directly in Office and share code snippets. It includes a great collection of sample code too.
The new WebApplications are hosted on a Webserver. You can develop Office Apps with Visual Studio.
Here is a good course for developing Office Apps including an overview of the Javascript Office API:
https://mva.microsoft.com/en-us/training-courses/introduction-to-office-365-development-8329

Log into Outlook via Process without Dialog for password

When I try to run Outlook via Interop using the profile name it opens a dialog for the password. This script is running from Windows Task Scheduler Task. Does it use the admin account when running these tasks? The profile been made and my email account is the only one loaded in here.
The Always prompt for login credentials is unchecked for the account listed in the profile.
This is a network computer in domain. Outlook 2010.
Profile Switch(link):
Process.Start("Outlook", "/profile profilename")
'logs in with a prompt for the password
How can I pass the password in code and avoid the dialog?
Alternatively, I have a macro that does what I need, but I have not been able to get it to run when the profile loads. This would solve the problem as well. Macros enabled is checked in the Trust Center.
Thanks
First, you need to run both application under the same security context to be able to automate one from another.
This app is being launched from Windows Task Scheduler
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
As a workaround, you may consider usign a low-level API on which Outlook is based on - Extended MAPI. Or any third-party wrapper around that API such as Redemption.

Why might COM automation of Word from within a console application run as a scheduled task work on my development machine but hang on another?

I have a console application that uses COM automation to manipulate .DOC and .DOCX files in Word 2010. This works in a scheduled task for a not logged in user account on two development machine (running 32 bit Windows Server 2003) but not on another machine (running 64 bit Windows Server 2003). It does run on that machine if run from the command line by the same user account when logged in (so I don’t think it’s a 32/64 bit issue).
The code hangs at the point it tried to open a document not when the Word application is created.
I have logged in as the user account and opened the file manually (so I don’t think it is popping up any dialog boxes).
I thought that it might be something to do with autocorrect and while looking at the proofing options noticed that the “automatically use corrections from the spelling checker” checkbox is greyed out.
I have used process monitor and could not find any file access failures for files which are on the dev machine but not on the other (Word seems to look for Normal.dot in a number of places but this file in not on the dev machine either).
I am aware that Word automation on a server is not recommended or supported by Microsoft and may be outside the terms of the license.
I am using automation as I need to manipulate files for older versions of Word.
This may be related to my other issue with automation from non logged in accounts: Why might COM automation from within a console application work on my development machine but not on another? However this case is different in that opening a file is hanging rather than creation of the application program failing.
What else should I try?

IIS7.5 Excel printing not working when run from server

I'm having trouble generating a PDF-file with PDFCreator from Excel macro (using VB.NET 3.5 and Interop).
Through Windows login as the domain user I can run the macro directly from Excel and everything works fine (a pdf file is printed and saved), but when published and run as the same user from server there is no printer found.
In the macro I know this can be solved by setting Application.ActivePrinter ("PDFCreator on Ne00:" in my case), which again works when I run directly from Excel but not from server. So what I wonder is how to make it possible to set ActivePrinter when running on server?
It worked with previous IIS version on the server (6.0). I have tried giving the domain user access permissions (e.g. in DCOMCNFG), the PDFCreator is set up correctly and accessible, don't really know how to approach this.
Using Office Interop from server-like scenarios (IIS/ASP.NET/Windows Service...) is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
Another point is that since windows vista there have been several security-related changed which prevent doing any "desktop-like" things (for example printing...) from a Windows Service...
Alternative to Interop:
To create PDF from Excel file there are several libraries out there which do not use Excel and work fine in server-scenarios - like Flexcel, Aspose.Cells, SpreadsheetGear...
It works even in IIS8 also.
Give Microsoft Excel Application sufficient Permission from DcomConfig (Eg-IIS_IUSRS,Network Services etc)
take care of impersonate user id and password provided In Web.xml. do not make it true if not necessary. it worked for me when i removed this.

MS Office Add On

I want to add on certain feature in MS Office. Currently, I am looking at VBA to develop it. However, it seems that running macros requires security disabled. This means that if I distribute the VBA program, other people need to enable macros to run. (Security issues)
The problem now is, how do I distribute the VBA that I wrote? E.g. in a .exe file? And is there any other method to go about creating this add on?
I downloaded some add on for MS Word and it seems that it is written in C++ and it is in .dll format.
Thanks.
You can run macros in a document/template/add-in even in "high" security mode, if:
the VBA project is digitally signed
the user agrees to 'trust' the publisher of the digital signature
The first time the user runs a macro signed with your digital signature, they'll get a prompt saying "the macros are signed by YourCompanyName - do you want to trust all add-ins from this publisher". If they click "yes", they won't see the prompt again - and your macros will run.
See this link for details of how to create a digital signature.
Visual Studio Tools for Office (VSTO) allows you to author extensions to Microsoft Office using any .NET language, including Visual C++. Such extensions would indeed compile to DLL-files, and after installation on a client machine, they wouldn't require the user to dismiss any additional security warnings. You will need Visual Studio 2005/2008 Professional in order to use the VSTO framework.
Wikipedia has more information about VSTO, including a comparison with VBA. Amazon seems to have a fair amount of books on the subject as well.