我有一个有 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 文件或生成的文件?