Possible Duplicate:
Reading Microsoft word document in iphone
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.
Possible Duplicate:
Reading Microsoft word document in iphone
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.
If all you need from a Word document is the plain text, that's pretty easy.
Assume you have an NSData filled with data from a Word .doc...
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.)
Read another UInt32 from byte index 588 in the data. This number is how many characters are in the text.
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];