It looks like a few people on stackoverflow get this to work but their code isn\'t posted. I\'m using
[web loadData:data MIMEType:MIMEType textEncodingName
The only way i found to read an Office object (tested with .doc or .xls) is to save the NSData object in a temp file, then read it.
-(void)openFileUsingExtension:(NSString*)extension {
NSString *path = [NSString stringWithFormat:@"%@temp.%@",NSTemporaryDirectory(),extension];
NSLog(@"%@",path);
if ([objectFromNSData writeToFile:path atomically:YES]) {
NSLog(@"written");
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webview loadRequest:request];
self.webview.scalesPageToFit = YES;
self.webview.delegate = self;
[self.view addSubview:self.webview];
}
}
then you can remove the file inside the UIWebViewDelegate method:
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSString *path = [NSString stringWithFormat:@"%@temp.%@",NSTemporaryDirectory(),extension];
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}