How can i create excel sheet and file in iPhone sdk?
Solution 1
Well, the right guy saw your post! There is an open source C++ library on SourceForge, xlslib, that will do exactly what you need.
But wait - there's even more! There is a Objective-C wrapper to that library - its a bit out of date but recently someone reported that they got it to work on iOS.
The two people supporting this library appear to be quite responsive to users, so its likely that they will continue to support the ObjectiveC wrapper if people are using it.
That said, there is no out-of-the-box library/framework to just stick in your project. You will have to spend some time, maybe even a day or two, to get the thing to build and run on iOS. If you are in a hurry you will have to spend the time. If you are patient you may get help on it.
EDIT: there is an ObjectiveC framework using this library: JXLS.
Solution 2
I found a link on github. Just add these few files & follow instruction for integrating code(easy to integrate).
Here is Link
https://github.com/andreac/RSSheet
Please convert these files into ARC to avoid crashing due to memory management. Hope it works.
Solution 3
Another option if your Excel file isn't very complicated would be to use an HTML table. I've tried it and it works pretty well.
NSURL * docsDir = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].lastObject;
NSURL *file = [docsDir URLByAppendingPathComponent:@"sample.xls"];
NSString* htmlString = @"<table>
<tr>
<th bgcolor="#00FF00">Month</th>
<th bgcolor="red">Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>";
[htmlString writeToFile:file.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
Once created the file, attach it to an e-mail with XLS extension and open it with Excel.
To try if this solution fits your needs you could create plain text file with your "HTML template" and open it with Excel. Once checked create it programmatically :)
Related videos on Youtube
Jaspreet Singh
Updated on July 11, 2022Comments
-
Jaspreet Singh almost 2 years
i want to generate the application to create the excel file in iPhone sdk. can anybody suggest me to create it.
-
Jaspreet Singh almost 12 years@thanx David H for your suggestion
-
David H almost 12 yearsAs far as I know, this is the only open source library that you could use for this. As you will see its had thousands of downloads and is widely used on a variety of platforms.
-
Muhammad Saqib over 10 yearshi Gagan. Your example is working for me but i cannot add style in the sheet when ever i tried to add style into sheet using the file i am unable to open the sheet
-
Muhammad Saqib over 10 yearsYeah it start working for me thank you :) i want to ask one question how can i set the width of a column is there any way. I'll appreciate you help..
-
Gagan_iOS over 10 yearsthere is property to set width & height. You can find these property in "ReadMe" file on git.
-
i.AsifNoor about 10 yearsThe example given in link "github.com/andreac/RSSheet" does not work properly. When I open the file genered through this example, it says "The file can not be opened".It may be damaged or use a file format that Preview doesn’t recognize.
-
Rushi trivedi over 9 yearsSame problem xls sheet is generated.But when i open file in openoffice it is unble to open.
-
rmaddy almost 9 yearsThis does not create an xls file. It creates an HTML file.
-
Jordi Corominas almost 9 yearsYou're right rmaddy, but this file can be opened with Excel. Maybe it's not a solution that fits all the cases but it's easy to implement and it can work in certain scenarios.
-
Lukas Kalinski over 8 yearsJXLS works great! To see how to use it, look at the PHP documentation of xlslib.
-
Mayank Jain over 7 yearsCan I attach image in it?
-
Aditya about 7 years@Rushi : I am also facing the same problem, when i am creating xls file using RSSheet. Do you have any idea how to solve it?