Is it possible to place escaped characters in a Streamlit text_area component?

Is it possible to place escaped characters in a Streamlit text_area component?

I would like to place escaped tabs “\t” into the text_area component so that I can copy and paste the text area content into an Excel spreadsheet. The spreadsheet has merged cells so the format must be [text, tab, text tab tab, text tab tab, text] for the content to be properly copied into the correct cells.

Or maybe theres a better way?

Thanks for your help,

If you copy code that has tabs in it, you should be able to split the text by tabs, and then grab the remaining items.

Something like this should work:

In [6]: text = "abc\tqrs\t\txyz\t\tbcd"
   ...: items = [item for item in text.split("\t") if item]
   ...: print(items)
   ...: 
['abc', 'qrs', 'xyz', 'bcd']
2 Likes

Hey @ihudson709! Welcome to our forum!

Looks like your intuition should work. Meaning this:

st.text_area("Text", "oooo\taaaa\tbbb")

Does indeed give


Which can be copy pasted to Excel (or here a Google Sheet) and it should work seamlessly!
image


Now, depending on your overall workflow, I wonder if there would be a cleaner way to transmit data from your app to Excel. If, by chance, you’re using Pandas, maybe worth giving a look at to_excel()?

3 Likes

Thanks blackary and arnaud. This works perfectly. :grinning:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.