How can i create excel sheet and file in iPhone sd

2019-02-01 02:50发布

问题:

i want to generate the application to create the excel file in iPhone sdk. can anybody suggest me to create it.

回答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.



回答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.



回答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 :)



回答4:

http://www.youtube.com/watch?v=9NRDEFwaVE0

This allows you to save a file to your documents directory. You could change the file type. I am not sure how you could edit a csv file though.