核查合并后的数据,把0的数据或者空的数据单独提取出来
import os
import openpyxl
import pandas as pd
from pathlib import Path
workbook_to = openpyxl.Workbook()
sheet_to = workbook_to.active
workbook_to.save(r'G:\可能有问题的学校及月份.xlsx')
workbook_to = openpyxl.load_workbook(r'G:\可能有问题的学校及月份.xlsx')
sheet_to = workbook_to.active
path = r'G:\2021.1-2023.8月成本汇总表'
k = 1
for file in os.listdir(path):
workbook_from = openpyxl.load_workbook(os.path.join(path, file))
sheet_from = workbook_from.active
for i in range(2, 28):
if sheet_from.cell(row=i, column=19).value == None or float(sheet_from.cell(row=i, column=19).value) == 0:
sheet_to['A' + str(k)].value = file[:-5]
for j in range(1,21):
sheet_to[chr(j + 1 + 64) + str(k)].value = sheet_from.cell(row = i, column = j).value
print(sheet_to['B' + str(k)].value)
k += 1
if sheet_from.cell(row=i, column=3).value == None or float(sheet_from.cell(row=i, column=3).value) == 0:
if sheet_from.cell(row=i, column=8).value == None or float(sheet_from.cell(row=i, column=8).value) == 0:
sheet_to['A' + str(k)].value = file[:-5]
for j in range(1,21):
sheet_to[chr(j + 1 + 64) + str(k)].value = sheet_from.cell(row = i, column = j).value
print(sheet_to['B' + str(k)].value)
k += 1
workbook_from.save(os.path.join(path, file))
print("*"*10, file, "*"*10)
workbook_to.save(r'G:\可能有问题的学校及月份.xlsx')