Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.clearContents()
    pasteBoard.writeObjects(["data to excel"])


}

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

like image 580
Kevin Chang Avatar asked Oct 25 '25 15:10

Kevin Chang


1 Answers

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.clearContents()
pasteBoard.writeObjects([tsvString as NSString])
like image 88
Kevin Chang Avatar answered Oct 27 '25 07:10

Kevin Chang