NSTableView - Let user copy rows into excel

Hello together,


I have a problem with my Table. In the moment it is not possible to copy the rows and to paste them into excel. But that is how it has to work like.

Can anybody help me? It is the last step for me to finish my programm but I am a Newbie and I have no idea and I didn't found the right snippet.


Here is my code:


extension FourthViewController: NSTableViewDataSource, NSTableViewDelegate {
  
    func numberOfRowsInTableView(tableView: NSTableView) -> Int {
        let numberOfRows:Int = getDataArray().count
        return numberOfRows
    }
  
    func tableView(tableView: NSTableView!, objectValueForTableColumn tableColumn: NSTableColumn!, row: Int) -> AnyObject!
    {
      
        let newString = getDataArray().objectAtIndex(row).objectForKey(tableColumn.identifier)
        return newString;
    }
  
    func getDataArray () -> NSArray{
        var dataArray:[NSDictionary] = [["Erste": "Mary", "Zweite": "Jane"]];
        dataArray.removeAll()
        /
        let style = NSMutableParagraphStyle()
        style.alignment = .Right
        let myAttribute = [
            NSFontAttributeName: NSFont.boldSystemFontOfSize(13),
            NSParagraphStyleAttributeName: style
        ]   
      
        if AMesse > 0 {
            dataArray += [["Erste": String(format:"\(AMesse) x Messe Kategorie A à %.2f Euro (netto)",locale: de,AMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(AMesse) * AMessePreis))]]
        }
      
        if BMesse > 0 {
            dataArray += [["Erste": String(format:"\(BMesse) x Messe Kategorie B à %.2f Euro (netto)",locale: de,BMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(BMesse) * BMessePreis))]]
        }
      
        if CMesse > 0 {
            dataArray += [["Erste": String(format:"\(CMesse) x Messe Kategorie C à %.2f Euro (netto)",locale: de,CMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(CMesse) * CMessePreis))]]
        }
      
        if DMesse > 0 {
            dataArray += [["Erste": String(format:"\(DMesse) x Messe Kategorie D à %.2f Euro (netto)",locale: de,DMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(DMesse) * DMessePreis))]]
        }
      
        if EMesse > 0 {
            dataArray += [["Erste": String(format:"\(EMesse) x Eintägige Messe à %.2f Euro (netto)",locale: de,EMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(EMesse) * EMessePreis))]]
        }
      
        if AnzahlMesse + AnzahlMesseE >= 1{
            dataArray += [["Erste":NSAttributedString(string: "Gesamtbetrag der gebuchten vocatium/nordjob Messe(n) (netto)", attributes: myAttribute), "Zweite":NSAttributedString(string: String(format:"%.2f €", locale: de, (Double(AMesse) * AMessePreis + Double(BMesse) * BMessePreis + Double(CMesse) * CMessePreis + Double(DMesse) * DMessePreis + Double(EMesse) * EMessePreis)), attributes: myAttribute)]]
        }

        return dataArray;
       
}
}


Thanks for your help!


Regards

Andreas

Replies

You would need to write some kind of data to the pasteboard in a format excel accepts. Not sure if excel supports something like this or not. You can write data to the pasteboard but the other application decides what type of data it would accept.


Not sure if excel supports Applescript. You could look into that.

Hello together,


I am really a newbie and have no idea how to handle. Can anybody put met together some code? Would be really great. This is my last problem before finishing the programm and i a kind of stucked.


Best regards

Andreas

Have a look at this tutorial and the following ones on how to implement copy and paste :


https : / / www.youtube.com/watch?v=V0yLZnVFJjw&list=PLE83F832121568D36&index=55

https : / / www.youtube.com/watch?v=U1RDnd7U9xo&list=PLE83F832121568D36&index=56

https : / / www.youtube.com/watch?v=qr0nTll0Upg&list=PLE83F832121568D36&index=57

https : / / www.youtube.com/watch?v=sN1Z97busa0&index=58&list=PLE83F832121568D36


It is more for drag and drop but implements copy and paste as well.

But it is not swift. For me really dificult, to dificult to transform into swift. Sorry.

Does nobody has an idea or code for me? It is really important. I have no idea how to handle that.