I'm writing an app in which I'd like to be able to open, edit, and write .docx files. I've read documentation and tutorials on TextKit and understand how attributes can be applied to text and I know that .docx is basically a .zip containing some XML
. However I'm at a loss of how to read a .docx in Objective-C and place it into a UITextView and then write it back again. Any idea on how to go about this?
Asked
Active
Viewed 1,265 times
-2

Slayter
- 1,172
- 1
- 13
- 26
-
1UITextView supports rich text so one possibility is to save the Word document as RTF and then simply load it into the UITextView. This would only support a subset of the Word document format though. Otherwise I think the Fruity guy below may be correct with his suggestion. – Duncan Groenewald Nov 05 '13 at 23:34
-
Would there be a way to do that locally within the app? – Slayter Nov 05 '13 at 23:35
-
Not without writing your own code (or third-party library) to convert from MS Word format to RTF or RTFD. You might want to check the NSAttributedString docs to confirm this though, the OS X libraries handle saving to a number of formats but I can't recall whether they can import from these formats as well or whether the iOS libraries offer the same capabilities. I'll check the export code (OS X) I am using and get back to you if I find anything that looks like it might be useful. – Duncan Groenewald Nov 06 '13 at 03:08
-
1initWithDocFormat:documentAttributes: Initializes and returns a new NSAttributedString object from Microsoft Word format data contained in the given NSData object. - (id)initWithDocFormat:(NSData *)data documentAttributes:(NSDictionary **)docAttributes Availability Available in OS X v10.3 and later. Declared In NSAttributedString.h – Duncan Groenewald Nov 06 '13 at 03:29
-
It seems UIKit (iOS) NSAttributedString only supports initialisation with the following document types: NSString *NSPlainTextDocumentType; NSString *NSRTFTextDocumentType; NSString *NSRTFDTextDocumentType; NSString *NSHTMLTextDocumentType; – Duncan Groenewald Nov 06 '13 at 03:32
-
this may be a dumb question but would .docx be coonsidered a `NSHTMLTextDocumentType`? – Slayter Nov 06 '13 at 03:35
-
1No, docx uses OOXML which is not the same as HTML. – Duncan Groenewald Nov 06 '13 at 22:59
2 Answers
0
You could try http://libopc.codeplex.com/ which per that link is a
- ISO/IEC 29500 standard conformant,
- cross-platform,
- open source,
- standard C99-based
implementation of Part II (OPC) and Part III (MCE) of the ISO/IEC 29500 specification (OOXML).

JasonPlutext
- 15,352
- 4
- 44
- 84
-1
UITextView
only supports text, so you probably want to implement your own UIView
subclass to display the docx file.
- Unzip the collection of Open Packaging Conventions.
- Implement a view that conforms to the markup languages you want to support that you found in step 1.
The 7,000 page document describing the Open Office document standard is here. http://www.ecma-international.org/publications/standards/Ecma-376.htm

Fruity Geek
- 7,351
- 1
- 32
- 41