SummerRest
SummerRest

Reputation: 1

openpyxl can not read consecutive hidden columns

In my excel file I hide certain column(s) and when I read the column visible state with openpyxl, following situations happen:

  1. hide 'A' in excel, read out 'A' as hidden;
  2. hide 'ABC' in excel, read out 'A' as hidden, 'BC' visible (which is weird);
  3. hide 'B' in excel, read out 'B' as hidden; then hide 'A' in excel, read out 'A' as hidden, but 'B' is visible; ...

It seems that only the first column can be read out hidden for a consecutive column set hidden. My source code is as below. If anything wrong, please let me know. Thanks.

import openpyxl

work_book = openpyxl.load_workbook('test_1.xlsx', read_only=False)
work_sheet = work_book.get_sheet_by_name('sheet_1')

for col in ['A', 'B', 'C', 'D', 'E', 'F', 'G']:
    print work_sheet.column_dimensions[col].hidden

Upvotes: 0

Views: 956

Answers (1)

Charlie Clark
Charlie Clark

Reputation: 19527

Excel merges the definitions of the columns A:C together. You can check for this looking at the min and max attributes of the relevant column definition.

Upvotes: 2

Related Questions