检查Word模板文件 [英] Check word template file

查看:397
本文介绍了检查Word模板文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查Word模板文件。它可以使用扩展的.dot或.DOTX进行检查。 但是,如果用户更改为.txt为.DOT。它怎么能确定??

How can I check a word template file. It can be checked using the extension .dot or .dotx. But if the user changed a .txt to .dot. How could it identified??

推荐答案

要检查一个DOTX文件(实际上是一个zip文件),确认头:

To check for a dotx file (which is actually a zip file), check the header:

0000000: 504b 0304 1400 0000 0800 95a1 3435 4a07  PK..........45J.

前四个字节分别量0x050 0x4b 0×03 0×04。这将证明,如果一个文件是一个压缩文件(所以不一定是DOTX),如果你想进一步检查你需要解压整个缓冲区并解析生成的XML。

First four bytes are 0x050 0x4b 0x03 0x04. This will demonstrate if a file is a zip file (so not necessarily a dotx), if you wanted to checked further your would need to unzip the entire buffer and parse the resulting XML.

要检查点文件(pre 2007),检查标题:

To check for a dot file (pre 2007), check the header:

0000000: d0cf 11e0 a1b1 1ae1 0000 0000 0000 0000  ................

前八个字节0xd0 0xcf为0x11 0xe0的0xa1 0xb1 0x1A的0xe1

First eight bytes 0xd0 0xcf 0x11 0xe0 0xa1 0xb1 0x1a 0xe1

因此​​,对于这两种情况下,以二进制方式打开文件,读取前八个字节和比较。

So for either of these cases, open the file in binary mode, read the first eight bytes and compare.

这篇关于检查Word模板文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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