What I'm trying to accomplish: I'm in the process of writing a routine that would allow the user to copy a range of cells in Excel and use that data to populate a table, minus the formatting that Excel insists on putting in there, using our company standard table style instead.
What I'm having trouble with: Well, I looked to
Doslib for the
dos_clipboard function to return the contents of the clipboard but I'm having difficulty breaking the returned string into an appropriate list that I can work my way through to populate the cells of the Autocad table. For example, I've got a sample spreadsheet with a 5x5 table of junk, which I've selected and copied to the windows clipboard. When I do this:
Command: (setq test (dos_clipboard))
I get this:
"Column 1\tColumn 2\tColumn 3\tColumn 4\tColumn 5\r\n1\t5\t1\t5\t1\r\n2\t6\t2\t6\t2\r\n3\t7\t3\t7\t3\r\n4\t8\t4\t8\t4\r\n"
As you can see, the cells in my selection are separated by tabs (\t) and the rows of my selection are separated by a carriage return (\r\n). If I now do this:
Command: (setq test2 (dos_strtokens test "\t" t))
I get a single list which still contains the carriage returns like this:
("Column 1" "Column 2" "Column 3" "Column 4" "Column 5\r\n1" "5" "1" "5" "1\r\n2" "6" "2" "6" "2\r\n3" "7" "3" "7" "3\r\n4" "8" "4" "8" "4\r\n")
If I try to take out the carriage returns along with the tabs, like this:
Command: (setq test3 (dos_strtokens test "\t\r\n" t))
I get this:
("Column 1" "Column 2" "Column 3" "Column 4" "Column 5" "1" "5" "1" "5" "1" "2" "6" "2" "6" "2" "3" "7" "3" "7" "3" "4" "8" "4" "8" "4")
What I actually
need, though, is something like this:
(
("Column 1" "Column 2" "Column 3" "Column 4" "Column 5")
("1" "5" "1" "5" "1")
("2" "6" "2" "6" "2")
("3" "7" "3" "7" "3")
("4" "8" "4" "8" "4")
)
Maybe it's too early in the morning, maybe I haven't had enough coffee, but I'm hitting a mental road-block with this and I'm looking for advice, a nudge in the right direction, or alternative ideas.