Skip to content

feat: add method to split text into columns - #1557

Open
jiisanda wants to merge 9 commits into
burnash:masterfrom
jiisanda:text-to-column
Open

jiisanda wants to merge 9 commits into
burnash:masterfrom
jiisanda:text-to-column

Conversation

@jiisanda

@jiisanda jiisanda commented Jun 11, 2025 •

Copy link
Copy Markdown

Issue and Discussion: #1000

Update

  • Adding a DelimiterType StrEnum in utils.py.
  • Adding a text_to_column method in Worksheet class... something like this...
    @cast_to_a1_notation
    def text_to_column(
        self,
        source_range: str,
        delimiter_type: DelimiterType = DelimiterType.comma,
        custom_delimiter: Optional[str] = None,
    ) -> JSONResponse:

Usage for csv will be like...

worksheet.text_to_column("A1:A4", DelimiterType.comma)

@alifeee @lavigne958 its ready for review... let me know if you have any feedback...

@jiisanda
jiisanda marked this pull request as draft June 11, 2025 21:32
@jiisanda
jiisanda marked this pull request as ready for review June 22, 2025 15:16
@alifeee

alifeee commented Jun 26, 2025

Copy link
Copy Markdown
Collaborator

thanks for this change ! it looks very well crafted ;]

as for these tests which fail, I believe all tests in worksheet_test.py initialise a spreadsheet object (here), so unless this fixture is turned off for the tests, they will need API access, and therefore a VCR cassette

https://github.com/jiisanda/gspread/blob/4292e133a108d1d93c5471ab006b796e943da3f0/tests/worksheet_test.py#L2110-L2113

@jiisanda

Copy link
Copy Markdown
Author

Thanks @alifeee, and sorry for the slow follow up! You were right about the fixture: the validation tests need cassettes too, so I've recorded them.
Other changes since your review:

  • custom_delimiter now raises a ValueError if it's passed with a non-CUSTOM delimiter_type (it used to be silently ignored), and an empty string is rejected for CUSTOM
  • Merged the private helper into text_to_column
  • Restored tests for the period, semicolon, space, mixed-count and multi-character delimiters.
  • Renamed the "preserve existing data" test to overwrites_adjacent_columns

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants