Openpyxl and Hidden / Unhidden Excel spreadsheets

I have the following code that reads data from a tab delimited text file and then writes it to the specified sheet in an existing Excel workbook. The variables "workbook", "write_sheet" and "text_file" are entered by the user

tab_reader = csv.reader(text_file, delimiter='\t')
xls_book = openpyxl.load_workbook(filename=workbook)
sheet_names = xls_book.get_sheet_names()
xls_sheet = xls_book.get_sheet_by_name(write_sheet)
for row_index, row in enumerate(tab_reader):
        number = 0
        col_number = first_col
        while number < num_cols:
                cell_tmp = xls_sheet.cell(row = row_index, column = col_number)
                cell_tmp.value = row[number]
                number += 1
                col_number += 1
xls_book.save(workbook)

However, when I run this code in an existing “workbook” in which the “worksheet” is a hidden tab, the output displays the tab. I think the reason is that openpyxl does not modify the file, but completely creates a new file. Is there an easy way to tell python to check if a worksheet is hidden and then display a hidden or hidden sheet based on whether the condition is satisfied?

Thank!

+4
2

openpyxl, , , . , . Bitbucket.

[]

:

ws.sheet_state = 'hidden'

xls_sheet.sheet_state = 'hidden' .

+5

:

ws.sheet_state = 'hidden'

.

+1

Source: https://habr.com/ru/post/1537108/


All Articles