是否有任何Objective-C库来解析/读取Word文档? [英] any objective-c library to parse/read word documents?

查看:59
本文介绍了是否有任何Objective-C库来解析/读取Word文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在iphone中阅读Microsoft Word文档

想知道是否可以使用某种objC库来解析/读取Word文档,以便我可以将其转换为txt文件以进行更多数据处理.

wondering if there is some sort of objC library that I could use for parsing/reading word documents so i can convert it to txt files for more data processing.

推荐答案

如果您从Word文档中所需的只是纯文本,那很容易.

If all you need from a Word document is the plain text, that's pretty easy.

假设您有一个NSData,其中填充了Word .doc中的数据...

Assume you have an NSData filled with data from a Word .doc...

从数据的字节索引536处读取UInt32.此数字加512是文本开始的字节索引.(通常从2048开始,但并非总是如此.)

Read a UInt32 from the data, at byte index 536. This number, plus 512, is the byte index where the text starts. (It usually starts at 2048, but not always.)

从数据中的字节索引588读取另一个UInt32.这个数字是文本中有多少个字符.

Read another UInt32 from byte index 588 in the data. This number is how many characters are in the text.

从这两个UInt32中选择一个范围,然后从该范围的数据中读取文本.

Make a range out of those two UInt32s and then read the text from that range in the data.

UInt32 fcMin;
[data getBytes:&fcMin range:NSMakeRange(536, sizeof(UInt32))];
UInt32 ccpText;
[data getBytes:&ccpText range:NSMakeRange(588, sizeof(UInt32))];
NSData *textData = [data subdataWithRange:NSMakeRange(fcMin + 512, ccpText)];
NSString *textContent = [[NSString alloc] initWithData:textData encoding:NSUTF16LittleEndianStringEncoding];

这篇关于是否有任何Objective-C库来解析/读取Word文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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