我正在尝试将一些Word文档转换为swf文件的代码。
我是这样做的:
我是在我的计算机上完成的(64位,Windows Server 2008 R2,Office 2010)并且工作正常,但是当我把它放在服务器(64位,Windows Server 2008 R2,Office2010)中时,“保存”由于'对话框将显示代码试图在程序中关闭Word时,以及我是否单击'保存'或'取消',它将抛出异常'文件是只读'。但实际上,我没有更改原始文件,我只是打开它并将其保存为PDF文档。
以下是“将Word转换为PDF”代码:
bool ret = true;
Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = null;
object Unknown = Type.Missing;
try
{
object Source = path;
object Target = path.Substring(0, path.LastIndexOf(".")) + ".pdf";
if (outpath != "")
Target = outpath;
object readOnly = true;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
doc = newApp.Documents.Open(ref Source, ref Unknown, ref readOnly,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
doc.SaveAs(ref Target, ref format,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
}
catch (Exception e)
{
ret = false;
}
finally
{
if (doc != null)
{
doc.Close(ref Unknown, ref Unknown, ref Unknown);
//dialog shows up here
}
newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
GC.Collect();
}
return ret;
有什么建议吗?
答案 0 :(得分:4)