- (IBAction)exportCSV:(id)sender{ NSLog(@"getFileToSave %@",[sender description]); NSSavePanel *savePanel = [NSSavePanel savePanel]; [savePanel setRequiredFileType:@"csv"]; [savePanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:^(NSInteger result) { if (result == NSOKButton) { [savePanel orderOut:self]; [self application:NSApp saveCSVFile:[savePanel filename]]; } }]; }
- (BOOL)application:(NSApplication *)app saveCSVFile:(NSString *)fn { theData = [myDocument checkbookItemsArray]; [theData retain]; //thePrefs = [myUISettings settings]; //[thePrefs retain]; mA = [NSMutableArray arrayWithCapacity:50]; for (cbi in theData) { lineArray = [NSMutableArray arrayWithCapacity:5]; date = [cbi date]; NSLog(@"%@", [date description]); dateParts = [[date description] componentsSeparatedByString:@" "]; s = [dateParts objectAtIndex:0]; NSLog(@"%@", s); [lineArray addObject:s]; [lineArray addObject:@","]; isDeposit = [[cbi isDeposit] boolValue]; if (isDeposit) { [lineArray addObject:@" "]; } else { [lineArray addObject:[cbi checkNumber]]; } [lineArray addObject:@","]; [lineArray addObject:[cbi name]]; [lineArray addObject:@","]; [lineArray addObject:@"\n"]; line = [lineArray componentsJoinedByString:@""]; [mA addObject:line]; } entry = [mA componentsJoinedByString:@""]; NSLog(@"now, do the save %@", entry); NSError **e; [entry writeToFile:fn atomically:YES encoding:NSASCIIStringEncoding error:e]; [theData release]; //[thePrefs release]; return YES; } |