Leading spaces lost after opening, reading, and saving workbook

Issue #1303 resolved
Vivian Young created an issue

My excel worksheet contains leading spaces in certain columns that are necessary for distinguishing a nesting structure. When I open the worksheet using openpyxl in my python script, read the cell values of cells in a column, make edits to the worksheet (adding a new column, not touching the cells in the aforementioned column), and save it, the leading spaces in the column are lost.

My excel sheet column before running my python script:

After running:

Comments (7)

  1. Vivian Young reporter

    @CharlieC I’ve attached a sample excel worksheet. Let me know if there’s anything else I should provide. Thanks!

  2. CharlieC

    Thanks for the file. This is related to the handling of whitespace in strings and should actually be fixed in 2.6.2 so you might want to doublecheck your version or try working with a checkout, because it works fine with my local copy.

    However, I’d also suggest you look at the outlining function that Excel provides for just this kind of grouping.

  3. Log in to comment