UIWebview(iOS)中的Docx支持? [英] Docx support in UIWebview(iOS)?

查看:100
本文介绍了UIWebview(iOS)中的Docx支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查了文档支持的官方链接,并且明确指出UIWebview不支持docx,

I have checked the official links for doc support, and its clear that docx is not supported in UIWebview,

https://developer.apple.com/library/ios/qa/qa1630/_index.html

但是,我也发现有些人能够在UIWebview中打开docx文件,

But , i also found out that some guys were able to open docx files in UIWebview,

Cannot通过web浏览器应用程序中使用OpenIn功能
为什么doc和docx丢失样式信息iOS?
如何打开Microsoft Office iPhone中的文档

另外,还有iOS移动浏览器在UIWebview上,我可以在浏览器中从互联网上打开docx文件。
但是当我从我的测试服务器下载docx时(我已经通过从模拟器导入它来交叉检查下载的docx并且它在我的mac上完全打开),我无法在UIWebview中查看它。

Also, afaik, iOS safari browser is built upon UIWebview and i am able to open docx files from internet in the browser. But when I download a docx from my test server(I have cross checked the downloaded docx by importing it from simulator and it opens perfectly on my mac), i am unable to view it in UIWebview.

我很困惑,
docx是否支持?
或者看来docx还有更多种格式支持吗?

I am confused, Is docx Supported or not? Or it seems that docx has further variety of formats out which some are supported?

这是我的加载代码,

    NSURLRequest *request = [NSURLRequest requestWithURL:urlPath];
    [webViewForDocsView loadRequest:request];


推荐答案

不知道为什么但是使用URL方案来负载的docx没有工作,(下面的代码没有工作)

Don't know why but using the URL scheme to load docx didn't worked,(below code didn't worked)

 NSURLRequest *request = [NSURLRequest requestWithURL:urlPath];
[webViewForDocsView loadRequest:request];

而是将文件加载到内存中(使用NSData)并加载MIME类型的数据(下面)代码就像魅力一样!)

Instead loading the file in memory(using NSData) and loading the data with MIME type worked(the below code worked like charm!)

NSString *path = [urlFileInView path];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];


webViewForDocsView.delegate = self;
[webViewForDocsView loadData:data MIMEType:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document" textEncodingName:@"UTF-8" baseURL:nil];

这篇关于UIWebview(iOS)中的Docx支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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