UIWebView不会打开ms字(doc)和ms excel(xls)文件 [英] UIWebView does not open ms word (doc) and ms excel (xls) files

查看:100
本文介绍了UIWebView不会打开ms字(doc)和ms excel(xls)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XCode 3.2.5 iOS SDK 4.2开发iPad应用程序。此应用程序需要打开PDF,DOC和XLS文件并将其预览给用户。



我正在尝试使用UIWebView控件打开它们。只有PDF文件正确打开。打开DOC或XLS时,我看到一个黑色的空白视图。
这是在模拟器和设备中发生的。



我做错了什么?



这是代码:


$ (NSString *)filePath fileType:(NSString *)fileType请求:(NSURLRequest *)请求{

UIWebView * webView =(UIWebView *)self.view;
self.actualFilePath = filePath;

NSLog(@文件路径%@,filePath);

NSString * mimeType = @;
if([fileType caseInsensitiveCompare:@PDF] == NSOrderedSame){
mimeType = @application / pdf;
} else if([fileType caseInsensitiveCompare:@DOC] == NSOrderedSame){
mimeType = @application / msword;
} else if([fileType caseInsensitiveCompare:@XLS] == NSOrderedSame){
mimeType = @application / vnd.ms-excel;
}

[webView loadData:[NSData dataWithContentsOfFile:filePath] MIMEType:mimeType textEncodingName:@UTF-8baseURL:[NSURL URLWithString:@http://www.google。 COM]];

}


解决方案

word或excel或pdf文档,您需要文件文件物理路径。这意味着文件应该保存在文档或临时目录中,或者它可能在应用程序包中。

  //现在使用文件路径加载到webview 
[yourWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:yourFilePath]]];


I'm developing an application for iPad using XCode 3.2.5 iOS SDK 4.2. This application requires to open PDF, DOC and XLS files and preview them to the user.

I'm trying to open them with the UIWebView control. Only PDF files are being opened correctly. When opening DOC or XLS I got a black empty view. This is happening in Simulator and Device.

What am I doing wrong?

Here is the code:

-(void)prepareToShow:(NSString*)filePath fileType:(NSString*)fileType request:(NSURLRequest*)request{

UIWebView *webView = (UIWebView*)self.view;
self.actualFilePath = filePath;

NSLog(@"File Path %@",filePath);

NSString *mimeType = @"";
if ([fileType caseInsensitiveCompare:@"PDF"]==NSOrderedSame){
    mimeType = @"application/pdf";
} else  if ([fileType caseInsensitiveCompare:@"DOC"]==NSOrderedSame){
    mimeType = @"application/msword";
} else  if ([fileType caseInsensitiveCompare:@"XLS"]==NSOrderedSame){
    mimeType = @"application/vnd.ms-excel";
}

[webView loadData:[NSData dataWithContentsOfFile:filePath] MIMEType:mimeType textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://www.google.com"]];

}

解决方案

For loading word or excel or pdf documents, you need is physical path of document file. it means file should saved in document or temporary directory or it may be in application bundle.

//now use file path to load in webview
[yourWebView loadRequest:[NSURLRequest requestWithURL:[NSURL  fileURLWithPath:yourFilePath]]];

这篇关于UIWebView不会打开ms字(doc)和ms excel(xls)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆