在 Cocoa 中创建 Excel (.xlsx) 文件
我正在编写一个 Cocoa 应用程序,并尝试导出为 Excel XML 格式(ISO/IEC 29500-1),该格式基本上是一个 zip 文件,其中包含一堆以 .xlsx< 命名的 XML 文件。 /代码> 扩展名。
我尝试生成 AppleScript 并使用 NSAppleScript 创建 Excel 文件,该文件可以工作,但速度很慢,并且用户必须在其计算机上安装 Excel。
我能够通过将 XML 写入 Objective C 中的文件并压缩它们并将该 zip 重命名为 .xlsx
来创建一个简单的 .xlsx Excel 文件。 Excel 可以打开该文件,但 Numbers 尝试打开我创建的文件时抛出错误。看来 Excel 必须实现了全部(或大部分)ISO/IEC 规范,而 Numbers 可能只能打开 Excel 风格的版本。
如何使用 Cocoa 和 Objective-c 创建工作 Excel 文件?
I'm writing a Cocoa application and I'm trying to export to the Excel XML format (ISO/IEC 29500-1) which is basically a zip file with a bunch of XML files in it named with a .xlsx
extension.
I've tried generating AppleScript and using NSAppleScript
to create the Excel file, which works, but is slow and the user has to have Excel installed on their machine.
I was able to create a simple .xlsx Excel file by writing the XML to files in Objective C and zipping them up and renaming the zip to .xlsx
. Excel could open the file, but Numbers threw an error trying to open the file I created. It seems Excel must have implemented all (or most of) the ISO/IEC spec, while Numbers may only open the Excel flavored version.
How to create working Excel files using Cocoa and Objective-c?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 HTML 表格封装在 Excel 文件中怎么样?我已经检查过它是否有效,并且可以使用 Excel 打开它。
How about encapsulating HTML table in Excel file? I have checked that this works and I can open it with Excel.
我使用过 OpenOffice API,效果非常好。我建议您使用它来创建 Excel 文件。如果您没有时间/耐心来执行此操作,解决方法可能是提供 2 个导出文件链接,即针对世界各地 Excel 的 XLSX 版本 hack,然后为 Numbers 应用程序单独导出 CSV 文件。
I've worked with the OpenOffice API and it works great. I would suggest you work with that to create your Excel files. If you don't have time time/patience to do that, a workaround could be to have 2 links to export files, the XLSX version hack for the Excels of the world and then a separate exported CSV file for the Numbers application.
Wikipedia 提供了一些库链接,这可能会给您一个良好的开端。
如果不需要 Office Open XML 格式,并且不需要导出过于复杂的文件,我还建议检查将文件保存为 Excel 也可以读取的样式表格式的 HTML。了解如何将所需的 HTML 设置为电子表格格式的简单方法是在 Excel 中创建文件并将其另存为 HTML。
Wikipedia offers some links to libraries, which would probably give you a good start.
If the Office Open XML format isn't a requirement, and you don't need overly complex files exported, I also suggest checking saving the files as stylesheet formatted HTML which Excel can also read. A simple way to learn how to format the HTML you want as a spreadsheet is creating the file in Excel, and saving it as HTML.