I am creating .csv file with following code
-(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]];
}
I am successful to create csv file but I am having a problem when I am opening the .csv file in excel sheet then any row who having more characters , extending its column width according to characters but I need to wrap text with fixed column width , row height should be extend. So what should I do for this task. can any one give suggestion .