我有一个ASP.NET 2.0 Web应用程序,应该上传一个ppt文件,然后将其幻灯片提取到图像.为此我导入了office.dll和Microsoft.Office.Interop.PowerPoint.dll程序集并编写了以下代码
public static int ExtractImages(string ppt, string targetPath, int width, int height)
{
var pptApplication = new ApplicationClass();
var pptPresentation = pptApplication.Presentations.Open(ppt, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
var slides = new List<string>();
for (var i = 1; i <= pptPresentation.Slides.Count; i++)
{
var target = string.Format(targetPath, i);
pptPresentation.Slides[i].Export(target, "jpg", width, height);
slides.Add(new FileInfo(target).Name);
}
pptPresentation.Close();
return slides.Count;
}
Run Code Online (Sandbox Code Playgroud)
如果我在本地机器,asp.net或可执行文件中运行此代码,它运行完美.但是,如果我尝试在生产服务器中运行它,我会收到以下错误:
System.Runtime.InteropServices.COMException(0x80004005):PowerPoint无法打开该文件.在Microsoft.Office.Interop.PowerPoint.Presentations.Open(String FileName,MsoTriState ReadOnly,MsoTriState Untitled,MsoTriState WithWindow)at PPTImageExtractor.PptConversor.ExtractImages(String caminhoPpt,String caminhoDestino,Int32 largura,Int32 altura,String caminhoThumbs,Int32 larguraThumb,上传.ProcessRequest(HttpContext上下文)中的Int32 alturaThumb,Boolean geraXml)
该过程与用户NT AUTHORITY\NETWORK SERVICE一起运行.IIS配置为使用匿名身份验证.匿名用户是管理员,我将其设置为允许应用程序运行而不必担心权限.
在我的开发机器上,我有办公室2010 beta1.我已经在Office 2007的pc中测试了可执行文件.如果我从服务器中的可执行文件运行代码,安装了Office 2003,它就可以完美运行. …