如何编程判断一个word文档被破坏? [英] How to programatically tell if a word document is corrupt?

查看:407
本文介绍了如何编程判断一个word文档被破坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小C#应用程序与Word转换一堆字.doc文件到TEXTFILES互操作性展示,并在大多数情况下能正常工作。

I've got a little C# application that interops with word converting a bunch of word .doc files into textfiles and for the most part this works fine.

不过,如果该文件是currupt则Word无法打开该文件,一个弹出对话框,这意味着我不能完全自动完成这一转换过程 - 有人观看的对话。

However, if the document is currupt then word cannot open the file and a dialog box pops up, which means that I cannot fully automate this conversion process - someone has to watch for the dialogs.

有没有一种方法来测试,如果一个字的.doc是currupt,不打开呢?也许通过文字互操作或者通过第三方的工具。

Is there a way to test if a word .doc is currupt, without opening it? Perhaps through word interop or maybe through a 3rd party tool.

一个想法我已经是产生一个线程执行转换并杀死它,如果这个过程是开放的时间超过n秒,但我想知道是否有一个更简单的方法?

One idea I've had is to spawn a thread that does the conversion and kill it if the process is open for longer than n seconds, but I was wondering if there was a simpler way?

推荐答案

唯一可靠的方式来确定是否会认为该文件已损坏是让Word中打开它: - )。我不认为任何第三方应用程序将在这方面100%可靠的 - 毕竟,文件可能会在事实上的没有的是腐败的,但这并不能帮助你如果Word认为它的。但是,显然有一些情况可以检测,如该文件是零大小或诸如此​​类

The only sure-fire way to determine whether Word will think that the file is corrupt is to get Word to open it :-). I don't think any 3rd-party application would be 100% reliable in this regard - after all, the document might in fact not be corrupt, but that doesn't help you if Word thinks that it is. However, clearly there are some situations you could detect, such as the file being zero-sized or suchlike.

我不遇到很多(任何?)损坏的文件,所以我不知道你看到的损坏可能会按照你可以发现一个模式?例如,在这些文件从某处,通常缺少文件或东西的后半部分下载?

I don't come across many (any?) corrupt documents, so I do wonder if the corruption you're seeing might follow a pattern that you can detect? For example, are these documents downloaded from somewhere and usually missing the latter part of the file or something?

在任何情况下,一个损坏的文件是不是这个词可能会弹出一个对话框,唯一的原因。其他原因包括:

In any case, a corrupt file is not the only reason that Word might pop up a dialog box. Other reasons include:

  • 在该文件的密码保护
  • 该文件包含链接到其他文件
  • 在该文件中包含宏(其本身可弹出对话框,或者可能导致安全警告对话框出现)

您可以规避一些使用Application.DisplayAlerts的等,但不是所有的(特别是安全警告)。

You can circumvent some of these using Application.DisplayAlerts, etc. but not all (especially the security warning).

我已经使用该检测由办公室和(对于那些能够识别)presses适当的按钮拥有对话框第2线程一些成功。它几乎没有优雅,但它的工作。是的,我的第二个线程也将终止该应用程序,如果时间过长过执行特定的操作。

I've had some success with using a 2nd thread that detects dialogs owned by Office and (for those that it recognizes) presses an appropriate button. It's hardly elegant, but it does work. And yes, my 2nd thread will also terminate the application if it takes too long to perform certain operations too.

这篇关于如何编程判断一个word文档被破坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆