amr*_*ama 2 .net c# powerpoint visual-studio
当然Embed interop类型功能是一件好事,但即使在简单的场景中也无法让它与我合作,所以请建议这是我在没有安装powerPoint的机器上运行我的项目时得到的错误:

我的代码非常简单我只是从powerPoint创建对象,创建演示文稿并在其中滑动写入内容.
我嵌入的库是Office和Microsoft.Office.Interop.PowerPoint
将构建配置转换为x68并没有解决它,
我正在构建Windows应用程序并按下单击按钮,如下所示:
private void button1_Click(object sender, EventArgs e)
{
var pp = new powerpoint.Application();
var oPres=pp.Presentations;
pp.Visible = Office.MsoTriState.msoTrue;
powerpoint.Presentation oPre= oPres.Add(Office.MsoTriState.msoTrue);
powerpoint.Slides oSlides = oPre.Slides;
powerpoint.Slide oSlide = oSlides.Add(1, powerpoint.PpSlideLayout.ppLayoutText);
powerpoint.Shapes oShapes = oSlide.Shapes;
powerpoint.Shape oShape = oShapes[1];
powerpoint.TextFrame oTxtFrame = oShape.TextFrame;
powerpoint.TextRange oTxtRange = oTxtFrame.TextRange;
oTxtRange.Text = "All-In-One Code Framework";
string fileName = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location) + "\\Sample1.pptx";
oPre.SaveAs(fileName,
powerpoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation,
Office.MsoTriState.msoTriStateMixed);
oPre.Close();
pp.Quit();
pp = null;
}
Run Code Online (Sandbox Code Playgroud)
在顶部,我补充说
using powerpoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
using System.IO;
using System.Reflection;
Run Code Online (Sandbox Code Playgroud)
注意:程序在我安装Office 2013的时候工作正常,但是这个错误出现在我的客户端电脑上
如前所述,问题是客户端计算机上没有安装Powerpoint.
powerpoint对象在COM类型库中实现,并在安装Powerpoint时进行安装和注册.COM和.NET是完全不同的技术.要从.NET应用程序中使用COM类型,不要直接使用COM类型,而是使用特殊的互操作.NET程序集.这个程序集不包含任何PPT功能,它只是一个包装器,可以作为.NET应用程序和COM类型之间的桥梁.互操作程序集为您完成所有艰苦工作,并定义可用作其他.NET类的.NET类型(来自COM类型),例如powerpoint.Application.
互操作程序集只是一个普通的.NET程序集.您可以将其引用为其他.NET引用(Embed Interop Types = false).在这种情况下,您需要与您的应用程序一起分发互操作DLL.如果设置Embed Interop Types = true,则会编译互操作程序集并将其直接嵌入到应用程序程序集中.而且,只嵌入了真正使用的类型和功能.因此,使用此选项具有优化和单组装的优势.
但是,即使在嵌入时,互操作信息也只是必须安装在客户端计算机上的真实COM类型的包装器.如果不是,则会收到错误.有关详细信息,请访问https://msdn.microsoft.com/en-us/library/xwzy44e4.aspx
您可以选择强制客户端安装PPT或避免使用Microsoft.Office.Interop.PowerPoint并使用可以随应用程序分发的某些第三方PPT库.
| 归档时间: |
|
| 查看次数: |
2378 次 |
| 最近记录: |