验证 Word 2007 模板文件

发布于 2024-07-25 10:28:09 字数 379 浏览 1 评论 0原文

我正在开发一个解决方案,允许人们上传 DOCX 文件作为模板。 该模板用于生成带有数据库信息的Word文档。

我想做的是一旦模板上传,检查它是否有错误。 (我不希望我的解析器在使用模板时崩溃。)

我看到了有关 检查 Word 模板的签名,但这不足以验证文件的完整性。 当然,可以尝试解压缩文件,验证其中的 XML,等等,但这相当耗费 CPU 资源,如果有的话,我希望有一种不同的方法。

是否有属于 Open XML SDK 一部分的解决方案或其他标准方法? 任何想法都会受到赞赏。

I'm developing a solution that allows people to upload a DOCX file as a template. This template is used for generating Word documents with database info.

What I would like to do is once a template gets uploaded, to check it for errors. (I don't want my parser crashing when a template is used.)

I've seen the question about checking a signature of a Word template, but that isn't enough to validate the integrity of the file. Of course it is possible to try to unzip the file, validate the XML in there, and so on, but this is rather CPU intensive and I'd like a different approach if there is one.

Are there any solutions that are part of the Open XML SDK or other standard approaches to this? Any ideas are apreciated.

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

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

发布评论

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

评论(1

玩套路吗 2024-08-01 10:28:09

在 C# 中 MSDN 站点

public static bool IsDocumentValid(WordprocessingDocument mydoc)
{
    OpenXmlValidator validator = new OpenXmlValidator();
    var errors = validator.Validate(mydoc);
    foreach (ValidationErrorInfo error in errors)
        Debug.Write(error.Description);
    return (errors.Count() == 0);
}

in C# off the MSDN site

public static bool IsDocumentValid(WordprocessingDocument mydoc)
{
    OpenXmlValidator validator = new OpenXmlValidator();
    var errors = validator.Validate(mydoc);
    foreach (ValidationErrorInfo error in errors)
        Debug.Write(error.Description);
    return (errors.Count() == 0);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文