I am using Microsoft Office Interop to open Excel files. The file is placed in a special folder from where it the Workbook code reads the file. Now, the requirement is that the Excel file can be placed anywhere. I believe the best approach is to attach the Excel file as an embedded resource. But if I attach as embedded resource how will I read the file using Excel workbook.
_excelapplication.Workbooks.Open(Filename: pExcelTemplatePath);
What is the best way to read the excel template file regardless of the location of the file?
You can't open it directly from the embedded resources - at least not with Interop...
You will need to save it somewhere as a file - i.e. first read it from the resource (for example by Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceNameOfEmbeddedExcelFile)
) and then write that stream to some location like ApplicationData
/ CommonApplicationData
/ LocalApplicationData
/ MyDocuments
/ CommonDocuments
from Environment.SpecialFolder
Another option would be to use a library capable of opening/editing Excel files from a stream - let me know if you need some links to libraries...