Goal of the code:
As an instance I’ve Three excel recordsdata to cope with.
These file have already been filtered or hidden as a result of the content material may be very giant. And I solely want a part of the content material for each excel recordsdata.
I do not wish to open each file and worksheets with the intention to copy the specified vary.
I wish to write a code to mix each filtered or hidden cells and put these cells to a model new workbook.
Steps of the code:
1.Mix each filtered or hidden cells of all worksheets for each excel recordsdata.
2.Create a brand new empty single-worksheet workbook.
3.Put all cells of Step 1 into Step 2.
Drawback of the code:
1.Operating too gradual. Perhaps there are too many
import openpyxl import os import glob path = os.getcwd() knowledge= x=enter('identify：') + '.xlsx' target_xls = os.path.be part of(path,x) for file in glob.glob(path+'*.*'): if file.endswith((".xlsx")): wb = openpyxl.load_workbook(file, data_only=True) for sheet in wb.worksheets: for j in vary(2, sheet.max_row+1 ): for i in vary(1,sheet.max_column+1): ihidden = sheet.row_dimensions[j].hidden # Row Visibility True / False svalue = sheet.cell(column=i,row=j).worth if ihidden == True: shidden = "HIDDEN" else: shidden = "VISIBLE" knowledge.append(svalue) WP= openpyxl.Workbook() ws = WP.energetic ws.title = "Sheet1" x=sheet.max_column new_list = [data[i:i+x] for i in vary(0, len(knowledge), x)] for elem in new_list: ws.append(elem) WP.save(target_xls)