有没有用于创建Excel(.xlsx)文件的库或示例? [英] Is there a library or example for creating Excel (.xlsx) files?

查看:171
本文介绍了有没有用于创建Excel(.xlsx)文件的库或示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Cocoa应用程序,我试图导出到Excel XML格式(ISO / IEC 29500-1),它基本上是一个zip文件,其中有一堆xml文件,命名为 .xlsx 扩展。

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.

我已经尝试生成苹果脚本并使用 NSAppleScript 创建Excel文件,它工作,但是很慢,用户必须在他们的机器上安装Excel。

I've tried generating apple script and using NSAppleScript to create the Excel file, which works, but is slow and the user has to have Excel installed on their machine.

我可以创建一个简单的 .xlsx 通过将xml写入objective-c中的文件并将其压缩并将zip重命名为 .xlsx 。 Excel可以打开该文件,但是Numbers尝试打开我创建的文件时出现错误。看起来Excel必须已经实现了所有(或大部分)的ISO / IEC规范,而数字只能打开Excel风格的版本。

I was able to create a simple .xlsx Excel file by writing the xml to files in objective-c and zipping them up and re-naming 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.

有任何示例如何使用 cocoa / objective-c 或有助于简化此任务的库来执行此操作?

Are there any examples of how to do this using cocoa/objective-c or a library that would help simplify this task?

推荐答案

我有一个新想法...

I have a new idea...

使用以下代码创建XLS:

Create XLS by following code:

只需创建一个HTML表格

Simply create a table of HTML

NSURL * documentsDirectory = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].lastObject;
NSURL *file = [documentsDirectory URLByAppendingPathComponent:@"contacts.xls"];
NSString* string = @"<table><tr><td>FOO</td><td>BAR</td></tr></table>";
[string writeToFile:file.path atomically:YES encoding:NSUTF8StringEncoding error:nil];

使用Excel打开它。

Open it with Excel.

这篇关于有没有用于创建Excel(.xlsx)文件的库或示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆