我正在尝试创建 Excel 格式的报告,准备通过电子邮件发送。到目前为止,我发现最好、最简单的方法是创建一个 xml 文档,如下所示,并将其另存为 xls。
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1">
<Row>
<Cell><Data ss:Type="String">Name</Data></Cell>
<Cell><Data ss:Type="String">Example</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">Value</Data></Cell>
<Cell><Data ss:Type="Number">123</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
然后我可以使用保存该文档
NSArray *documentDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [NSString stringWithFormat:@"%@/Report.xls", [documentDirectoryPath objectAtIndex:0]];
[xmlString writeToFile:docDir atomically:YES encoding:NSUTF8StringEncoding error:NULL];
[serializedData writeToFile:docDir atomically:YES];
但是,在我发送电子邮件并尝试打开 xls 文件后,xml 反而显示在电子表格中。谁能引导我找到创建此 xls 文件的正确方向?
我尝试了与OP相同的方法,然后放弃了。我最终使用 libxls 打开和读取 xls 文件,并使用 csv 将文件写出。 (libxls不能写xls,只能读取)。
http://libxls.sourceforge.net http://libxls.sourceforge.net
我没有尝试过,但xlslib声称可以写入excel文件。它于 2014 年 1 月 6 日进行了更新,表示可以在 iOS 上运行:
http://sourceforge.net/projects/xlslib/files/ http://sourceforge.net/projects/xlslib/files/
另外,请阅读为什么编写 Excel 文件如此困难,因为它是真实且有趣的:http://www.joelonsoftware.com/items/2008/02/19.html http://www.joelonsoftware.com/items/2008/02/19.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)