【问题标题】:Append Pub file to other MS Publisher 2010 file with PowerShell使用 PowerShell 将 Pub 文件附加到其他 MS Publisher 2010 文件
【发布时间】:2013-11-26 00:57:06
【问题描述】:

在 MS Publisher 2010 中,您可以将 PUB 文件(将模板与来自 Excel 文件的数据合并的目录出版物)添加到现有 pub 文件的末尾。 编写目录书非常方便。我可以使用 Publisher 用户界面手动完成,我想自动执行此任务(共有 26 章)。

不幸的是,我找不到自动化功能,也不是一个简单的例子。 有人可以帮助我完成这项任务的一些自动化示例吗?

谢谢,

【问题讨论】:

    标签: powershell office-automation publisher ms-publisher


    【解决方案1】:

    您可以使用 PowerShell 访问 Publisher 互操作库吗?

    如果是这样,我会这样做(未经测试的 C#,但如果你在 MSDN's Publisher VBA reference 中阅读它,它应该会让你知道如何去做):

    Publisher.Application firstPubApp = new Publisher.Application(); //open a new publisher instance
    Publisher.Document sourcePublication = firstPubApp.Open("sourcefile.pub"); //open your publisher document
    
    Publisher.Application otherPubApp = new Publisher.Application();
    Publisher.Document targetPublication = otherPubApp.Open("targetfile.pub");
    targetPublication.Pages.Add(1, 1); //add one page after page 1
    
    foreach (Publisher.Shape shape in sourcePublication.Pages[1].Shapes) //loop through all pages on page 1
    {
        shape.Copy(); //copy the shape
        otherPubApp.ActiveDocument.Pages[2].Shapes.Paste(); //paste it in the other document
    }
    

    很可能比循环遍历所有页面上的所有形状更好的方法隐藏在该文档的某个地方。与 Excel 或 Word 相比,Publisher 的示例总是很难找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-25
      • 1970-01-01
      • 2011-11-06
      • 2020-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多