Kevin Chang Kevin Chang - 1 year ago 129
Swift Question

Write data to NSPasteboard and paste into Excel split by column and line

Regarding use of NSPasteboard by Swift. I want to write an OS X program to copy NSTableView data and paste it into Excel split by row and column, to match Excel format. Current code:

@IBAction func copyDataButton(sender: AnyObject) {

let pasteBoard = NSPasteboard.generalPasteboard()

pasteBoard.writeObjects(["data to excel"])


I don't know how to adjust NSPasteBoardWriting data in NSPasteboard to insert a ASCII or ???

Answer Source

I had find the answer, you can construct the string use \t for tab a column, use \n to change line.

let tsvString = "data to excel\n then change line \t then tab a column"

let pasteBoard = NSPasteboard.general()

pasteBoard.writeObjects([tsvString as NSString])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download