On Sep 20, 2010, at 12:57 PM, Philip White wrote:

> Hello,
>  I've tried using the following code to save an attributed string as a docx 
> file.
> 
> //the attributed string is 'contents'
> 
> NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: 
> NSOfficeOpenXMLTextDocumentType, NSDocumentTypeDocumentAttribute, nil];
> NSRange range = {0,[contents length]};
>       
> NSError *error=nil;
> NSFileWrapper *wrapper = [contents fileWrapperFromRange: range 
> documentAttributes: attributes error: &error];
> 
> [wrapper writeToFile:[path stringByExpandingTildeInPath] atomically:YES 
> updateFilenames:NO];
> 
> 
> What I end up with is what appears to be an unzipped docx file (my 
> understanding is that docx files are zipped archives), i.e a folder full of 
> various resource files. I then try zipping it and changing the extension to 
> docx but I don't seem to end up with a valid docx file, or at least not 
> something that Pages 2008 can open. Maybe that version of Pages can't open 
> that format anyway, but still that code clearly isn't creating what I would 
> call a docx file. Any thoughts?

fileWrapperFromRange... is what you use when you want something that has a 
directory structure on disk, e.g. RTFD.  Use dataFromRange... instead.

Douglas Davidson

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to