Vin*_*des 5 c# asp.net openoffice.org ms-office office-interop
我有一个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,它就可以完美运行.
为确保权限不会出现任何问题,服务器中的每个人都可以完全访问该网站.该网站在IIS7和经典模式下运行.
我还听说Open-office有一个能够做到这一点的API,但是我找不到任何关于它的东西.我不介意使用DLLImport做我必须做的事情,我可以在Web服务器上安装open-office.不要担心重写这个方法,只要参数相同,一切都会起作用.
我感谢您的帮助.
小智 10
不要从ASP.NET应用程序使用Office Interop.请参阅Office的服务器端自动化的注意事项.
但是,如果您没有其他选择,则需要在Windows Server 2008上创建以下目录以使其工作:
Windows 2008 Server x64:C:\ Windows\SysWOW64\config\systemprofile\Desktop Windows 2008 Server x86:C:\ Windows\System32\config\systemprofile\Desktop
Interop 库要求将相关应用程序安装在运行它们的计算机上。即,为了使其在您的生产服务器上运行,您需要在该服务器上安装 Office。这通常是一个糟糕的主意。设置类型存在许多问题,因为每次有人发出请求时,都会启动相关应用程序的新实例(在您的情况下为 PowerPoint)。
如果您想在中央服务器上解析 PowerPoint 文件,那么您应该使用读取 PowerPoint 文件的库。我知道Aspose生产此类产品(Aspose.Slides),但还有其他产品。
如果文档位于 PowerPoint 2007 中,您也许能够解析 Open Office XML 以获取所需的数据。有关详细信息,请参阅 Office (2007) Open XML 文件格式简介和Open XML SDK 2.0 for Microsoft Office 。
| 归档时间: |
|
| 查看次数: |
10058 次 |
| 最近记录: |