Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Construct string to paste into multiple cells in google sheets

I am creating a Desktop app that contains my own grids of data, I want users to be able to easily paste from my grid into a google sheet. How can I construct a string that when put into the clipboard, can be pasted directly into Google Sheets to enter data into multiple cells?

For example I have this CSV string as a variable in Python:

1,2,3,4

If I paste that string into google sheets it gets pasted as 1 cell with the value 1,2,3,4, where I want it pasted as 4 cells in the same row.

like image 854
Adam Griffiths Avatar asked Aug 24 '26 08:08

Adam Griffiths


2 Answers

As @doubleunary suggested (and I had already tried), tabs or '\t' in python are the answer.

However, I made the mistake of outputting the line to copy to a text box and allowing the user to highlight it and copy/paste themselves. The text box automatically converted the tabs to spaces, breaking the copying and pasting.

The solution was to insert the string to be copied directly into the clipboard using pyperclip:

import pyperclip
pyperclip.copy('1\t2\t3\t4')
like image 166
Adam Griffiths Avatar answered Aug 26 '26 20:08

Adam Griffiths


Use tab (ASCII 9) as horizontal separator and newline (ASCII 10) as line separator.

like image 43
doubleunary Avatar answered Aug 26 '26 20:08

doubleunary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!