C语言 在 Objective-C (iPhone) 中从 Excel 文件中读取数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3516129/
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
Read data from Excel file in Objective-C (iPhone)
提问by Marin Todorov
I've searched in google but I don't seem to find a way to read Excel files from Objective-C. The only answers I find are to first convert to CSV and then read as a text file, but I don't want that.
我在谷歌搜索过,但似乎没有找到从 Objective-C 读取 Excel 文件的方法。我找到的唯一答案是先转换为 CSV,然后作为文本文件读取,但我不想要那样。
I know there must be a way, while I used many times the PHP modules to read/write Excel files, so I'm supposing there's also a C library to do that (which then could be used in Objective-C/iPhone app)
我知道一定有办法,虽然我多次使用 PHP 模块来读/写 Excel 文件,所以我假设还有一个 C 库可以做到这一点(然后可以在 Objective-C/iPhone 应用程序中使用)
So ... does anyone know of such a library I could use on the iPhone?
那么......有谁知道我可以在 iPhone 上使用的这样一个库?
采纳答案by David H
Actually, there is such a project - its called libxlson source forge. There is a ObjectiveC class interface to the project as well. With this project you can open an excel file, and read most of the information in it (cell values as well as the file's properties).
实际上,有一个这样的项目——它在 source forge上被称为libxls。该项目还有一个 ObjectiveC 类接口。使用此项目,您可以打开一个 excel 文件,并读取其中的大部分信息(单元格值以及文件的属性)。
In addition there is an iOS Objective C interfaceto the library.
此外,该库还有一个iOS Objective C 接口。
回答by rjw
I think the PHP libraries use the Office OpenXML formats... The best library for reading/writing binary Excel files ( without running Excel itself and calling it via COM ) I've used is Apache POI - http://poi.apache.org/, but this is Java. You could attempt to use GCJ to get that working on the iPhone, but who knows what Apple would make of it. You could manually port the whole thing to Obj-C/ C++ I guess...
我认为 PHP 库使用 Office OpenXML 格式...我使用过的用于读取/写入二进制 Excel 文件的最佳库(不运行 Excel 本身并通过 COM 调用)是 Apache POI - http://poi.apache。 org/,但这是Java。你可以尝试使用 GCJ 来让它在 iPhone 上运行,但谁知道苹果会怎么做。你可以手动将整个东西移植到 Obj-C/C++ 我猜...
There are a few C / C++ libraries that do a limited subset, but they probably are not incredibly reliable or simple to use.
有一些 C/C++ 库可以执行有限的子集,但它们可能不是非常可靠或易于使用。
http://xlslib.sourceforge.net/index.php- LGPL
http://xlslib.sourceforge.net/index.php- LGPL
http://www.libxl.com/- Commercial, $199, who knows if they would give you source for that to compile into your app.
http://www.libxl.com/- 商业版,199 美元,谁知道他们是否会为您提供源代码以编译到您的应用程序中。
http://www.codeproject.com/KB/office/ExcelFormat.aspx- C++ source, incredibly unclear licence like everything on code project. Who knows.
http://www.codeproject.com/KB/office/ExcelFormat.aspx- C++ 源代码,像代码项目上的所有内容一样令人难以置信的不清楚的许可证。谁知道。
Another option is to attempt to extract the code from an open source excel reading competitor. Open Office - http://www.openoffice.org/- is likely to be a complete nightmare, Gnumeric is probably a better bet. Excel code is here - http://git.gnome.org/browse/gnumeric/tree/plugins/excel- its likely to need a lot of messing about to make it work outside Gnumeric. KSpread has similar code here : http://websvn.kde.org/trunk/koffice/filters/kspread/excel/import/, but I believe Gnumeric has a better reputation for accuracy wrt to Excel import.
另一种选择是尝试从开源 excel 阅读竞争对手中提取代码。Open Office - http://www.openoffice.org/- 可能是一场彻头彻尾的噩梦,Gnumeric 可能是更好的选择。Excel 代码在这里 - http://git.gnome.org/browse/gnumeric/tree/plugins/excel- 它可能需要大量的混乱才能使它在 Gnumeric 之外工作。KSpread 在这里有类似的代码:http://websvn.kde.org/trunk/koffice/filters/kspread/excel/import/ ,但我相信 Gnumeric 在 Excel 导入的准确性方面享有更好的声誉。
回答by Robot1987
回答by olivaresF
I recently got into a project where the client wanted to import information from an Excel file into an app. I know a lotof people say, just transform it into a CSV and parse it that way, but I really didn't want the client to go through yet another step and introduce a different file format - as simple as that may be.
我最近进入了一个项目,客户希望将信息从 Excel 文件导入到应用程序中。我知道很多人说,只需将其转换为 CSV 并以这种方式解析它,但我真的不希望客户端再执行另一个步骤并引入不同的文件格式 - 就这么简单。
I tried using DHlibxls, but I felt it was a little bit too complicated, so I created QZXLSReader.It's a drag-and-drop solution so it's a lot easier to use. I don't think it's as feature complete, but it worked for me.
我尝试使用DHlibxls,但我觉得它有点太复杂了,所以我创建了QZXLSReader。这是一个拖放式解决方案,因此使用起来要容易得多。我不认为它的功能完整,但它对我有用。
It's basically a library that can open XLS files and parse them into Obj-C classes. Once you have the classes, it's very easy to send them to Core Data or a dictionary or what have you.
它基本上是一个可以打开 XLS 文件并将它们解析为 Obj-C 类的库。一旦你有了这些类,就很容易将它们发送到 Core Data 或字典或你拥有的东西。
I hope it helps!
我希望它有帮助!
回答by rbbtsn0w
Other way, some where use libxls.
其他方式,有些地方使用 libxls。
any way, more choose:
无论如何,更多选择:

