从命令行编译 MS Office 互操作应用程序

发布于 2024-07-26 11:04:27 字数 900 浏览 2 评论 0原文

我如何使用 csc.exe 从命令行成功编译此代码,就我应该引用哪个 dll 而言。 我希望它能够与 Office 2007 和 Office 2003 一起使用。

我使用 .Net Framework SDK 2.0。

我收到此编译错误:

(2,37):错误 CS0234:命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(您是否缺少程序集引用?)

源代码:

using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

 namespace PPInterop
 {
 class Program
 {
    static void Main(string[] args)
    {
            PowerPoint.Application app = new PowerPoint.Application();
            PowerPoint.Presentations pres = app.Presentations;
            PowerPoint._Presentation file = pres.Open(@"C:\project\JavaTut1.ppt", MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
            file.SaveCopyAs(@"C:\project\presentation1.jpg", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
    }
  }
 }

how do I successfully compile this code from the commandline, using csc.exe, in terms of which dll's I should reference. I would like this to work with Office 2007 as well as Office 2003.

I am use .Net Framework SDK 2.0.

I get this compilation error:

(2,37): error CS0234: The type or namespace name 'Interop' does not exist in the namespace 'Microsoft.Office' (are you missing an assembly reference?)

Source code:

using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

 namespace PPInterop
 {
 class Program
 {
    static void Main(string[] args)
    {
            PowerPoint.Application app = new PowerPoint.Application();
            PowerPoint.Presentations pres = app.Presentations;
            PowerPoint._Presentation file = pres.Open(@"C:\project\JavaTut1.ppt", MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
            file.SaveCopyAs(@"C:\project\presentation1.jpg", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
    }
  }
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凶凌 2024-08-02 11:04:27

您需要找到实现您引用的接口的 dll 的路径,然后查看 csc.exe 的命令行参数以了解如何将这些引用添加到您的命令中。

You need to find the paths to the dlls implementing the interfaces you reference, then look at the command-line parameters for csc.exe to learn how to add those references into your command.

弥繁 2024-08-02 11:04:27

您需要包含 Microsoft.Office.Interop.PowerPoint 路径应类似于:
C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.PowerPoint.dll for 07 并用 Office11 替换 Office12 for 03 我相信

You need to include Microsoft.Office.Interop.PowerPoint the path should be something like:
C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.PowerPoint.dll for 07 and replace Office12 with Office11 for 03 I believe

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文