How to open & view view .doc, .docx, .rtf, .ppt, .pptx, .xlsx, .xls file in iphone using UIWebview in Document directory?

StackOverflow https://stackoverflow.com/questions/20953584

  •  24-09-2022
  •  | 
  •  

Frage

Can we open & view .doc, .docx, .rtf, .ppt, .pptx, .xls, .xlsx file in iphone using UIWebview?

I am using Document directory to show the file.

.doc file is working fine here… but rest of the files' extensions are not working..

if any one has implemented this then please help me...

any code snippet or any web link help...

thanks in advance...

War es hilfreich?

Lösung 3

Try this:

     [self.m_webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:_m_filePath]cachePolicy:NSURLCacheStorageAllowedInMemoryOnly timeoutInterval:3.0]];  

You can change timeoutInterval and cachePolicy, in sometime you have to wait more time to loading.

Andere Tipps

You may want to look at the QuickLook Framework for iOS: https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/UsingtheQuickLookFramework.html

It supports the following formats:

  • iWork documents
  • Microsoft Office documents (Office ‘97 and newer)
  • Rich Text Format (RTF) documents
  • PDF files
  • Images
  • Text files whose uniform type identifier (UTI) conforms to the public.text type (see * Uniform Type Identifiers Reference)
  • Comma-separated value (csv) files

More specifically you may want to look at the QLPreviewController: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/QLPreviewController_Class/Reference/Reference.html#//apple_ref/occ/cl/QLPreviewController

with swift 2.2

For showing PDF and DOC file I have use following code snip

//Document file url
var docUrl = NSURL(string: "https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwjjwPSnoKfNAhXFRo8KHf6ACGYQFggbMAA&
url=http%3A%2F%2Fwww.snee.com%2Fxml%2Fxslt%2Fsample.doc&usg=AFQjCNGG4FxPqcT8RXiIRHcLTu0yYDErdQ&sig2=ejeAlBgIZG5B6W-tS1VrQA&bvm=bv.124272578,d.c2I&cad=rja")

let req = NSURLRequest(URL: docUrl!)
webView.delegate = self
//here is the sole part
webView.scalesPageToFit = true
webView.contentMode = .ScaleAspectFit
webView.loadRequest(req)

Note: make sure on backed side (for api) we have to define content-type as document in headers.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top