我有一个ASP.NET 2.0的Web应用程序,应该上传一个PPT文件,然后将其幻灯片提取到图像。对于我已经进口office.dll和Microsoft.Office.Interop.PowerPoint.dll组件和写了下面的代码asp.net中的办公自动化问题。我可以使用替代办法,如开放式办公室,如果我知道如何
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;
}
如果我运行我的本地机器的代码,在asp.net或可执行文件,它完美运行。但如果我尝试在生产服务器上运行它,我得到以下错误:
System.Runtime.InteropServices.COMException (0x80004005): PowerPoint could not open the file. at 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, Int32 alturaThumb, Boolean geraXml) at Upload.ProcessRequest(HttpContext context)
的过程与用户NT AUTHORITY \ NETWORK SERVICE运行。 IIS被配置为使用匿名身份验证。匿名用户是一名管理员,我这样设置允许应用程序运行而不必担心权限。
在我的开发机器中,我有Office 2010 beta1。我已经用Office 2007中的可执行文件进行了测试。如果我从服务器中的可执行文件运行代码,并安装了Office 2003,它可以完美运行。
为确保权限不会出现任何问题,服务器中的每个人都可以完全访问该网站。该网站在IIS7和经典模式下运行。
我也听说Open-office有一个应该可以做到这一点的API,但是我找不到任何关于它的东西。我不介意使用DLLImport来做我必须做的事情,我可以在Web服务器上安装open-office。不要担心重写这个方法,只要参数是一样的,一切都会工作。
我感谢您的帮助。
永远不要从ASP.NET应用程序使用Office Interop。请参阅[有关办公室服务器端自动化的注意事项](http://support.microsoft.com/kb/257757) – 2011-10-06 02:52:05