Word 正在尝试恢复

发布于 2024-09-14 12:50:42 字数 2950 浏览 1 评论 0原文

我们目前正在用c#程序处理大word文档。 在处理过程中,我收到消息“Microsoft Windows 已停止工作”。

该程序根据添加到文档中的注释读取Word文档,并处理文档中的图像和其他文本,并使用原始文档的内容创建许多独立的Word文档。

问题的原因是什么?这是因为Word文档的创建、打开和关闭过于频繁吗?

程序步骤: 1) 将文档中注释引用的内容复制到剪贴板

    comment.Scope.CopyAsPicture();

2) 然后将内容转换为“html”或“纯”图像

    public String _GetContentFromClipboard()
    {
        String text = "";
        if (Clipboard.GetData(DataFormats.Html) != null)
        {
            text = Clipboard.GetData(DataFormats.Html).ToString();
        }
        else
        {
            IDataObject iData = Clipboard.GetDataObject();
            if (iData.GetDataPresent(DataFormats.Bitmap))
            {
                Image image = iData.GetData(DataFormats.Bitmap, true) as Image;
                String imageFile = Guid.NewGuid().ToString() + ".jpg";
                image.Save(imageFile, System.Drawing.Imaging.ImageFormat.Jpeg);
                text = "<img src=\"" + imageFile + "\" width=\"" + image.Width + "\" height=\"" + image.Height + "\" />";
            }
        }
        return text;
    }

3) 有时也将内容从剪贴板保存到新的 Word 文档

    public String SaveClipboardContentToDoc(bool removeComments)
    {
        Object docName = GeneralUtil.GetTempFileWithoutExtension() + ".docx";
        Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();

        Microsoft.Office.Interop.Word.Document oDoc = new Microsoft.Office.Interop.Word.Document();

        oDoc = oWord.Documents.Add(ref missingObj, ref missingObj, ref missingObj, ref missingObj);
        oWord.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
        oWord.Visible = false;
        oDoc.ActiveWindow.Selection.Paste();
        if (removeComments == true)
        {
            foreach (Comment selectionComment in oDoc.Comments)
            {
                selectionComment.Delete();
            }
        }
        oDoc.SaveAs(ref docName, ref missingObj,
                    ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj,
                    ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj,
                    ref missingObj, ref missingObj, ref missingObj, ref missingObj);
        ((Microsoft.Office.Interop.Word._Document)oDoc).Close(ref missingObj, ref missingObj, ref missingObj);
        ((Microsoft.Office.Interop.Word._Application)oWord).Quit(ref missingObj, ref missingObj, ref missingObj);
        return docName.ToString();
    }

初始警告消息是

"Microsoft Windows has stopped working"
Windows can check online for a solution to the problem and try to recover your information.
Check online for a solution and close the program
close the program
Debug the program

Then clicking on debug leads to " "An unhandled win32 execption occurred in WINWORD.EXE [7372]"

We are currently processing big word documents in c# program.
During processing i am getting message "Microsoft Windows has stopped working".

The program reads the word document based on the comments added to the document and processes the images and other text in the document and also creates lot of independent word documents with content from the original document.

What is the reason for the problem? Is this because word documents are created, opened and closed so frequently?

Program Steps:
1) Copy the content referred by the comment in the doc to clipboard

    comment.Scope.CopyAsPicture();

2) Then process convert the content to "html" or "plain" image by

    public String _GetContentFromClipboard()
    {
        String text = "";
        if (Clipboard.GetData(DataFormats.Html) != null)
        {
            text = Clipboard.GetData(DataFormats.Html).ToString();
        }
        else
        {
            IDataObject iData = Clipboard.GetDataObject();
            if (iData.GetDataPresent(DataFormats.Bitmap))
            {
                Image image = iData.GetData(DataFormats.Bitmap, true) as Image;
                String imageFile = Guid.NewGuid().ToString() + ".jpg";
                image.Save(imageFile, System.Drawing.Imaging.ImageFormat.Jpeg);
                text = "<img src=\"" + imageFile + "\" width=\"" + image.Width + "\" height=\"" + image.Height + "\" />";
            }
        }
        return text;
    }

3) Also sometimes save the content from the clipboard to new word document

    public String SaveClipboardContentToDoc(bool removeComments)
    {
        Object docName = GeneralUtil.GetTempFileWithoutExtension() + ".docx";
        Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();

        Microsoft.Office.Interop.Word.Document oDoc = new Microsoft.Office.Interop.Word.Document();

        oDoc = oWord.Documents.Add(ref missingObj, ref missingObj, ref missingObj, ref missingObj);
        oWord.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
        oWord.Visible = false;
        oDoc.ActiveWindow.Selection.Paste();
        if (removeComments == true)
        {
            foreach (Comment selectionComment in oDoc.Comments)
            {
                selectionComment.Delete();
            }
        }
        oDoc.SaveAs(ref docName, ref missingObj,
                    ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj,
                    ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj,
                    ref missingObj, ref missingObj, ref missingObj, ref missingObj);
        ((Microsoft.Office.Interop.Word._Document)oDoc).Close(ref missingObj, ref missingObj, ref missingObj);
        ((Microsoft.Office.Interop.Word._Application)oWord).Quit(ref missingObj, ref missingObj, ref missingObj);
        return docName.ToString();
    }

The initial warning message is

"Microsoft Windows has stopped working"
Windows can check online for a solution to the problem and try to recover your information.
Check online for a solution and close the program
close the program
Debug the program

Then clicking on debug leads to " "An unhandled win32 execption occurred in WINWORD.EXE [7372]"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸵鸟症 2024-09-21 12:50:42

好吧,你的代码轰炸了Word。这并不常见,但 Word 是一个相当大的野兽,可能包含数千个尚未发现的错误。您不会从异常本身获得任何帮助,它发生在核心代码内部。即使您确实拥有 Word 的源代码,您可能仍然需要花费大量时间才能找出到底出了什么问题。

支持Word,您可以致电Microsoft 支持。当您完成外部支持层后,您最终会得到一位支持工程师来解决您的问题,该工程师非常了解 Word 并且可以诊断原因。为了穿过这些外层,拥有良好的重现非常重要。可以在任何机器上引发此崩溃的最简单的程序。收到后,准备好信用卡并给他们打电话。他们会给您一个用于上传重现代码的 URL。当您的案件涉及支持级别时,请务必与他们保持联系,您需要主动确保他们继续关注案件。如果需要全部完成,预计需要几周的时间。如果他们确定这是 Word 中的错误而不是您的代码中的错误,您将获得退款。

Fwiw,努力获得简单的重现通常是找出代码有什么问题(如果有的话)的好方法。祝你好运。

Well, your code bombed Word. That doesn't happy very often, but Word is rather a large beast and probably contains thousands of bugs that haven't been found yet. You'll get no help from the exception itself, it happens inside the core code. Even if you did have the source code for Word, you'd probably still have a helluva time finding out exactly what went wrong.

Word is supported, you can call Microsoft Support. After you went through the outer support layers, you'll eventually get a support engineer assigned to your problem that knows Word well and can diagnose the cause. To get through those outer layers, it is very important that you have a good repro available. The simplest program that can trip this crash on any machine. Once you got that, have your credit card ready and call them. They'll give you a URL to upload your repro code. Be sure to stay in touch with them as your case traverses the support levels, you need to be proactive to ensure they stay on the case. Count on several weeks if it needs to get all the way. You'll get your money back if they determine it is a bug in Word instead of your code.

Fwiw, working on getting the simple repro is usually a good way to find out what, if anything, is wrong with your code. Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文