本文介绍了在UIWebView中显示ppt,doc和xls不起作用,但pdf可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

看起来像stackoverflow上的一些人让这个工作,但他们的代码没有发布。我正在使用

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:@"UTF-8" baseURL:nil];

其中MIMEType是:

where MIMEType is:


  • @application / vnd.ms-powerpoint

  • @application / vnd.ms-word

  • @application /vnd.ms-excel

(顺便说一句,我看过DOC文件使用mimetype @application / msword但是 vnd版本似乎更合适。我试过两种以防万一。

(BTW, I've seen DOC files use mimetype @"application/msword" but the "vnd" version seems more appropriate. I tried both just in case.)

我确认我的'数据'是正确的。 PDF和TXT文件有效。当UIWebView显示PPT,DOC或XLS文件时,它是空白的。我把NSLOG语句放在我的UIWebViewDelegate调用中。

I verified that my 'data' is correct. PDF and TXT files work. When the UIWebView displays PPT, DOC, or XLS files, it's blank. I put NSLOG statements in my UIWebViewDelegate calls.

  shouldStartLoadWithRequest:<NSMutableURLRequest about:blank> navType:5
  webViewDidStartLoad:
  didFailLoadWithError:Error Domain=NSURLErrorDomain Code=100 UserInfo=0x122503a0 "Operation could not be completed. (NSURLErrorDomain error 100.)"
  didFailLoadWithError:Error Domain=WebKitErrorDomain Code=102 UserInfo=0x12253840 "Frame load interrupted"

显然负载失败,但为什么?如果我将我的mimetype更改为@text / plain以获取PPT文件,则UIWebView会正常加载并按预期显示不可打印的字符。那告诉我传递给loadData的'数据'是好的。

so obviously the load is failing, but why? If I change my mimetype to @"text/plain" for a PPT file, the UIWebView loads fine and displays unprintable characters, as expected. That's telling me the 'data' passed to loadData: is ok.

意味着我的mimetypes不好?

Meaning my mimetypes are bad?

为了确保我的PPT,DOC和XLS文件确实可以显示,我创建了一个带有锚标记的简单html文件。当在iPhone上的Safari中显示html文件时,单击文件会在Safari中正确显示。

And just to make sure my PPT, DOC, and XLS files are indeed ok to display, I created a simple html file with anchor tags to the files. When the html file is displayed in Safari on the iPhone, clicking on the files displays correctly in Safari.

我试图研究didFailLoadWithError(100)中显示的错误代码但是所有记录的错误代码都是负数且大于1000(如NSURLError.h中所示)。

I tried to research the error code displayed in didFailLoadWithError (100) but all the documented error codes are negative and greater than 1000 (as seen in NSURLError.h).

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { NSLog(@"didFailLoadWithError:%@", error); }


推荐答案

您是否尝试过使用以下记录的方法?:

Have you tried using the following documented method?:

-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
    NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
}

// Calling -loadDocument:inView:

[self loadDocument:@"mydocument.rtfd.zip" inView:self.myWebview];

适用于iPhone OS 2.2.1中的这些:
Excel(.xls)
Keynote(.key.zip)
Numbers(.numbers.zip)
Pages(.pages.zip)
PDF(.pdf)
Powerpoint(.ppt)
Word(.doc)

It works for these in iPhone OS 2.2.1:Excel (.xls)Keynote (.key.zip)Numbers (.numbers.zip)Pages (.pages.zip)PDF (.pdf)Powerpoint (.ppt)Word (.doc)

iPhone OS 3.0支持以下附加文档类型:
富文本格式(.rtf)
富文本格式目录(.rtfd.zip)
Keynote '09(.key)
Numbers '09(.numbers)
Pages '09(.pages)

iPhone OS 3.0 supports these additional document types:Rich Text Format (.rtf)Rich Text Format Directory (.rtfd.zip)Keynote '09 (.key)Numbers '09 (.numbers)Pages '09 (.pages)

这篇关于在UIWebView中显示ppt,doc和xls不起作用,但pdf可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:02