question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't manually escape cell values with '

See original GitHub issue

I am exporting short git sha1 references, such as “1234”, “abcd”, “fe3a” etc, and whenever a sha1 reference happens to be something like “7e30” or “9e50”, the cells are filled with the corresponding number in scientific notation instead of the strings they are.

This stems from value_input_option='USER_ENTERED' on https://github.com/robin900/gspread-dataframe/blob/9ea7aec5c44f13c65ff06ef6fee51f10c566ec78/gspread_dataframe.py#L254

Allowing one to override this option could be a workaround, or, one could expect to be able to prepend the relevant cell values with ' before export (just like one would as a user entering such values in the spreadsheet).

However, due to https://github.com/robin900/gspread-dataframe/blob/9ea7aec5c44f13c65ff06ef6fee51f10c566ec78/gspread_dataframe.py#L58-L59 any cell values that starts with ' gets another ' prepended, resulting in the literal value of '7e30 being saved in the cell rather than 7e30.

Changing line 58 to if (not allow_formulas) and value.startswith('='): resolves this issue, however one needs to remember to prepend ' to relevant cell values before every export.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
robin900commented, Sep 15, 2020

@motin I’ve created release 3.1.0 in PyPI with this feature. If you have any feedback on the feature that I need to incorporate into the code, I’d be glad to do so and make a further release.

1reaction
robin900commented, Sep 15, 2020

I’ve changed the accepted values of string_escaping. Here’s the new parameter documentation. Your desired option would be 'off'.

string_escaping: determines when string values are escaped as text literals
            (by adding an initial `'` character) in requests to Sheets API.
            Four parameter values are accepted:
              - 'default': only escape strings starting with a literal `'` character
              - 'off': escape nothing; cell values starting with a `'` will be interpreted by
                       sheets as an escape character followed by a text literal.
              - 'full': escape all string values
              - any callable object: will be called once for each cell's string value;
                     if return value is true, string will be escaped with preceding `'`
                     (A useful technique is to pass a regular expression bound method, e.g.
                    `re.compile(r'^my_regex_.*$').search`.)
            The escaping done when allow_formulas=False (escaping string values beginning with `=`)
            is unaffected by this parameter's value.
            Default value is `'default'`.

The branch/PR is updated with the new code to match the documentation above, with full test coverage. You’re welcome to test it and give commentary today. And because this new code is backwards compatible with prior releases, I am ready to cut a new release quickly and push to PyPI today.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid broken formulas - Microsoft Support
You can right-click on the cell and select Format Cells > General (or Ctrl + 1), then press F2 > Enter to change...
Read more >
How to escape special characters in building a JSON string?
JSON strings cannot be quoted with single quotes. ... If you have to use special character in your JSON string, you can escape...
Read more >
How can I escape special characters in cell formatting in Excel
You can use the backslash ( \ ) to escape characters like the colon. In your example, then, you can use the format...
Read more >
How to delete special / unwanted characters in Excel - Ablebits
See how to strip special characters from a text string using Excel formulas and remove unwanted characters from multiple cells with custom ...
Read more >
Excel formula showing as text? 3 things you should check to ...
You type a formula in a cell, then press ENTER. ... tab in calculations there is an option to set calculate value manually...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found