Is it possible to import excel file Xcode bundle? - ios

I want to import the excel file in Xcode bundle.
When I click on button then all excel content store in the database then it visible in the table from the database.

Umm, you can use this: https://github.com/davedelong/CHCSVParser BUT you have to store the file as CSV, not XLSX or XLS
Also, you can store this in the bundle, you just have to call to the bundle, something like this:
NSString *fileName = #"theFileName";
NSString *pathToFile =[[NSBundle mainBundle] pathForResource:fileName ofType: #"csv"];
the #"csv" may need to be #"txt", try it with both

These stuffs may help u
File search with specific Extension Objective c
for read (import) a XLS file https://github.com/dhoerl/DHlibxls its working well
if you need to write (export) a XLS file, u use pods https://cocoapods.org/pods/JXLS its also working
if you need to edit a XLSX file https://github.com/renebigot/XlsxReaderWriter (i'm not sure, because i don't work with it)
If you just need to show the files(XLS/XLSX) to the users, you can use a UIWebView

Related

What is Plist file in detail?

I am learning iOS. I have a confusion about the Plist file, about the creator, applicable platform, format and so on. So what the Plist file really is?
PList is a property list.
You can find more useful information at:
https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html
http://nscookbook.com/2013/02/ios-programming-recipe-13-using-property-lists-plists/
How to use pList in iOS Programming
And the following one would give you more infor about the specific keys:
https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Introduction/Introduction.html
A plist file is a property list. You can either create it using the nice animations Xcode gives you, or you can create pragmatically using XML. A plist file is something that can store objects (string, bool, data, date, number), like a database. And you can run through the plist file to retrieve or store the information just like a database.
In games you mostly save your score using NSUserDefaults as the data isn't sensitive, however saving information like a home address in NSUserDefaults isn't the best idea. Instead you'd rather want to save the information in a database - a plist file. Apple uses plist files in their apps. When you open contacts the information is retrieved from the plist and then put into a UITableView. When you click on a person it gives you their details, the details which were received from the plist file.
Another great things about a plist file is that you can change it from binary to XML and vice versa. Why would you ever want to change it to binary? Sometimes when you're dealing with large data e.g. a whole dictionary, it'll be faster to run through the data is binary than it would be in XML. To change it into binary, you go to terminal and use this command, plutil -convert binary1 yourFile.plist. To change binary to XML you use this command, plutil -convert xml1 yourFile.plist.
A plist in raw XML looks like:
A plist with the nice animation in Xcode looks like:
And finally a plist in binary looks like:
Now lets say you've created your plist and stored all the information in it that you want. To retrieve this information (in objc) use the following code.
NSString *path;
path = [[NSBundle mainBundle] pathForResource:#"file" ofType:#"plist"];
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
for (NSString *str in array) {
#autoreleasepool {
NSLog(#"%#", str);
}
}
Hope this helped you!!

Adding file to specific folder in iOS application

We are making a common library in c++ for database and file reading.
We have decided a common folder structure for placing the files.
For eg. Insert statement files will be in a Lib/Files/Insert/
I will pass root directory of the project to c++ library, the library then will automatically append the path of the file to root directory.
For eg. If I need insert file of Author, I will pass /path/to/root/ to library. The library will append the rest of the path and pick up file like this: /path/to/root/Lib/Files/Insert/Author.txt
I was not able to open the file from c++ code.
Then I tried this to get the path of file using Objective-C:
NSString * authorPath = [[NSBundle mainBundle] pathForResource:#"Author" ofType:#"txt"];
It is showing the following path:
/Users/homam/Library/Application Support/iPhone Simulator/7.0.3/Applications/9C882381-DAA7-464D-AA84-8DB9288AAD71/CoreLibraryDemo.app/Author.txt
Although I have placed it in the folder /Lib/Files/Insert/, it is not included in the above path before Author.txt
So how can I maintain folder structure in iOS and read file from c++ library.

Where can I store my webserver URLs?

I hard code all URLs in my mobile app which I know is not a good idea. For example, if I were to ever need to move domain names I'd need to rename all URLs within the app from www.oldname.com to www.newname.com on each and every page.
I'm not sure where and how to store them so that I can modify this information on a single page and have it automatically changed across all pages.
In PHP I'd create a single file with variables that'd I'd include in all pages. I'm not sure how this is done in objective-c however. How do you do it?
You can create a constants file and include that in all other file where the URL is listed.
Create a file, e.g. constants.h where you put all your contstants.
In constants.h you could put something like this:
#define kApiBaseUrl #"https://myapi.mydomain.com"
And in your other files you acces it like this example:
NSURL *url = [NSURL URLWithString:kApiBaseUrl];
Probably this is like what you did use to do in PHP.
You can also set predefined URL's in the PLIST of your app but this is probably easier.
similar to edwardmp's response, you can also create a Constants.h file and define some static constant strings.
static NSString *const kSiteRootURL = #"http://www.someurl.com";
Check the folder "Supporting Files" inside your project you should have a file named "nameOfYourApp-Prefix.pch" then you can define the root URL for exemple
#define ROOT_URL #"yourwebsite.com"
and you can access ROOT_URL from anywhere in your project
You can keep your URLs in a property list file (File => New file => Property ...). You will have something like "config.plist". Similar with other property file, it is key => value file where the value can be a string, an arrays, etc.
Use NSBundle to load the file in your app, like
NSString *path = [[NSBundle mainBundle] pathForResource:#"config" ofType:#"plist"];
NSDictionary *config = [[NSDictionary alloc] initWithContentsOfFile:path];
This will give a benefit where you don't have to re-compile again your codes whenever you make any change on the URLs.
You can add a NSString to your .pch file to be included in all of modules.

Which zipping library should I use to properly assemble a valid XLSX file in Objective-C?

I am trying to modify an XLSX file programmatically using Objective-C.
So far, I am only modifying the data on one of the sheets. The steps I am taking are as follows:
Copy the XLSX file to Documents folder
Unzip the XLSX container with keeping the directory structure
Parse the corresponding sheet XML file (sheet2.xml in my case)
Add some rows
Rewrite the XML structure and save it
Put the updated XML file back into the XLSX container
However, the new XLSX file becomes corrupt. I am using GDataXML for XML parsing/writing and Objective-Zip for zipping/unzipping.
I know that the XML file I have created is proper, because when I manually unzip and the re-zip the corrupt XLSX file, it opens without any errors. I have done this on both OS X (using Unarchiver) and Windows (using 7-Zip).
The problem is either with the Objective-Zip library, or the way I use it. Below is how I implement the zipping method:
ZipFile *zipFile = [[ZipFile alloc] initWithFileName:XLSXDocumentsFilePath mode:ZipFileModeAppend];
ZipWriteStream *stream= [zipFile writeFileInZipWithName:XLSX_WORKSHEET_XML_SUBPATH compressionLevel:ZipCompressionLevelNone];
[stream writeData:data];
[stream finishedWriting];
[zipFile close];
I also tried the other compressionLevel arguments available with no luck:
ZipCompressionLevelDefault
ZipCompressionLevelBest
ZipCompressionLevelFastest
My questions are:
Which zipping library should I use to create a valid XLSX file programmatically?
If Objective-Zip is suitable, what is wrong with my code?
From an answer to another question, I found out that: "The OOXML format imposes that the only compression method permitted in the package is DEFLATE".
Is it possible to force Objective-Zip to use DEFLATE? Or is there an open-source iOS zipping library that uses DEFLATE?
I found the answer upon doing some research and also having a one to one correspondence with Objective-Zip's developer, flyingdolphinstudio.
First of all, Objective-Zip uses DEFLATE as the default compression method. I also confirmed this with the developer, who told me that using ZipCompressionLevelDefault, ZipCompressionLevelFastest or ZipCompressionLevelBest for the argument compressionLevel: will guarantee a DEFLATE compression.
So, the problem is coming from the mode: argument, which is ZipFileModeAppend in my case. It seems that MiniZip does not have a method to delete the files inside a zip file and that's why I am not overwriting the existing file, but adding a new one. To make it more clear, take a look at how my xl/worksheets folder look like after zipping it using Objective-Zip:
So, the only way to create a valid XLSX container is to create the zip file from scratch, by adding all the files and also keeping the directory/file structure intact.
I hope this experience would help somebody out.

Loading an image programmatically in iOS

In my App for the iPad I'm trying to load an image file programmatically. The file is NOT part of my project, hence it is not referenced in XCode. There is no entry for the file in XCode's Groups and Files column.
The image has to be loaded at runtime instead, it name being read from a Property List.
I'm trying to load the file like this:
NSString* pathToImageFile = [[NSBundle mainBundle] pathForResource:#"MyImage" ofType:#"png" inDirectory:#"MyDirectory"];
UIImage* retVal = [UIImage imageWithContentsOfFile:pathToImageFile];
In this case, mydirectory lives in the main bundle like this:
MyAmazingApp.app/MyDirectory/MyImage.png
Unfortunately, the Image will not load. I can't add the image file to my project, as its name is to be determined at runtime and cannot be known in advance. The file name is read from a config file (a Property List) at runtime instead.
What am I doing wrong? Your help will be very much appreciated.
You can use NSFileManager to get the contents of a directory, or several directories. You obviously have to know something about the file you want to load so that you can identify it, but you could for example use NSFileManager to help you generate a list of images in your app bundle and in your app's Documents directory.

Resources