How to programmatically load an XLL file into Excel? - c#

How to programmatically load an XLL file into Excel when it is linked to other DLLs.
Using c# winforms application + Excel Automation I’m creating Excel Application object. Then I’m using:
bool bXllLoadSuccess = _excelApp.RegisterXLL(_pathXll);
It is OK when XLL is self-contained. The problem occurs when it depends on other DLLs. Even when I put them into the same folder Excel doesn’t want to pick them up.
I tried to do following before loading the XLL but it doesn’t help:
_excelApp.DefaultFilePath = Path.GetDirectoryName(_pathXll);
I have tried this one as well:
Directory.SetCurrentDirectory(Path.GetDirectoryName(_pathXll));
Dependency walker shows no issues – all required files are in the same folder with the XLL.
Any ideas?
Thanks.
UPD: I tried copying all requried dlls into a folder and then added it's path to PATH variable. Didn't help :)
UPD2: I tried to change current directory for both c# app and Excel application object at the same time. Didn't help :(

Related

Deploying Excel DNA Application

I am a newbie to using Excel DNA so please pardon if the question is off. I have an ExcelDNA project that I am trying to find the steps on how to publish and deploy on the user's machine. The Application is written in c# using vs2017 and is a class library that I installed the ExcelDna.Integration and Microsoft.Office.Interop.Excel DLLs. The application is small at this point it contains a class called RibbonControl which inherits from ExcelRibbon. In the RibbonControl class, there is an XML tag that declares buttons and onaction methods. This creates buttons in the Ribbon. The functions of the button just write data to the excel sheet using the Microsoft.Office.Interop.Excel DLL. I am not using an a vsto add in or anything just the Excel interop lib and Excel DNA. When building in Release mode the directory looks like this
My question is can I publish this application as is and if so how would I go about doing that. If not what do I need to to get this application published and deployed. Thanks
The intention is that you now have two single-file packed add-ins:
Ribbon-AddIn-packed.xll
Ribbon-AddIn64-packed.xll
These are the add-ins for the 32-bit and 64-bit versions of Excel respectively, and if everything is set up correctly, you need only redistribute these.
But you should first check that the EPPlus.dll was correctly packed and works, so I suggest you copy the appropriate packed add-in into a separate directory on your machine, and check that it works fine from there. If not, copy in the EPPlus.dll next to the .xll, and check again.
The EPPlus.dll dependency would not be packed if you didn't add the required <Reference Path=... Pack='true' /> line into your .dna file.
Once you have the packed add-in working right on your machine, those two files are all you need to distribute (or just one file, if you know the bitness of the Excel installation of the user).
To load into Excel - simplest is to copy the .xll to a convenient directory, then File -> Open from within Excel. Your ribbon should load and everything should work.
Then to install as an add-in that loads automatically, go to the add-ins dialog (either just press "Alt+t i", or navigate with File -> Options -> Add-Ins ... Manage: Excel add-ins) then browse to the .xll and select it.

Open pdf file dynamically from toolstripmenu c# winform

i'm trying to open a pdf file from my winform application, while the pdf file is in the directory of the application. I want to pack this app latter so I can open them dynamically even if the app is installed in another machine. I'm using Process.Start(".\file.extension") but I'm getting the error: The system cannot find the file specified. I heard that I need to send it in System32 folder but when I pack it I have no idea how to send it there. Hope you understood and can come with a solution for this problem. Thanks in advance.
If the pdf file is inside the project itself, You can simply do this:
Your PDF File as seen from the solution explorer > Right Click > Properties
Copy to Output Directory > Copy Always
After this, each time you build your project or when you deploy it, The PDF file will always be included in the project output folder.
Try this...
string commandexec = string.format("{0}\{1}",AppDomain.CurrentDomain.BaseDirectory,filename);
Process.Start(commandexec);

Accessing an excel Project from A Winform Project in same Solution

I am trying to open an excel project in my Solution from a Winform Application. Please note:
Winform is my starting Project.
I can add Winform Reference in Excel but I can not add Excel Reference in Winform Project.
As I mentioned I cant find Excel Project in ADD REFERENCE>SOLUTION of Winform project. I also cant add it manually (Invalid dll or COM file Error!).
Any idea?
To open up excel you can use this:
Process.Start("excel.exe"); // or the real path of excel
And to have it open up with a certain worksheet, you could pass as an argument the path of the file:
Process.Start("excel.exe \"c:\My Folder\book1.xlsx\"");
i think iam not really getting what you mean but if you need to open the excel file with one click in the app
and you dont want to write the path of the excel file (may be because you want you app portable)
so the answer is to 1- put the excel file anywhere in the project folder
2- add existing item (. filter) and select the excel file
3-change the properties of the excel file
build action: resource
Copy to output directory:copy always
4-open the properties of the solution and click resources the drag the file and drop it
5-use the (using system.reflection & using system.io & using system.resources)
then write the code like this
string sPath = Path.GetTempFileName();
File.WriteAllBytes(sPath, Properties.Resources.excel File name here);
then take that (spath) and use it as your path so then you can change the project location with the excel file inside it and it will still be working without writing a constant path for it

Workbooks.Open cannot find file, but path is correct

I'm building a C# addin for Autodesk Inventor. The only reason this is relevant is because I had to uncheck the box "Register for COM Interop".
Here's what I'm using. The xls is always in the same directory the code is running in. I've tried this with an absolute path as well, but I get the same error. The bool is for testing only, but it returns true. The file is not read-only.
bool fileExists = File.Exists ("Assembly3.xls");
xlBook = xlApp.Workbooks.Open ("Assembly3.xls");
Error message I'm getting: https://dl.dropbox.com/u/46698764/cantFindFile.png
Since it says COMException, I'm thinking my problem might be because I unchecked the "Register for COM Interop" box. If this is the case, can someone recommend a different way to open the workbook?
If it matters, I have Excel 2010.
Try specifying the full path. Excel might be opening with a different startup directory and it could be looking in that directory for the XLS file. Since you are hosted as an addin, you might need to play with different ways to get the path. A few places to start would be:
Application.StartupPath
GetCurrentDirectory

Is there any Open source Library to generate and edit .xls and .ppt file?

My task is to extract information from ppt file and compare with another ppt file. I have to use windows platform so i used excel and powerpoint's COM object.
After developing and testing the code in my computer when i exported the file into another computer it just failed. I started to debug in that file, and surprisingly debug was successful from first to last but as soon as click on the executable it fails.
I am totally *ucked up now cause inspite of updating excel dll files into those computers (which will serve the com support) it's not working. In every pc it gives different error message. I don't wanna work COM object anymore. It *ucks.
Can anyone suggest me any open source alternative in which i can read and extract information from Excel and Powerpoint files (both 2003 and 2007 format) ???
My preferred language is c# ........I got an paid solution (aspose) but i don't wanna go for that.
Any help will be appreciated. Just suggest me how can i deal with office files assuming ms office is not installed in my computer.
NPOI works well for Excel; I only know to use the built in, MS object library for PPT files.

Categories