Microsoft Word文档打开在服务器上挂起,但可以在开发中使用

时间:2019-05-21 10:05:26

标签: c# ms-word interop

我正在使用c#编写Web服务来替换单词书签。

以下代码在开发中可用,但在Windows Server中不可用。

无法在下一行打开单词

Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref CopyOfTemplate, ref confirmConversions, ref readOnly, ref addToRecentFiles, ref passwordDoc, ref passwordTemplate, ref revert, ref writepwdoc, ref writepwTemplate, ref format, ref encoding, ref visible, ref openRepair, ref docDirection, ref notEncoding, ref xmlTransform);

两种环境下的Word版本均为2013。

在服务器中,我看到任务上已启动的单词处理过程,但它冻结了。 CPU 0%。

Microsoft.Office.Interop.Word._Application wordApp = new Microsoft.Office.Interop.Word.Application();

                wordApp.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsMessageBox;

                // wordApp.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

                wordApp.Visible = true;
                object confirmConversions = Type.Missing; object readOnly = Type.Missing; object addToRecentFiles = Type.Missing; object passwordDoc = Type.Missing; object passwordTemplate = Type.Missing; object revert = Type.Missing; object writepwdoc = Type.Missing; object writepwTemplate = Type.Missing; object format = Type.Missing; object encoding = Type.Missing; object visible = Type.Missing;
                object openRepair = Type.Missing;
                object docDirection = Type.Missing; object notEncoding = Type.Missing; object xmlTransform = Type.Missing;

                if (!File.Exists(CopyOfTemplate.ToString()))
                {
                    throw new Exception("template does not exists ");
                }
                File.AppendAllText(Path.Combine(Settings.RealFilePath, "log.txt"), "\r\n before open;CopyOfTemplate="+ CopyOfTemplate);




                Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref CopyOfTemplate, ref confirmConversions, ref readOnly, ref addToRecentFiles, ref passwordDoc, ref passwordTemplate, ref revert, ref writepwdoc, ref writepwTemplate, ref format, ref encoding, ref visible, ref openRepair, ref docDirection, ref notEncoding, ref xmlTransform);

0 个答案:

没有答案