1

I am trying to load a .xls Ms-Excel file in my WebView it showing error through didFailWith error delegates method the problem is i am unable to understand this error please help me.

Here is my code:-

-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
    NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSData *data = [NSData dataWithContentsOfURL:url];

    [webView loadData:data MIMEType:@"application/vnd.ms-excel" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
}

And Error is:-

    EXCEPTION CPMessageException: (null)
    2013-09-25 12:35:47.051 ewApps-dev18[1111:c07] [ReportsWebView_iPhone.m:116] did fail with error:- Error Domain=OfficeImportErrorDomain Code=912
 "Unknown exception" UserInfo=0x97a4970 
{NSErrorFailingURLKey=x-apple-ql-id://B7559867-1117-4FF5-8F61-015464D8E2C7/x-apple-ql-magic/, NSErrorFailingURLStringKey=x-apple-ql-id://B7559867-1117-4FF5-8F61-015464D8E2C7/x-apple-ql-magic/, NSLocalizedDescription=Unknown exception}.
Vinodh
  • 5,262
  • 4
  • 38
  • 68
Gaurav
  • 553
  • 5
  • 9

1 Answers1

1

This is working code. `

UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0.0, 0.0, 1000, 760)];
[webView setScalesPageToFit:YES];
webView.backgroundColor=[UIColor clearColor];
NSString *excl = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"xls"];
NSURL *exclURL = [NSURL fileURLWithPath:excl];
NSURLRequest *request = [NSURLRequest requestWithURL:exclURL];
[webView loadRequest:request];
[self.view addSubview:webView];

`

Make sure your file is not password protected.

Regarding your error check out error code Error Code List

Jagdeep
  • 578
  • 4
  • 11
  • 1
    reference link : (http://stackoverflow.com/questions/2520137/displaying-ppt-doc-and-xls-in-uiwebview-doesnt-work-but-pdf-does) – Jagdeep Sep 25 '13 at 08:23