office文件转pdf出现的奇怪异常,忘大侠帮帮我
各位大侠,你们好,我目前用微软的offce2007的组件转换office文件到pdf,其中出现下面的异常,忘高手帮帮偶.谢谢!
以下是转换代码:
word:
Microsoft.Office.Interop.Word._Application oWord;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
//oWord.Visible = true;
oDoc = oWord.Documents.Open(ref tempFileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
try
{
savePath = driverPath + "\\" + mediaName + "\\" + pathName + "\\";
if (!Directory.Exists(savePath.ToString()))
{
Directory.CreateDirectory(savePath.ToString());
}
savePath = savePath + strFileName + "." + astdt;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
oDoc.SaveAs(ref savePath, ref format,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.Close(ref flg, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
}
excel:
book.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
savePath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
(限于长度,只贴出出错的那一句,前面代码的跟转换word的类似。)
powerpoint:
ppApp.Presentations[ppApp.Presentations.Count].SaveAs(savePath.ToString(), Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF, Microsoft.Office.Core.MsoTriState.msoTrue);
(限于长度,只贴出出错的那一句,前面代码的跟转换word的类似。)
以下是异常信息:
转换Word:
System.Runtime.InteropServices.COMException (0x800A1066): Command failed。
转换Excel:
它先弹出一对话框,对话框内容是“Document not saved. The document may be open, or an error may have been encountered when saving.”。
异常是:System.Runtime.InteropServices.COMException (0x800A03EC): HRESULT からの例外: 0x800A03EC。
转换Powerpoint:
System.Runtime.InteropServices.COMException (0x80004005): Presentation (unknown member) : An error occurred while PowerPoint was saving the file.
程序是B/S的,转换的代码是在WebService上执行的。在以前转换失败也就是网络超时或者其他的,没出现过这种错误。
这个错在我本机执行源代码时才出现。如果用发布的版本执行,目前没有出现此类错误。(以前在我本机上也没出现错误)
我的环境。VS2005。安装了SaveAsPdf和office2007。
我在网上搜索了两天,还没找到解决办法,望高手救救我。谢谢
我只有20分,我是新人,希望大侠们不要看中分数,谢谢