Opening word,excel, and PDF files without using UIWebview on iOS
Asked Answered
C

1

8

Is it possible to open word and excel file in iPhone/iPad without using UIWebview?

Cutcherry answered 8/8, 2011 at 14:17 Comment(0)
F
12

You have two options. For iOS 4.0 or later, you can use the QLPreviewController. You will need to implement the following two methods-

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller 
{
  return 1; //assuming your code displays a single file
}

- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index 
{
  return [NSURL fileURLWithPath:path]; //path of the file to be displayed
}

And initialize the QLPreviewController as follows-

QLPreviewController *ql = [[QLPreviewController alloc] init];
 ql.dataSource = self;
 ql.delegate = self;
 ql.currentPreviewItemIndex = 0; //0 because of the assumption that there is only 1 file  
 [self presentModalViewController:ql animated:YES];
 [ql release];

For older iOS versions, you can use the UIDocumentInteractionController in the following way. Implement the delegate method-

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
 return self;
}

Init & display-

    UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
docController.delegate = self;
[docController presentPreviewAnimated:YES];

Thanks,

Akshay

Fic answered 8/8, 2011 at 14:29 Comment(2)
Akshay thanks alot. Can you tell me one thing more, is it passible to customize the view of controller in own formate?Cutcherry
No. Both these options do not allow customization. Please mark it as the answer if you liked it.Fic

© 2022 - 2024 — McMap. All rights reserved.