xcode 如何在 iPhone sdk 中创建 Excel 表格和文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11775661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:06:52  来源:igfitidea点击:

How can i create excel sheet and file in iPhone sdk?

iphoneiosxcodeios4ms-office

提问by Jaspreet Singh

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

我想生成应用程序以在 iPhone sdk 中创建 excel 文件。任何人都可以建议我创建它。

回答by David H

Well, the right guy saw your post! There is an open source C++ library on SourceForge, xlslib, that will do exactly what you need.

嗯,对的人看到了你的帖子!SourceForge 上有一个开源 C++ 库xlslib,它可以完全满足您的需求。

But wait - there's even more! There is a Objective-C wrapperto that library - its a bit out of date but recently someone reported that they got it to work on iOS.

但是等等 - 还有更多!该库有一个 Objective-C包装器- 它有点过时,但最近有人报告说他们让它在 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.

支持这个库的两个人似乎对用户非常敏感,所以如果人们正在使用它,他们很可能会继续支持 ObjectiveC 包装器。

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.

也就是说,没有开箱即用的库/框架可以坚持您的项目。您将需要花一些时间,甚至一两天,才能在 iOS 上构建和运行该东西。如果你赶时间,你将不得不花时间。如果你有耐心,你可能会得到帮助。

EDIT: there is an ObjectiveC framework using this library: JXLS.

编辑:有一个使用这个库的 ObjectiveC 框架:JXLS

回答by Gagan_iOS

I found a link on github. Just add these few files & follow instruction for integrating code(easy to integrate).

我在github上找到了一个链接。只需添加这几个文件并遵循集成代码的说明(易于集成)。

Here is Link
https://github.com/andreac/RSSheet

这是链接
https://github.com/andreac/RSSheet

Please convert these files into ARC to avoid crashing due to memory management. Hope it works.

请将这些文件转换为ARC,以免因内存管理而崩溃。希望它有效。

回答by Jordi Corominas

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.

如果您的 Excel 文件不是很复杂,另一种选择是使用 HTML 表格。我试过了,效果很好。

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>0</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.

创建文件后,将其附加到扩展名为 XLS 的电子邮件中,然后用 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 :)

要尝试此解决方案是否符合您的需求,您可以使用“HTML 模板”创建纯文本文件并使用 Excel 将其打开。检查后以编程方式创建它:)