次のコードで .csv ファイルを作成しています
-(NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@"myfile.csv"];
}
-(void)createfile{
if (![[NSFileManager defaultManager] fileExistsAtPath:[self dataFilePath]]) {
[[NSFileManager defaultManager] createFileAtPath: [self dataFilePath] contents:nil attributes:nil];
}
for (int i=0; i<[arr count]; i++) {
NSString *_amnt = [[self.reversedArr objectAtIndex:i] valueForKey:@"amount"];
writeString = [NSString stringWithFormat:@"%@,%@,%@", [[arr objectAtIndex:i] valueForKey:@"date"], [[arr objectAtIndex:i] valueForKey:@"particular", [NSString stringWithFormat:@"%@\n", _amnt]];
}
NSFileHandle *handle;
handle = [NSFileHandle fileHandleForWritingAtPath: [self dataFilePath] ];
//say to handle where's the file fo write
[handle truncateFileAtOffset:[handle seekToEndOfFile]];
//position handle cursor to the end of file
[handle writeData:[writeString dataUsingEncoding:NSUTF8StringEncoding]];
}
私はcsvファイルを作成することに成功しましたが、.csvファイルをExcelシートで開いているときに問題が発生し、文字数に応じて列幅を拡張し、文字数に応じてテキストを折り返す必要がありますが、列幅を固定する必要があります。行の高さを拡張する必要があります。では、このタスクのために何をすべきか。誰でも提案できますか。