Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-13-2009, 01:11 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 4
mpek is on a distinguished road
Exclamation Load Microsoft documents -- UIWebView

Hey Folks --

Am trying to load an excel/ppt/word file in my UIWebView. Am downloading the file into NSData Object and then invoking the "loadData" method on UIWebview.

Below is the code :
[webView loadData:documentData MIMEType:[self getMIMEType:documentURL] textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:fName]];

The getMIMEType -- returns the mime type depending on the file extension.
Not sure what value needs to go to "baseURL" parameter.

My files are not locally stored and are pulled down from remote servers (across the internet).


Anyway, PDFs load beautifully. But, no excel, word or ppt. It throws an error -- as it invokes the "didFailLoadWithError" delegate method of UIWebView.

on a side note, has anyone figured an approach to handle flash files in an app ?

Can someone help please ??

Cheers

Mayur
mpek is offline   Reply With Quote
Old 09-13-2009, 01:37 PM   #2 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
mnemonic_fx is an unknown quantity at this point
Default

UIWebView could not load those files, and also it could not load flash.

For loading word or excel, you can look up "Docs" app, but this is not an official app.

Since it's not, maybe the source code is out there somewhere, if they distribute it.
__________________
Visit Me

Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
mnemonic_fx is offline   Reply With Quote
Old 09-13-2009, 02:23 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 4
mpek is on a distinguished road
Default

Quote:
Originally Posted by mnemonic_fx View Post
UIWebView could not load those files, and also it could not load flash.

For loading word or excel, you can look up "Docs" app, but this is not an official app.

Since it's not, maybe the source code is out there somewhere, if they distribute it.

Thanks for responding.

But, how does Safari load those type of documents ? -- doesn't it use the same class (UIWebView) ...


Cheers --

Mayur
mpek is offline   Reply With Quote
Old 09-13-2009, 02:30 PM   #4 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
mnemonic_fx is an unknown quantity at this point
Default

Nope, never seen safari load excel or ppt, or word, if it does, maybe it's using private API.
__________________
Visit Me

Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
mnemonic_fx is offline   Reply With Quote
Old 09-13-2009, 02:55 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 4
mpek is on a distinguished road
Default

Quote:
Originally Posted by mnemonic_fx View Post
Nope, never seen safari load excel or ppt, or word, if it does, maybe it's using private API.
Found this
Technical Q&A QA1630: Using UIWebView to display select document types

although, it does not answer my question -- as its using "loadRequest"

Cheers

Mayur
mpek is offline   Reply With Quote
Old 09-13-2009, 03:06 PM   #6 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
mnemonic_fx is an unknown quantity at this point
Default

Oh, never realized that.

Well it's using fileURLWithPath:, so it's referring to the local file path, loadRequest will accept any NSURL object from any source.

I think your problem is with your data provided from your server. It may not conform to the right file format, when it's received on the client.
__________________
Visit Me

Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
mnemonic_fx is offline   Reply With Quote
Old 09-14-2009, 08:48 PM   #7 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 4
mpek is on a distinguished road
Default

Quote:
Originally Posted by mnemonic_fx View Post
Oh, never realized that.

Well it's using fileURLWithPath:, so it's referring to the local file path, loadRequest will accept any NSURL object from any source.

I think your problem is with your data provided from your server. It may not conform to the right file format, when it's received on the client.

any suggestions guys ??
mpek is offline   Reply With Quote
Old 09-26-2009, 10:45 PM   #8 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 8
Mugunth Kumar is on a distinguished road
Unhappy

I too have this problem...
Frame load interrupted error while loading a word document in UIWebView - Stack Overflow

My case is that, not *all* documents fail to load.




Quote:
Originally Posted by mpek View Post
Hey Folks --

Am trying to load an excel/ppt/word file in my UIWebView. Am downloading the file into NSData Object and then invoking the "loadData" method on UIWebview.

Below is the code :
[webView loadData:documentData MIMEType:[self getMIMEType:documentURL] textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:fName]];

The getMIMEType -- returns the mime type depending on the file extension.
Not sure what value needs to go to "baseURL" parameter.

My files are not locally stored and are pulled down from remote servers (across the internet).


Anyway, PDFs load beautifully. But, no excel, word or ppt. It throws an error -- as it invokes the "didFailLoadWithError" delegate method of UIWebView.

on a side note, has anyone figured an approach to handle flash files in an app ?

Can someone help please ??

Cheers

Mayur
Mugunth Kumar is offline   Reply With Quote
Old 11-05-2009, 01:29 AM   #9 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 180
wolverine is on a distinguished road
Smile

Quote:
Originally Posted by mpek View Post
any suggestions guys ??
I was able to load .xls,.ppt as well as .pdf file in UIWebView after i loaded them into my application as Resources. If u ppl got the answer pls reply. Otherwise i will post my code for that.
wolverine is offline   Reply With Quote
Old 12-17-2010, 01:20 AM   #10 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 2
thearora is on a distinguished road
Default Request for Code

Hi wolverine,

I cant view docx and xlsx files inUIWebview , please send your code here or on my mail ID: thearora@yahoo.co.in

Thanks in advance.

Quote:
Originally Posted by wolverine View Post
I was able to load .xls,.ppt as well as .pdf file in UIWebView after i loaded them into my application as Resources. If u ppl got the answer pls reply. Otherwise i will post my code for that.

Last edited by thearora; 12-20-2010 at 10:16 PM.
thearora is offline   Reply With Quote
Old 05-25-2011, 03:08 AM   #11 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 2
thearora is on a distinguished road
Default

Hi All,

I am able to access all above mentioned extension, so any one want sample code for that mail me on thearora@yahoo.co.in
thearora is offline   Reply With Quote
Old 08-19-2011, 04:33 AM   #12 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 2
aanchal is on a distinguished road
Default Need your sample code

Quote:
Originally Posted by wolverine View Post
I was able to load .xls,.ppt as well as .pdf file in UIWebView after i loaded them into my application as Resources. If u ppl got the answer pls reply. Otherwise i will post my code for that.
Hi,

Can you please send me the sample project/code ?

My e-mail is userfacebook999@gmail.com

Thank you !

aanchal
aanchal is offline   Reply With Quote
Old 08-19-2011, 04:40 AM   #13 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by aanchal View Post
Hi,

Can you please send me the sample project/code ?

My e-mail is userfacebook999@gmail.com

Thank you !

aanchal
you don't need to ask for sourcecode, this can be achieved with 3 lines of code.

see this tutorial
iPhone Coding ? Learning About UIWebViews by Creating a Web Browser | iPhone Programming Tutorials

and replace the code in viewDidLoad with

Code:
- (void)viewDidLoad 
{
   [super viewDidLoad ];

   NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"pdf"];
   NSURL *url = [NSURL URLWithStringdfPath];
   NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
   [webView loadRequest:urlRequest];
}

you can load in the same mode, ppt, doc, etc...
__________________
dany_dev is offline   Reply With Quote
Old 08-19-2011, 04:52 AM   #14 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 2
aanchal is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
you don't need to ask for sourcecode, this can be achieved with 3 lines of code.

see this tutorial
iPhone Coding ? Learning About UIWebViews by Creating a Web Browser | iPhone Programming Tutorials

and replace the code in viewDidLoad with

Code:
- (void)viewDidLoad 
{
   [super viewDidLoad ];

   NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"pdf"];
   NSURL *url = [NSURL URLWithStringdfPath];
   NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
   [webView loadRequest:urlRequest];
}

you can load in the same mode, ppt, doc, etc...

Hi,

Thanks for your response.

I am able to open .doc, .ppt, .pdf files in UIWebView. I want code for open .xls file in UIWebView.

Thanks.
aanchal is offline   Reply With Quote
Old 08-19-2011, 05:17 AM   #15 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

UIWebView should read xls in the same manner of pdf, doc, ppt, etc...just change the file name
__________________
dany_dev is offline   Reply With Quote
Reply

Bookmarks

Tags
excel, loaddata, uiwebview, word

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 339
11 members and 328 guests
givensur, glenn_sayers, guusleijsten, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:30 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0