Re: creating docx file
Re: creating docx file
- Subject: Re: creating docx file
- From: Douglas Davidson <email@hidden>
- Date: Mon, 20 Sep 2010 14:31:12 -0700
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 (email@hidden)
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:
This email sent to email@hidden