how to open file.xlsx in UIWebView IOS using objective-c -


i have file.xlsx in ios app documents folder. want show open excel file in uiwebview. getting below error,

error domain=webkiterrordomain code=102 "frame load interrupted"  

but pdf , csv files opening, new ios , tried possible things work guess last 2 days. nothing worked out.. please me

update: if rename file.xls not opening below code,

    nsurl* nsurl = [nsurl urlwithstring:url];         _urlreq = [nsurl urlwithstring:url];         [self performselector:@selector(urlrequestforfile) withobject:nil afterdelay:0];         _webview.delegate = self;         nsurlrequest* request = [nsurlrequest requestwithurl: nsurl];         [_webview loadrequest: request]; 

-(void)urlrequestforfile{     self.connection = nil;     nsurlrequest *requestforfile = [nsurlrequest requestwithurl:_urlreq cachepolicy:nsurlrequestreloadignoringcachedata timeoutinterval:300];     _connection = [[nsurlconnection alloc]initwithrequest:requestforfile delegate:self startimmediately:yes];     _ongingserviceflag = yes;  } 

need in showing xlsx file inside ios app either using uiwebview or there other way show xlsx file inside app without using third party apps?

update(solution):
surprised see there no support xlsx mentioned in apple site uiwebview uiwebview supports xlsx format. 1 thing need make sure specify correct 'textencodingname' value. if file stored base64 binary encoding u have mention textencodingname:@"base64" otherwise u have mention "utf-8"

below line worked me:

[webview loaddata:urldata mimetype:@"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" textencodingname:@"base64" baseurl:nil]; 

the .xlsx filetype based on openxml news! means it's readable, need let webview know type, or rather mimetype, of file loading/displaying. according microsoft mimetype use xlsx (openxml) files is:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

source: https://blogs.msdn.microsoft.com/dmahugh/2006/08/08/content-types-for-open-xml-documents/

to load data (datawithcontentsoffile: or datawithcontentsofurl: or prefered method) calling webview method:

[_webview loaddata:<#(nonnull nsdata *)#> mimetype:<#(nonnull nsstring *)#> textencodingname:<#(nonnull nsstring *)#> baseurl:<#(nonnull nsurl *)#>] 

example of working code:

nsdata *data = [nsdata datawithcontentsofurl:[nsurl urlwithstring:@"https://mycoolserver.com/file.xlsx"]]; [_webview loaddata:data mimetype:@"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" textencodingname:@"utf-8" baseurl:nil]; 

side-by-side comparison of origional file , webview rendered file


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -