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

I have a .xlsx file in the iOS application docs folder. I want to show this excel file in UIWebview. but I get below error,

Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" 

but the pdf and csv files open, I am new to iOS and have tried all possible things to work, I think the last 2 days. nothing worked .. please help me

Update: Even if I rename it as file.xls, it does not open below my 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;

}

do I need help showing the xlsx file inside my IOS application using UIWebView or is there any other way to show the xlsx file inside the application without using third-party applications?

Update (Solution):
, , XLSX - Apple UIWebView, UIWebView XLSX. , "textEncodingName". base64, textEncodingName: @ "base64", "utf-8"

:

[webView loadData:urlData MIMEType:@"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" textEncodingName:@"base64" baseURL:nil];
+6
3

.XLSX openXML, ! , , webview , mimeTYPE, , /. microsoft, mimetype XLSX (OpenXML):

/vnd.openxmlformats-officedocument.spreadsheetml.sheet

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

(dataWithContentsOfFile: dataWithContentsOfURL: ), webView:

[_webView loadData:<#(nonnull NSData *)#> MIMEType:<#(nonnull NSString *)#> textEncodingName:<#(nonnull NSString *)#> baseURL:<#(nonnull NSURL *)#>]

:

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];

Comparison between source file and displayed webpage file

0

.xlsx UIWebView. .xls UIWebView. , UIWebView

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

.xlsx file, QuickLook FrameWork, QLPreviewController. :

  - (void) initQlController{
  QLPreviewController *prev = [[QLPreviewController alloc]init];
  prev.delegate = self;
  prev.dataSource = self;
  [self presentModalViewController:prev animated:YES];
  [prev.navigationItem setRightBarButtonItem:nil]; }

dataSource : -

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
+2

All Articles