How to get Excel Template path from VSTO project

大兔子大兔子 提交于 2019-12-10 10:26:48

问题


I am working on a VSTO Excel 2010 Macro Enabled Template Project, that I plan to packaged with various other file/content/resources and installed (WiX toolset) onto the target machine.

It is intended that the user will click on a shortcut (e.g. from desktop) to the Excel Template, fire up Excel with the add-ins and then work from there. I also have some dotx reports in the installation directory that is to be triggered by VSTO Ribbon Button.

Question is, how can I find out the installation directory from the VSTO Ribbon button?

Since the new Excel Workbook came from an Excel Template, would be good if there is something like ThisWorkbook.Template.Path.

EDIT: I realize there are two parts to this question, the first part is answered here while the second needs clarification:

Suppose I have a template document mytemplate.xltm in C:\templates. I then double click on the file to open up Excel and a "New Workbook" is created by default from the file. Now how can I get back the path "C:\templates" from the "New Workbook"? I want to know where the file mytemplatex.xltm or better still, which file produced "New Workbook" from.

The answer to this question should give me "C\templates\mytemplate.xltm" in C# VSTO/Interop. Thanks.


回答1:


Are you behind this Globals.ThisAddIn.Application.TemplatesPath?




回答2:


InstallLocation = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);


来源:https://stackoverflow.com/questions/9799971/how-to-get-excel-template-path-from-vsto-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!