我正在尝试创建 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 文件?