iPhoneアプリで、SQLiteデータベースファイルをCSVファイルにエクスポートしたい。(後でこのファイルをメールで添付します)
それも表形式(またはExcelシート形式)で
次のロジックを試しましたが、テーブル形式や列の配置の大きな違いとは異なります。
StoredataBaseArray=[データベースselectAllFromDB];
NSString *CSVstring=@"SNO \t\t\t Index \t\t\t Definition\n" ;
NSString *CSVPath,*record;;
NSString *temporayCSV= @"" ;
for(int i=0;i<storedataBaseArray.count ;i++)
{
record = [NSString stringWithFormat:@"%@, \t\t\t %@, \t\t\t %@, [ [storedContactsArray objectAtIndex:i] objectForKey"id"] , [ [storedContactsArray objectAtIndex:i] objectForKey"title"], [ [storedContactsArray objectAtIndex:i] objectForKey"Definition"]];
// NSString *role =[storedContactsArray objectAtIndex:i] ;
NSLog(@"%d",i);
temporayCSV = [NSString stringWithFormat:@"%d %@ \n ",(i+1),record];
CSVstring = [CSVstring stringByAppendingFormat:temporayCSV];
NSLog(@"%@",CSVstring);
}
CSVPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.csv", @"CSV_FormatedTable"]];
//add our file to the path
[fileManager createFileAtPath:CSVPath contents:[CSVstring dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
NSData *rolesCSVData =[NSData dataWithContentsOfFile:CSVPath];
[mailpage addAttachmentData:rolesCSVData mimeType:@"text/csv" fileName:@"CSV_FormatedTable.csv"];
データベースファイル:
必要な形式:
My Out Put CSVファイル:
誰かが私にこれを行う方法を提案できますか