Function of the code:
I’ve three Excel information to take care of.
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 information.
I do not need to open each file and worksheets with a purpose to copy the specified vary.
I need to write a code to mix each filtered or hidden cells and put these cells to a model new workbook.
Steps of the code:
Mix each filtered or hidden cells of all worksheets for each excel information.
Create a brand new empty single-worksheet workbook.
Put all cells of Step 1 into Step 2.
Downside of the code:
- Working too gradual
import openpyxl import os import glob path = os.getcwd() knowledge= x=enter('title：') + '.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.lively 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)