简体   繁体   中英

Export data to csv format file in mac app

I'm new to mac app development.

I have set of data in the nstableview and i need to save this data in .cs format progarmmatically.

-(IBAction)exportInvoice:(id)sender
{
    AppDelegate *appDelegate = [NSApp delegate];
     NSString *tempStr = [NSString stringWithFormat:@"%@", [OrderModel getInitialOrderBITToDisplay:[appDelegate getDBPath]]];
    NSArray* commaSeparatedObjects = [tempStr componentsSeparatedByString:@","];
    //NSString *commaSeparatedObjects = [tempStr componentsJoinedByString:@","];
    NSLog(@"%@",commaSeparatedObjects);

    NSSavePanel *pdfSavingDialog = [NSSavePanel savePanel];

    [pdfSavingDialog setRequiredFileType:@"csv"];

    if ( [pdfSavingDialog runModalForDirectory:nil file:nil] == NSOKButton ) {
       // NSData *dataForPDF = [self exportPdfData];
        NSData *dataForPDF = [NSKeyedArchiver archivedDataWithRootObject:commaSeparatedObjects];
        NSLog(@"%@",dataForPDF);
        [dataForPDF writeToFile:[pdfSavingDialog filename] atomically:NO];

    }
}

Can anyone help me to sort the problem?

您应该查看 CHCSVParser: https : //github.com/davedelong/CHCSVParser希望有所帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM