NSTableview - Let user copy rows and paste into Excel

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • NSTableview - Let user copy rows and paste 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:
    1. extension FourthViewController: NSTableViewDataSource, NSTableViewDelegate {
    2. func numberOfRowsInTableView(tableView: NSTableView) -> Int {
    3. let numberOfRows:Int = getDataArray().count
    4. return numberOfRows
    5. }
    6. func tableView(tableView: NSTableView!, objectValueForTableColumn tableColumn: NSTableColumn!, row: Int) -> AnyObject!
    7. {
    8. let newString = getDataArray().objectAtIndex(row).objectForKey(tableColumn.identifier)
    9. return newString;
    10. }
    11. func getDataArray () -> NSArray{
    12. var dataArray:[NSDictionary] = [["Erste": "Mary", "Zweite": "Jane"]];
    13. dataArray.removeAll()
    14. /
    15. let style = NSMutableParagraphStyle()
    16. style.alignment = .Right
    17. let myAttribute = [
    18. NSFontAttributeName: NSFont.boldSystemFontOfSize(13),
    19. NSParagraphStyleAttributeName: style
    20. ]
    21. if AMesse > 0 {
    22. dataArray += [["Erste": String(format:"\(AMesse) x Messe Kategorie A à %.2f Euro (netto)",locale: de,AMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(AMesse) * AMessePreis))]]
    23. }
    24. if BMesse > 0 {
    25. dataArray += [["Erste": String(format:"\(BMesse) x Messe Kategorie B à %.2f Euro (netto)",locale: de,BMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(BMesse) * BMessePreis))]]
    26. }
    27. if CMesse > 0 {
    28. dataArray += [["Erste": String(format:"\(CMesse) x Messe Kategorie C à %.2f Euro (netto)",locale: de,CMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(CMesse) * CMessePreis))]]
    29. }
    30. if DMesse > 0 {
    31. dataArray += [["Erste": String(format:"\(DMesse) x Messe Kategorie D à %.2f Euro (netto)",locale: de,DMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(DMesse) * DMessePreis))]]
    32. }
    33. if EMesse > 0 {
    34. dataArray += [["Erste": String(format:"\(EMesse) x Eintägige Messe à %.2f Euro (netto)",locale: de,EMessePreis), "Zweite": String(format:"%.2f €", locale: de, (Double(EMesse) * EMessePreis))]]
    35. }
    36. if AnzahlMesse + AnzahlMesseE >= 1{
    37. 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)]]
    38. }
    39. return dataArray;
    40. }
    41. }
    Thanks for your help!
    Regards
    Andreas
  • Hallo,

    warum schreibst Du in einem deutschen Forum nicht in Deutsch?
    Das würde die Kommunikation deutlich vereinfachen.

    Die Zwischenablage muss sicherlich einen "Aufbau" haben, der für Excel passend ist.
    Du kannst ja mal aus Excel eine Zeile kopieren und dann die Zwischenablage ansehen.

    Vielleicht gibt es sogar eine Dokumentation von Excel/Microsoft dazu, wie die Daten erwartet werden…

    Viele Grüße
  • little_pixel schrieb:

    Hallo,

    warum schreibst Du in einem deutschen Forum nicht in Deutsch?
    Das würde die Kommunikation deutlich vereinfachen.

    Die Zwischenablage muss sicherlich einen "Aufbau" haben, der für Excel passend ist.
    Du kannst ja mal aus Excel eine Zeile kopieren und dann die Zwischenablage ansehen.

    Vielleicht gibt es sogar eine Dokumentation von Excel/Microsoft dazu, wie die Daten erwartet werden…

    Viele Grüße
    forums.developer.apple.com/thread/66176
    swift-support.de/?p=146-nstabl…py-from-rows-into-excel/0

    Weil es nur copy-paste ist, keine schöne Art.