Microsoft已发布Office文件的二进制规范。我需要从.Doc中提取文本。这个页面似乎意味着从Doc中提取文本并不困难,但我没有遵循。从Word Doc Binary中提取文本
这是我到目前为止所。
wIdent和wFib的值是错误的。请指出正确的方向。
UInt16 wIdent; // (2 bytes): An unsigned integer that specifies that this is a Word Binary File. This value MUST be 0xA5EC.
UInt16 wFib; // (2 bytes): An unsigned integer that specifies the version number of the file format used. Superseded by FibRgCswNew.nFibNew if it is present. This value SHOULD<13> be 0x00C1.
using (FileStream fs = File.OpenRead(fileName))
{
UTF8Encoding utf8 = new UTF8Encoding(true);
BinaryReader brFile = new BinaryReader(fs);
wIdent = brFile.ReadUInt16();
Debug.WriteLine(wIdent.ToString());
Debug.WriteLine(String.Format("{0:x}", wIdent)); // cfd0 wrong value
wFib = brFile.ReadUInt16();
Debug.WriteLine(wFib.ToString()); // 57361 wrong value
byte[] b = new byte[1024];
while (brFile.Read(b, 0, b.Length) > 0)
{
Debug.WriteLine(utf8.GetString(b));
}
}
上面显示了大部分的文字,但也有很多其他的东西。
我有通过OpenXML工作的docx。因为需要半格式化,所以不仅需要iFilter。在文本上运行一个算法来剔除不感兴趣的文档。还用于文档的快速文本,以便他们可以决定是否要下载文件和自动编码。
Office Interop不是一个选项。这是针对服务器的,Microsoft不建议在该环境中使用Office自动化。我们尝试过,并且对于我们需要处理的文档数量不稳定。
谢谢,转换文件不是一个选项,因为文件无法更改。我会看看你提出的其他选项。该msdn页面看起来很容易,但我再次甚至无法读取第一个偏移量。 – Paparazzi
在Apose网站上,他们列出了ASP.NET和Win Forms,但不包括WPF。他们不支持WPF吗?似乎很奇怪,因为文件转换不是UI。 – Paparazzi
我不认为它与UI有任何关系。我在没有任何UI的类库中使用了Apose。 – Jeremy