This article guides you how to create Excel readable XML format using xcode. Here are some points you must take care -
First create a NSMutableString variable
NSMutableString *excel = [[NSMutableString alloc] init];
and then build up your string with a header, then the spreadsheet header, then data and finally a closing section.
1. Header - Below lines should be added to the start of XML string -
2. Add the following code to create Worksheets and Table headings -
[excel appendString:@"<Worksheet ss:Name=\"User\">"];
[excel appendString:@"<Table ss:ExpandedColumnCount=\"8\" ss:ExpandedRowCount=\"2\" x:FullColumns=\"1\" x:FullRows=\"1\">"];
[excel appendString:@"<Row>"];
[excel appendString:@"<Cell><Data ss:Type=\"String\">TraineeDetailID</Data></Cell>"];
[excel appendString:@"<Cell><Data ss:Type=\"String\">Name</Data></Cell>"];
[excel appendString:@"<Cell><Data ss:Type=\"String\">DOB</Data></Cell>"];
[excel appendString:@"<Cell><Data ss:Type=\"String\">HeightFeet</Data></Cell>"]; [excel appendString:@"<Cell><Data ss:Type=\"String\">HeightInches</Data></Cell>"];
[excel appendString:@"<Cell><Data ss:Type=\"String\">Weight</Data></Cell>"];
[excel appendString:@"<Cell><Data ss:Type=\"String\">ImageFile</Data></Cell>"];
[excel appendString:@"<Cell><Data ss:Type=\"String\">BMI</Data></Cell></Row>"];
"ss:Name" will be the name of your worksheet
"ss:ExpandedColumnCount=\"8\" - number of columns of the table.
"ss:ExpandedRowCount=\"2\" - number of rows.
Above, I have then defined the column headers (just for an example). They are the ones beginning with <Cell>
After this add your dynamic data for each column using loop or whatever way you prefer. Like
I have tried above sample XML file and save as .xls file but its gave, unsupported formate message before open saved file in MS while in Open Office, whole XML was showing in column A.
Try to save as .xml format. Its extension will be .xml but this file can be open in Excel. Also default application to open this file will be Excel. You can see the Excel icon.
I have tried same as you mentioned but not getting success for it.
I have download EE.xml and try to open in Excel but give error as well as i wrote code as your article and save file as xml and xls but same result.
Can you provide more detail or your sample code so i will get the proper result.
Thanks
Have a question about something in this article?
You can receive help directly from the article author.
Sign up for a free trial to get started.
Comments (3)
Commented:
I have tried above sample XML file and save as .xls file but its gave, unsupported formate message before open saved file in MS while in Open Office, whole XML was showing in column A.
Can you explain solution for it?
thanks
Author
Commented:Thanks
Commented:
I have download EE.xml and try to open in Excel but give error as well as i wrote code as your article and save file as xml and xls but same result.
Can you provide more detail or your sample code so i will get the proper result.
Thanks