0
votes

I have a NSData object that holds the contents of a MS Office Word document that I want to show - using UIWebView.

I'm using the following command:

[self.webView loadData:data MIMEType:@"application/msword" textEncodingName:@"utf-8" baseURL:nil];

Unfortunately, I get an empty screen.

If I try to save the data to a file and open the file using UIWebView's requestWithURL:url method - the file opens just fine. However, it is crucial for the application to load the file from the data in memory and not to save, in any way, the data to a file on the device.

What do I need to show to load an NSData object containing a MS Office document without having to save the data first on the device?

2

2 Answers

2
votes

Try instead:

[self.webView loadData:data MIMEType:@"application/msword" textEncodingName:@"utf-8" baseURL:[NSURL URLWithString:@""]];

There is something about that nil that causes UIWebView not to load certain types. Not sure exactly, but I had similar problems. This solved them.

0
votes

There is one more way to open office document by set the correct MIMEtype as above. for Excel/ppt and other like msword.

NSString *mimtype = @"application/vnd.openxmlformats-officedocument.wordprocessingml.document";
self.webView.delegate = self;

[self.webView loadData:data MIMEType:mimtype textEncodingName:@"UTF-8" baseURL:nil];

This will work for docx too.

Thanks,