Group Group Group Group Group Group Group Group Group

How do I copy a NSTableView data using PasteBoard?

I’m trying to copy NSTableView data using pasteboard and want to paste it as a table in Microsoft Word. How should I do this?

I have tried copying TableView Data source as string but not able to copy the TableView itself.

    NSPasteboard *pasteboard=[NSPasteboard generalPasteboard];

    //_fillvalue,_levelfill(Mutable array) are the data source for my tableview with 2 column

    [pasteboard clearContents];
    int i=0;
    NSMutableArray *tval=[[NSMutableArray alloc]init];
    NSInteger row=[_tableView numberOfRows]; 

    for(i=0;i<(int)row;i++){

        NSString *s1=[_levelfill objectAtIndex:i]; //levelfill is datasource array

        NSLog(@"s1 value is  %@",s1);
        NSString *s2=[_fillvalue objectAtIndex:i];
        s1=[s1 stringByAppendingString:@"  "];
        s1=[s1 stringByAppendingString:s2];
        [tval addObject:s1];

    }
    [pasteboard writeObjects:tval];

I expect the output to be copied from tableview rather than datasource of tableview. Also is there a way to copy as a table itself which can be pasted as table directly in Microsoft word.

Hi @vivekstorm,
the way to do that is using a HTML format, that will then be copied as a table instead of plain text.

cheers,

Hi, Thank You. I tried using HTML format, it worked!