0
votes

I have a Visual Studio solution that contains two projects (1) a C# console application; and (2) a C# Excel Workbook.

The console application creates some data, which I would then like to pass into the workbook.

To do this I have created a method in the Excel workbook project, which receives data from the console application. However, I cannot create an instance of the Excel book. At the moment I am trying:

Excel.Application excelApplication = new Excel.Application(); Excel.Workbook excelWorkBook = excelApplication.Workbooks.Add("MyBook.xls");

I could hard code the path to the xls file, but I don't really want to do this as I would prefer to wrap everything up into a single .exe

Any ideas?

1

1 Answers

1
votes

So basically what you're asking is how to wrap two files (an exe and an excel file), into a single exe.

There is a simple (and fairly clumsy) way of doing this which revolves around using Resources in C#, meaning your program will have to do something similar to the following:

  1. Take excel file source out of Resources, and write it to a file when the program is run (temporary file)
  2. Use the Current Directory + excel temp file name to feed into the Worksheet.Add method
  3. Once edited, store the temporary file's data back into the Resources of your exe.

Another possibility would be, instead of using a temporary file, read a stream of bytes directly into Worksheets.Add if this is supported by the API (feel free to tell me if this is so).

EDIT: Great tutorial on using resources in C#.