में डेटा की सरणी से सीएसवी फ़ाइल बनाएं मैं एसक्यूएल फ़ाइल से सीएसवी फ़ाइल में डेटा लिखना चाहता हूं। मैंने एसक्यूएल फ़ाइल से सभी डेटा एक सरणी में एकत्र किया है और लूप के लिए उपयोग कर रहा हूं, मैं .csv फ़ाइल में डेटा जोड़ रहा हूं और लिख रहा हूं। लेकिन ऐसा लगता है कि यह एक पंक्ति में डेटा दिखाता है केवल नई पंक्ति बनाने के लिए यह नई लाइन पर नहीं जाता है। मैंने संदर्भ के लिए this का उपयोग किया है।आईओएस
-(NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@"myfile.csv"];
}
- (IBAction)saveAsFileAction:(id)sender {
if (![[NSFileManager defaultManager] fileExistsAtPath:[self dataFilePath]]) {
[[NSFileManager defaultManager] createFileAtPath: [self dataFilePath] contents:nil attributes:nil];
NSLog(@"Route creato");
}
NSString *writeString;
for (int i=0; i<[dataArray count]; i++) {
writeString = [NSString stringWithFormat:@"%@, %@, %@, %@, %0.2f,",[[dataArray objectAtIndex:i]dates],[[dataArray objectAtIndex:i] time],[[dataArray objectAtIndex:i] category],[[dataArray objectAtIndex:i]place],[[dataArray objectAtIndex:i] amount]];
NSLog(@"writeString :%@",writeString);
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]];
}
}
धन्यवाद। कोड पूरी तरह से ठीक काम कर रहा है .. धन्यवाद। –
कोई समस्या नहीं, मदद करने में खुशी हुई। – sosborn
अरे क्या आप जानते हैं कि सीएसवी फ़ाइल से उसी डेटा को वापस कैसे प्राप्त किया जाए? @Prernachavan – iSwaroop