如何从VSTO项目获取Excel模板路径 [英] How to get Excel Template path from VSTO project
问题描述
用户将点击快捷方式(例如从桌面)到Excel模板,使用加载项启动Excel,然后从那里工作。我还在安装目录中有一些由VSTO Ribbon Button触发的dotx报告。
问题是,我如何从VSTO功能区中找到安装目录按钮?
由于新的Excel工作簿来自Excel模板,如果有类似ThisWorkbook.Template.Path的东西会很好。
编辑:我知道这个问题有两个部分,第一部分回答了这里,而第二个需要澄清:
假设我有一个模板文件mytemplate.xltm在C:\templates。然后双击该文件打开Excel,并从文件默认创建一个新建工作簿。现在我如何从新工作簿中获取路径C:\templates?我想知道文件mytemplatex.xltm或更好的文件,哪个文件生成新工作簿。
这个问题的答案应该是给我C \ C#VSTO / Interop中的templates\mytemplate.xltm。谢谢。
InstallLocation = Path.GetDirectoryName(new Uri(System.Reflection.Assembly 。.GetExecutingAssembly()基本代码).LocalPath);
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.
InstallLocation = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);
这篇关于如何从VSTO项目获取Excel模板路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!