简体   繁体   English

在C#生成中调试损坏的OpenXML Word文档的最佳实践

[英]Best practices to debug broken OpenXML word document in C# generation

I'm generating a MS Word document with OpenXml package in C#. 我正在使用C#中的OpenXml包生成一个MS Word文档。 Many times I've seen this erorr message: 很多次我看到这个错误信息:

无法打开文件.docx,因为内容存在问题

This error message is pretty useless: all it says the problem is in footer. 这个错误信息是无用的:所有它说问题是在页脚中。 Most of the times it says the error is on line 1, char 1. 大多数时候它说错误在第1行,char 1。

I usually find the problem, but it takes too much time by going back and forth. 我经常发现问题,但来回走动需要花费太多时间。

Are there any tools/techniques that can help with debugging such errors? 是否有任何工具/技术可以帮助调试此类错误? Show a better error, like you are trying to add a Text outwith of a Run, or something like that? 显示一个更好的错误,就像你试图添加一个运行的文本,或类似的东西?

After poking a bit more online, I found tools that eased the pain. 在网上戳了一下之后,我发现了减轻痛苦的工具。 Even made a blog post about it: http://tech.trailmax.info/2014/04/validating-of-openxml-generated-documents-or-the-file-cannot-be-opened-because-there-are-problems-with-contents/ 甚至发了一篇关于它的博客文章: http//tech.trailmax.info/2014/04/validating-of-openxml-generated-documents-or-the-file-cannot-be-opened-because-there-are-问题与-内容/

The basics are here: 基础知识在这里:

  1. There is OpenXmlValidator class. OpenXmlValidator类。 Use it like this: http://msdn.microsoft.com/en-us/library/office/bb497334%28v=office.15%29.aspx 像这样使用它: http//msdn.microsoft.com/en-us/library/office/bb497334%28v=office.15%29.aspx
  2. There is Open Xml Package Explorer - use it for manual tweaking of your stuff and slightly better error messages. Open Xml Package Explorer - 用它来手动调整你的东西和更好的错误信息。

If you know other(better) ways, please let me know! 如果您了解其他(更好)的方式,请告诉我们!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM