Kevin Chang Kevin Chang - 8 months ago 59
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 ???


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])