Home » excel » xml – excel to plist conversion in cocoa and vice-versa

xml – excel to plist conversion in cocoa and vice-versa

Posted by: admin April 23, 2020 Leave a comment


I want to create a plist file from an excel file. The structure of excel and plist is defined.
Excel file has only two columns, one is “key” and the other is corresponding “value” column.
So the final plist that will be generated is of the form:


Now the problem is that the string values for “keys” and “values” are inturn strings i.e. they are not one word string. They may go more than one line.Hence I can’t use csv file structure here.

Need your urgent help.

Please suggest how to read values from excel sheet so that both column values can be separated.Any sample code will add aid.

How to&Answers:

I accomplished this by writing a formula in excel to create the text of the plist file for you. Its pretty easy.

1) (optional) In XCode, create a plist that has the formatting you want in the end. Save, and go to this in finder. Open it in textWrangler or text edit so that you can see what the tags are for each element in your plist.

For example, you should find something like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">


    <key>First Key Name</key>
        <string>Before God we are all equally wise</string>
        <string>Albert Einstein</string>

    <key>Second Key Name</key>
        <string>Do not worry about your troubles.</string>
        <string>Albert Einstein</string>


2) I will assume:
– Your spreadsheet represents a description of the same 4 properties for many rows/Objects/Levels
– You have each array as a separate row in your spreadsheet
– The same properties are being described for every row in the same order.
– You will be able to access the items in the array by knowing which index they are stored at. ie, I would get the second Author by looking in the second array at index 2.

Your spreadsheet should look something like this:

           A                B            C             D                E            F

     /--(Key Names)--\/-------------------(Properties of Each)-----------------\

1    Level Name      |   Quote        |  Notes  |   Author        |  Favorited  | 
2    First Key Name  |  Before God... |         | Albert Einstein |      0      |
3    Second Key Name |  Do not wor... |         | Albert Einstein |      0      |

So each of my objects will get its own key in my dictionary and each object is described by 3 Strings and an integer.

3) The Formula

On the right of the last column in my spreadsheet, I will write a formula that generates the xml code for that row:

(F2) = CONCATENATE ("<key>",A2,"</key> <array> <string>",B2,"</string> <string>",C2,"</string> <string>",D2,"</string> <integer>",E2,"</integer> </array>")

Drag the lower-right corner of this cell down into all the other rows and they will automatically populate the information for each row.

Similarly, at the bottom of the spreadsheet, under all the rows you can use another formula to concatenate the rows. Say you had 300 rows:

(F4) = CONCATENATE (F2:F300) 

Now copy this data into an text file, and add the last few tags and doctype information, which you can copy from above. save with the extension .plist and you’re good to go! Add the file back into your xcode project and load it like any other plist.


To export data from Excel to a text file, use the Save As command.

There are two commonly used text file formats:

Delimited text files (.txt), in which the TAB character (ASCII character code 009) typically separates each field of text.

Comma separated values text files (.csv), in which the comma character (,) typically separates each field of text.

You can change the separator character that is used.