6列のテーブルがあります。
CSVに書き込んでメールに添付したい。
どうやって作るの?
-(void)generateCSV
{
//create instance of NSFileManager
NSFileManager *fileManager = [NSFileManager defaultManager];
//create an array and store result of our search for the documents directory in it
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//create NSString object, that holds our exact path to the documents directory
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"Document Dir: %@",documentsDirectory);
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.csv", @"userdata"]]; //add our file to the path
[fileManager createFileAtPath:fullPath contents:[@"" dataUsingEncoding:NSUTF8StringEncoding] attributes:nil]; //finally save the path (file)
surveyarray = [db retrieveSurvey];
CHCSVWriter * csvWriter = [[CHCSVWriter alloc] initWithCSVFile:fullPath atomic:NO];
NSInteger numberOfColumns = 5;
for (NSInteger currentIndex = 0; currentIndex < [surveyarray count]; currentIndex++) {
id field = [surveyarray objectAtIndex:currentIndex];
[csvWriter writeField:field];
if ((currentIndex % numberOfColumns) == (numberOfColumns - 1)) {
[csvWriter writeLine];
}
}
[csvWriter release];
}
これが私の現在の機能です。csv ファイルはどこにありますか、または生成されますか?