Convert the content in Excel into a plist File

Source: Internet
Author: User

I encountered a problem today. The content is described as follows:
There is an Excel file with hundreds of thousands of rows of data, for example:

Name number content .......
Zhang San 12132 xxxxxxxxxx
Lili 321321 yyyyyyy
....

I wanted to apply the data to the app, but I couldn't find a proper method. I originally wanted to convert the data to SQLite. I found the SQLite management tool on MAC for a long time, but it was too troublesome to find it, simply store the data as a dictionary in an array. The method is as follows:
1. Convert the Excel file to a CSV file (note: The text encoding problem may occur here. I copied and pasted the contents of the CSV file as txt );
2. Code: the key code is as follows:
Nsstring * Path = [[nsbundle mainbundle] pathforresource: @ "4" oftype: @ "TXT"];

Nsstring * Contents = [[nsstring alloc] initwithcontentsoffile: path encoding: nsutf8stringencoding error: Nil];

Nsarray * contentsarray = [contents componentsseparatedbycharactersinset: [nscharacterset newlinecharacterset];


Nsstring * docs = [nshomedirectory () stringbyappendingpathcomponent: @ "Documents/xxxx. plist"];

Nsmutablearray * arr = [[nsmutablearray alloc] init];



Nsinteger idx;

For (idx = 0; idx <contentsarray. Count; idx ++ ){

Nsstring * currentcontent = [contentsarray objectatindex: idx];

Nsarray * timedataarr = [currentcontent componentsseparatedbycharactersinset: [nscharacterset charactersetwithcharactersinstring: @ ";"];

Nsmutabledictionary * DIC = [[nsmutabledictionary alloc] init];

[DIC setobject: [timedataarr objectatindex: 0] forkey: @ "name"];

[DIC setobject: [timedataarr objectatindex: 1] forkey: @ "Number"];

[DIC setobject: [timedataarr objectatindex: 2] forkey: @ "content"];

[Arr addobject: DIC];

}

[Arr writetofile: Docs atomically: Yes];
3. The next time you want to use this data, you can directly read it from plist ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.