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 ~~