zoukankan      html  css  js  c++  java
  • 去掉vsto生成的任务窗格

    使用vsto对office进行二次开发时,一般会自定义任务窗格!但有时我们并不需要在打开office时都带上任务窗格。而且对于一些外部用户(没有安装office二次开发产品的用户),打开同样的文档时会弹出烦人的提示窗口。那么如何将任务窗格跟office分离呢?

    在需要的地方加上,以下代码:

    if (ServerDocument.GetCustomizationVersion(targetfilepath) == 3) ServerDocument.RemoveCustomization(targetfilepath);

    使用上面的代码要引用

    using Microsoft.VisualStudio.Tools.Applications;如下图

    注意版本

    然后再次打开保存过的文档,会发现任务窗格已经没有了!!!

    下面的是我的一个例子,我在vs2010中新建了一个“excel模板”项目,在任务窗格中添加了一个按钮,用来自定义“另存为”功能,但是用户要求是另存为后,只想看到office文档,不要任务窗格。所以有代码如下:

            private void btnSaveAs_Click(object sender, EventArgs e)
            {
                try {
                    string targetfilepath = @"D:\学习\DesignPattern\练习\WinformTest\ExcelTemplateTest\ExcelTemplateTest14.xlsx";
                    Globals.ThisWorkbook.SaveCopyAs(targetfilepath);
                    if (ServerDocument.GetCustomizationVersion(targetfilepath) == 3) ServerDocument.RemoveCustomization(targetfilepath);
                }
                catch (Exception ex) { throw ex; }
                finally {
                    Globals.ThisWorkbook.ThisApplication.UserControl = true;
                    Globals.ThisWorkbook.Close();
                    Globals.ThisWorkbook.ThisApplication.Quit();
                }
            }
  • 相关阅读:
    enum:python实现枚举也很优雅
    jieba:我虽然结巴,但是我会分词啊
    pyquery:轻松、灵活的处理html
    lxml:底层C语言实现、高效地处理html
    shelve:极其强大的序列化模块
    Session管理之ThreadLocal
    Hibernate之Criteria
    Hibernate之list和iterator
    hibernate之createQuery与createSQLQuery
    C标签之forEach
  • 原文地址:https://www.cnblogs.com/jjhe369/p/2195806.html
Copyright © 2011-2022 走看看