File encoding issues with Excel file to plist file

Source: Internet
Author: User

Today, when testing, I encountered the need to convert a large amount of collated Excel data into a plist file. Baidu has a tutorial, found that although others have encountered similar situations, but some of the talk is not enough detail. So do the following. Baidu to the content of the use of mesasqlite, because there is no way, not to mention here temporarily. The actual process is as follows: 1. Convert the Excel file to a Notepad file. Copy and paste it out, this part of the operation I was under Windows, using Excel and notepad++. Using the default action also causes some problems later. 2. Directly drag the converted Notepad file into the Xcode resource folder, click Preview to the situation as follows, garbled: forced to run the program conversion, the program did not error, but the resulting plist file only the file header, the actual valid data is empty. The code is as follows:
      NSString *alarmpath = [[NSBundle mainbundle] pathforresource:@ "gsk980m" oftype:@ "TXT"];//NSLog (@ "%@", Alarmpath);    Attempt to change file encoding, failed//nsstringencoding GBK = cfstringconvertencodingtonsstringencoding (kcfstringencodinggb_18030_2000); NSString *alarmcontent = [[NSString alloc] Initwithcontentsoffile:alarmpath encoding:nsutf8stringencoding Error:nil]        ;//NSLog (@ "%@", alarmcontent);    Nsarray *alarmarray = [Alarmcontent componentsseparatedbycharactersinset:[nscharacterset newlineCharacterSet]];//    NSLog (@ "%@", Alarmarray);    NSString *docupath = [Nshomedirectory () stringbyappendingpathcomponent:@ "Documents"];    NSString *plistpath = [Docupath stringbyappendingpathcomponent:@ "Gsk980m.plist"];    NSLog (@ "%@", Plistpath);    Nsmutablearray *resultsarr = [Nsmutablearray array]; for (Nsinteger j = 0; J < Alarmarray.count; J + +) {nsstring *alarmstr = [Alarmarray objectatindex:j];//NS        Log (@ "%@", alarmstr); Nsarray *alarmarr = [Alarmstr componentsseparAtedbystring:@ ";"]; [Resultsarr addobject:@{@ "Alarmid": [Alarmarr objectatindex:0],@ "Alarmtype": [Alarmarr objectatindex:1],@ "Alarm": [    Alarmarr objectatindex:2],@ "ClearType": [Alarmarr objectatindex:3],@ "alarmcontent": [Alarmarr Objectatindex:4]}]; } [Resultsarr Writetofile:plistpath atomically:yes];

  

3. Search, confirm the issue of file encoding. Start by thinking about converting the encoding of the Notepad file, using the text editing that comes with your Mac. The app does not find the option to save as UTF-8. Continue Baidu, get the key information.Press the shortcut key in the text editor: Shift?+command?+t. When you save it, it will appear: then save it. 4. At this point, re-drag the file into the resource directory, the preview has been shown normal: Rerun the program to get the required plist file.

File encoding issues with Excel file to plist file

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.