Accessing an excel Project from A Winform Project in same Solution - c#

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

Related

Can I build the vsto project in excel file

I have faced the following problem: if I write an extension in Visual Studio for Excel file, it saves as the .vsto file in the same location and then uploads in the Excel file on run. But I need .vsto file to be automatically uploaded, when the Excel file starts to execute, and not visible to a person, to whom I will pass the excel file.
Is there any way to do this? I want to place USB-key checking code in the VSTO workbook project (Excel file will be unprotected and opened only if there is a USB-key in the USB-port)
In case you need further clarifications, please do not hesitate to ask in this thread
There is no support in VSTO for embedding your code inside an Excel workbook.
The easiest way of embedding code in a workbook is by using VBA.
Otherwise you would need to find a way of forcing your VSTO code and the workbook to be in the same location.

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);

Resources folder in Visual Studio

I write you all for a problem with my c# library. It needs an XML file that uses as a dictionary. Since the files will not change I would like the dll already contained the file and requires no memory references to it.
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(#G:\Project\dictionary.xml");
So I put the XML file in the "Resources" folder of visual studio, but now I do not know how to get that file. If you always use the memory reference to use the library without also enter the file, it does not work. How can I do? If I open the dll with a notepad I see that the XML file is in.
This should give you an idea:
add a *.resx file
drag and drop you XML File onto it.
Use it!

Read file from Application folder while publishing a Click Once application C#

I have an application in C# where I have to select a file and process it. I use Visual Studio's Publish option to generate a Click Once application . But if I want to bundle the file along with the application and set it as default instead of Open File dialog, where should I place the file? The file is an Excel file
first create a folder to hold your custom files in the project,put your excel file inside that folder using add as link in the dialog box.Mark all files as Copy if newer (Copy to output directory property)and just make sure your build action is content.
Thats it..
for more reference
Source 1
Source 2

How to programmatically load an XLL file into Excel?

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 :(

Categories