在我的應用程序中,我創建了一個.plist文件,但我需要使用存儲在此.plist中的數據存儲在Excel表中。我需要一種方法來獲得這個plist的csv。我試圖在網上搜索,但我發現只有轉換器允許從csv創建一個plist。我想有一種方法可以直接從我的iPad應用程序生成csv文件。有誰知道一種方法來做到這一點?從NSMutableArray創建一個csv
UPDATE:
+ (void)saveFileFromArray:(NSMutableArray *)promoArray {
NSMutableString *target = [@"Nome,Cognome,E-mail,Data di nascita,Indirizzo,Città,Cap,Telefono\n" mutableCopy];
for (NSDictionary *dict in promoArray) {
[target appendFormat:@"%@,%@,%@,%@,%@,%@,%@,%@\n",dict[@"name"],dict[@"surname"],dict[@"email"],dict[@"birthdate"],dict[@"address"],dict[@"city"],dict[@"zip"],dict[@"phone"]];
}
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"profiles.csv"];
NSURL *url = [NSURL URLWithString:fileName];
BOOL success = [target writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (!success) {
NSLog(@"Errore: %@", error.localizedDescription);
}
}
在應用程序中將plist轉換爲CSV,然後導出文件,以便在Excel中訪問... http://stackoverflow.com/questions/10119035/create-csv-file-from-array-of- data-in-ios – Tim