I am trying to create a report in Excel format, ready to be sent by email. So far I have found that the best and simplest way is to create an xml document as follows and save it as 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>
Then I could save this document using
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];
However, after I send the email and try to open the xls file, the xml is displayed in the spreadsheet instead. Could anyone please lead me to the right direction to create this xls file?
I tried the same thing as the OP, and gave up. I eventually used libxls to open and read xls files, and wrote the files out using csv. (libxls can't write xls, just read it).
http://libxls.sourceforge.net
I haven't tried it, but xlslib claims to write excel files. It has an update in Jan 6 2014 saying it can work in iOS:
http://sourceforge.net/projects/xlslib/files/
Also, read why it's so hard to write excel files, because it's true and funny: http://www.joelonsoftware.com/items/2008/02/19.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With