Convert Excel document (xls) to a plist

2019-01-16 06:45发布

I have a pretty straightforward Excel spreadsheet, and I need to use the data in an iPhone app. The xls document has 6 columns, and > 200 rows.

I would like to create a plist from the xls document. How can I convert one to the other, programmatically?

标签: iphone plist xls
7条回答
来,给爷笑一个
2楼-- · 2019-01-16 07:12

Use http://shancarter.github.io/mr-data-converter/ to convert xls to a Json(just copy & paste)(can re format it by remove white space in http://jsonviewer.stack.hu/). save json to text file named: in.json.

Use plutil command to format json to plist

plutil -convert xml1 in.json -o out.plist
查看更多
在下西门庆
3楼-- · 2019-01-16 07:18

Ladies and gentlemen,

I tried any other recommended solutions above but because of Unicode characters in my language (Turkish) none of them worked out for me... All unicode characters were all broken. Then I decided to make a tool for this.

I proudly present the simplest way to convert any XLS or XLSX or CVS file to a plist:

http://exceltoplist.herokuapp.com/

Just upload your XLS, XLSX or CSV and download your Apple Plist!

Enjoy!

Note: Because of Heroku's free dyno policy it might take a few moments to browse the page. Just keep waiting for 5-10 seconds to open page.

查看更多
我命由我不由天
4楼-- · 2019-01-16 07:24

For OpenOffice, use this formula

=CONCATENATE("<key>number</key><integer>"; A2;"</integer><key>MyString</key><string>";B2;"</string>")
查看更多
Viruses.
5楼-- · 2019-01-16 07:30

I'm late to the party but I built a desktop utility that will convert CSV to a plist. You can download the binary or use this code, which requires cCSVParse. It uses whatever is in row 0 to create key names, then generates dictionaries for each successive row.

    CSVParser *parser = [CSVParser new];
[parser openFileWithPath:pathAsString];
NSMutableArray *csvContent = [parser parseFile];
[parser closeFile];

if (pathAsString != nil)
{

    NSArray *keyArray = [csvContent objectAtIndex:0];

    NSMutableArray *plistOutputArray = [NSMutableArray array];

    NSInteger i = 0;

    for (NSArray *array in csvContent)
    {



        NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];

        NSInteger keyNumber = 0;

        for (NSString *string in array)
        {

            [dictionary setObject:string forKey:[keyArray objectAtIndex:keyNumber]];

            keyNumber++;

        }

        if (i > 0)
        {
            [plistOutputArray addObject:dictionary];
        }

        i++;

    }

    NSMutableString *mutableString = [NSMutableString stringWithString:pathAsString];
    [mutableString replaceOccurrencesOfString:@".csv" withString:@".plist" options:nil range:NSMakeRange([mutableString length]-4, 4)];

    NSURL *url = [NSURL fileURLWithPath:mutableString];


    [plistOutputArray writeToURL:url atomically:YES];
查看更多
forever°为你锁心
6楼-- · 2019-01-16 07:34

I found the CONCATENATE to work the best for this.

查看更多
霸刀☆藐视天下
7楼-- · 2019-01-16 07:35

For my purpose I just need to convert CSV with two columns to plist file. First column is keys and second are values. So, I slightly change Danilo Campos code as following:

CSVParser *parser = [CSVParser new];
[parser openFileWithPath:pathAsString];
NSMutableArray *csvContent = [parser parseFile];
[parser closeFile];

if (pathAsString != nil)
{
    NSMutableDictionary *plistOutputArray = [NSMutableDictionary dictionary];

    for (NSArray *array in csvContent)
    {
        NSString *key = (NSString *)([array objectAtIndex:0]);
        NSString *value = (NSString *)([array objectAtIndex:1]);

        [plistOutputArray setObject:value forKey:key];
    }

    NSMutableString *mutableString = [NSMutableString stringWithString:pathAsString];
    [mutableString replaceOccurrencesOfString:@".csv" withString:@".plist" options:nil range:NSMakeRange([mutableString length]-4, 4)];

    NSURL *url = [NSURL fileURLWithPath:mutableString];

    [plistOutputArray writeToURL:url atomically:YES];
}

P.S. You can find his initial source code here - http://code.google.com/p/danilobits/source/checkout Please note that to get his code work now you need to change "Base SDK" to "Latest OS X"

查看更多
登录 后发表回答