I want to devlop an application in iphone where user can open a xls file ,Can do some editing on data already present and finally save it.
How can i do it any idea?
Yes, Hardik it is very simple if you want to open a local xls file.
Add a local xls file in to your project
Drag and drop an UIWebView control on the view.
Connect Files owner and UIWebView Object
Add this:
- (void)viewDidLoad {
[super viewDidLoad];
//Get the path where your local xls file is located
NSString *FilePath = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"xls"];
//Now To use a local resource file in a web view you need to use NSURL fileURLWithPath:
NSURL *url=[NSURL fileURLWithPath:FilePath];
//URL Requst Object
NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[m_webView loadRequest:requestObj];
}
Now just Build and Go
You can use UIWebView to view an XLS file, but you won't be able to edit it. There's nothing built in to the iPhone SDK that will do this for you. You could try contacting these folks to see if they would license their software to you.
Related
I have a file, which i want to open in safari (or call it view in safari).
I add this file to my bundle resources.
and do the following:
NSString *path = [[NSBundle mainBundle] pathForResource:#"tryFile.txt" ofType:nil inDirectory:nil];
NSURL *url = [NSURL fileURLWithPath: path];
NSLog(#"path: %# \n url:%# \n can open url:%d",path,url,[[UIApplication sharedApplication] canOpenURL:url]);
BOOL didGo = [[UIApplication sharedApplication] openURL:url];
NSLog(#"didgo?: %d",didGo);
Of course, as the sandboxed environment says, I am not able to open the file ins safari. It says, canOpenURL as yes but then didGo is NO.
How can I do this without setting up a local server. Please suggest.
Should I keep the data stored in a variable and then open an html page with that data...or what?
EDIT:
These are the logs:
path: /var/mobile/Applications/C78C7CD8-22C7-468A-AA5D-AF22C6042378/TryApp.app/tryFile.txt
url:file://localhost/var/mobile/Applications/C78C7CD8-22C7-468A-AA5D-AF22C6042378/TryApp.app/tryFile.txt
can open url:1
didgo?: 0
PLEASE NOTE opening the file in a webview is not an option. The requirement wants it to be opened in safari. And anyways, this example is of a text file...the filethat may be opened can be anything, and webview does not support all file types.
The txt file resides within your application sandbox. The URL that you are trying to load in Safari will not get loaded due to security in iOS. Read more about it here
As a workaround you can use a UIWebView in your application and open the file in that.
Cheers!Amar.
You'll need to setup a server or open the page in a UIWebView inside the app.
NSString *path = [[NSBundle mainBundle] pathForResource:#"tryFile.txt" ofType:nil inDirectory:nil];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:path]];
This code is for open url in directly in safari OR you can use Webview and direct open url in your webview.thanks
I am having an application which consists of many different file formats like ppt,pdf,txt,png etc, I want to open it whenever the user taps the particular file. How this can be done?Please help me
Can I use WebView for all the files ?
Have a look at the quick look framework with UIDocumentInteractionController class it will have you to open different format of file in its view controller..
QuickLook is a framework that provides quick previewing of a range of document types – supported documents include iWork documents, Microsoft Office, Rich Text Format, PDF, images, text files and comma-separated (csv) files.
Sample Application
UIWebview allow you to display office documents :
You can open them by loading the file data, example with RTF file :
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"MyFile" ofType:#"txt"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
[self.webView loadData:myData MIMEType:#"application/rtf" textEncodingName:#"latin1" baseURL:nil];
Or you can load them by creating a request with local path :
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:#"fileName" ofType:#"pdf"];
NSURL *url = [NSURL URLWithStringdfPath];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
Note that for Office documents with complex layout you will have a very (very) poor rendering.
The only solution is to call a separate application that handles this kind of documents (Pages, Quick office, etc)
Have a look at UIDocumentInteractionController to open your documents in another app
Hope this helps,
Vincent
I have a zip file. In that zip file I have some ppt presentation.
I want to show that ppt presentation in my UIWebView.
I cannot extract and show ppt files there directly .
How do I access the ppt inside the zip in objective c?
This isnt easy. You might want to consider doing this another way. For example you could put the file unzipped on a server and open the link in a webview.
However, if you really want to do it this way there is 2 step.
1. Unzip the file.
You want end up with NSData. Read though some of the links suggested in the comments. You will need to use a 3rd party library to achieve this.
2. Load the data in to a UIWebView.
Write the NSData to the temp directory then point the UIWebView at it.
NSString *path = // .. Get a location in the NSTemporaryDirectory
if ([pptData writeToFile:path atomically:YES])
{
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
I want to display local html file that has css too in UIWebView. I am able to do that using following code..
NSURL *baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSString *path = [[NSBundle mainBundle] pathForResource:#"info" ofType:#"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:path];
[webView loadHTMLString:htmlString baseURL:baseUrl];
I am not able to get hover effects and my understanding is my be there is no hover kind of thing in a touch mobile,
Any ways my main issue is I had deleted my index.html from resources and then re added the updated one but not getting the updated one..
I don't know what happen the web view still loads the old html file. I tried to clean project too.
Second thing can I get css effects in iphone..?
Thanks..
As far as I know you can only achieve this result by using javascript-events like ontouchstart (or something).
I believe if you reset your simulator (While running your simulator, go to iOS Simulator > Reset Content and Settings in the menu bar) then re-run your app, the UIWebView will load the new index.html. UIWebViews cache these things, so you can add code to clear that cache and/or ignore the cache. Check here: Clearing UIWebview cache
I've looked EVERYWHERE for this, can't find anything. I basically need to store an entire website inside of my iPhone for some interesting reasons. Regardless I can't figure out how to display it correctly in my UIWebView.
EDIT: I should clarify, I can load the original HTML file, and I have chagned all of the pathing to be local, except nothing gets linked in.
Here is the code
self.dataDetectorTypes = UIDataDetectorTypeLink;
NSString *path = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self loadRequest:request];
index.html has a bunch of <script type="text/javascript" src="somescript.js">
None of the JS code gets executed
Looks like you're loading the HTML from inside your bundle. This means that all the additional files (.js, .css, and any media files) also need to be present in your bundle. So the first thing to check is to look inside the contents of your executable and make sure the js, etc. files are included.
If that looks fine the next thing to check is if the html, js, or css files reference content via relative or absolute URLs. If there's an absolute path reference in the web content then UIWebView is going to try to download that content each time so it'll only work when you have a net connection. If the path is relative then it's going to look in the bundle to see if such a file exists.
When you included the html and content into the XCode project file you probably dragged the file(s) over to the project side-bar and were asked whether to "Recursively create groups for any added folders" or to "Create Folder References for any added folders."
The default is the first one which means XCode creates a yellow folder in your project, but it'll ignore the directory hierarchy on disk when time comes to generate the output bundle. If you choose the second option then the folder is blue and if you look in your output bundle you'll see that the whole folder hierarchy has been replicated.
The first works for simple web pages where everything is at the same folder level and you can use the method you list above to load it. The second case works better if your web page is complex and references content in sub-folders in which case you need to load the web pages from a relative path (say, the 'webpages' folder):
NSString *path = [[NSBundle mainBundle]
pathForResource:#"index" ofType:#"html"
inDirectory:#"webpages"];
The last thing to check for is if there are any BASE tags in the html file. This is a way to specify a default address or target for all links on a page, but it can muck up webview links.
The problem is that this call:
NSURL *url = [NSURL fileURLWithPath:path];
doesn't setup a baseURL and so relative paths in the .html file for things like javascript, css, images etc don't work.
Instead use this:
url = [NSURL URLWithString: [path lastPathComponent]
relativeToURL: [NSURL fileURLWithPath: [path stringByDeletingLastPathComponent]
isDirectory: YES]];
and then things like "styles.css" in the index.html file will be found IFF they are copied into the bundle next to the .html file.
You need to set this:
myWebView.dataDetectorTypes = UIDataDetectorTypeLink
Make sure that the .js files are in your copy to resource bundle section and not in the compile section. Xcode places them in the compile group by default.
When adding pathFor resource in Dictionary , it displays a nil string error.
My attempt was to run an entire web page out of the Xcode project file. To do that you must:
When importing the file select "Create folder references for any added folders".
Set up the web view, but make sure you set the relative path as previously mentioned.
NSString *path = [[NSBundle mainBundle] pathForResource:#"filename"
ofType:#"html"
inDirectory:#"Directory"];
NSURL *url = [NSURL URLWithString:[path lastPathComponent] relativeToURL:
[NSURL fileURLWithPath: [path stringByDeletingLastPathComponent]
isDirectory:YES]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.currentWebView loadRequest:request];