当前位置: 首页 > wzjs >正文

汉阳网站推广佛山网络公司 乐云seo

汉阳网站推广,佛山网络公司 乐云seo,手机上使用微信网页版,网站没有icp备案怎么访问系列文章目录 文章目录 系列文章目录前言一、新增同机种多个片一起汇总总结 前言 一、新增同机种多个片一起汇总 import os import shutil import zipfile import pandas as pd import xlrd import xlwt import csv from xlutils.copy import copy from openpyxl import Work…

系列文章目录

文章目录

  • 系列文章目录
  • 前言
  • 一、新增同机种多个片一起汇总
  • 总结


前言

一、新增同机种多个片一起汇总

import os
import shutil
import zipfile
import pandas as pd
import xlrd
import xlwt
import csv
from xlutils.copy import copy
from openpyxl import Workbook
from openpyxl import load_workbook
from os.path import dirname
from decimal import Decimal
from openpyxl.utils.dataframe import dataframe_to_rows
# 读写2007 excel
import openpyxl
from openpyxl.styles import numbers
from openpyxl.styles import Alignment
import glob
import tkinter as tk
from tkinter import messagebox
from tkinter import simpledialogdef del_old_zip(file_path):os.remove(file_path)
def decompress(file_path,root):z = zipfile.ZipFile(f"{file_path}","r")z.extractall(path=f"{root}")for names in z.namelist():if names.endswith(file_flag):z.close()return 1z.close()return 0 def start_dir_make(root,dirname):os.chdir(root)os.mkdir(dirname)return os.path.join(root,dirname)def rem_dir_extra(root,father_dir_name):try:for item in os.listdir(os.path.join(root,father_dir_name)):if not os.path.isdir(os.path.join(root,father_dir_name,item)):continueif item == father_dir_name and len(os.listdir(os.path.join(root,father_dir_name))) == 1:os.chdir(root)os.rename(father_dir_name,father_dir_name + '-old')shutil.move(os.path.join(root,father_dir_name + '-old', item),os.path.join(root))os.rmdir(os.path.join(root,father_dir_name + '-old'))rem_dir_extra(root,item)else:rem_dir_extra(os.path.join(root,father_dir_name),item)except Exception as e:print("清除文件夹出错"+str(e))def get_allfile_msg(file_dir):for root, dirs, files in os.walk(file_dir):return root, dirs, [file for file in files if file.endswith('.xls') or file.endswith('.xlsx') or file.endswith('.csv')] def get_allfile_url(root, files):allFile_url = []for file_name in files:file_url = root + "/" + file_nameallFile_url.append(file_url)return allFile_urldef get_file_name(path, suffix = ['.xlsx', '.xls','.csv']):  #'.xlsx', '.xls',tmp_lst = []for root,dirs,files in os.walk(path):for file in files:tmp_lst.append(os.path.join(root, file))return tmp_lstdef extract_last_part_of_path(path):return os.path.basename(path)#定义读取csv_pandas
def read_csv_file(file_path):#参数:error_bad_lines=False跳过错误的行 delimiter=',',encoding = 'gbk',header = 0, engine='python'  sep = r"\s+\s{0}"  encoding = "iso-8859-1"return pd.read_csv(file_path,encoding = 'latin1',sep = r"\s+\s{0}",dtype=object,quotechar="'",delimiter=',',doublequote=True,engine="python",header = 1)   #第2行作为表头if __name__ == '__main__':#反射率标准S1和S2标准一致wave1start = 430wave1end = 530wave1standard = 1.5wave2start = 550wave2end = 780wave2standard = 1.1#***********************mode = input("请选择汇总模式: 1解压 2汇总单件号 3解压汇总单件号 4汇总多个件号 \n") if mode == "1":zippath = input("请输入需解压的文件路径:\n")parent_path = zippathfile_flag = '.zip'flag = 1while flag:for root,dirs,files in os.walk(parent_path):for name in files:if name.endswith(file_flag):new_ws = start_dir_make(root,name.replace(file_flag,""))zip_path = os.path.join(root,name)flag = decompress(zip_path,new_ws)del_old_zip(zip_path)rem_dir_extra(root,name.replace(file_flag,""))print(f'{root}\\{name}'.join(['文件:','\n解压完成\n']))rem_dir_extra(os.path.split(parent_path)[0],os.path.split(parent_path)[1])print("解压完成,请检查!!")elif mode == "2":   Summarypath = input("请输入汇总路径:\n")item = input("请输入汇总件号:(例如:39642A) \n")user_input = input("请输入汇总model,S1或S2或S1S2或S1&S2 \n")standerd_input = input("是否需要标准?\n")if standerd_input == "Y":wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2")        #设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center')   titlesS1 = ['data1','data2','data3']    titlesS2 = ['data4','data5','data6']  titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 1,column = 1).value = '判定'ws.cell(row = 1,column = 1).alignment = alignmentws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 1,column = 1).value = '判定'ws1.cell(row = 1,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 1,column = 1).value = '判定'ws2.cell(row = 1,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*****************************************************************#读取指定文件夹#file_dir = os.getcwd()file_dir = Summarypathcurrent_path = os.path.dirname(os.path.abspath(__file__))#file_dir = r"D:\Users\gxcaoty\Desktop\39526-905\一车间"root, dirs, files = get_allfile_msg(file_dir)allFile_url = get_allfile_url(root, files)dir_numbers = len(dirs)    #file_dir下的文件夹个数count = 0for root,dirs,files in os.walk(file_dir):for file_path in glob.glob(os.path.join(root,'*.csv')):if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {m} 个文件!")#print(files_chose)try:last_part = extract_last_part_of_path(xl)#print(last_part)  #filename为文件名filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1":df = df.iloc[:,1:4]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max()  if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S2":df = df.iloc[:,4:7]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws2.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max()  if cal1 <= wave1standard and cal2 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws2.cell(row = 2,column = n+2+3*m).value = cal1ws2.cell(row = 3,column = n+2+3*m).value = cal2continue#文件名输出区域ws2.cell(row = 5,column = 2+3*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws.cell(row = 2,column = 1).value = combinedwave1ws.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,6):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max()  if cal1 <= wave1standard and cal2 <= wave2standard :ws.cell(row = 1,column = n+2+6*m).value = "OK"ws.cell(row = 1,column = n+2+6*m).alignment = alignmentelse:ws.cell(row = 1,column = n+2+6*m).value = "NG"ws.cell(row = 1,column = n+2+6*m).alignment = alignment#print(ave1,ave2)ws.cell(row = 2,column = n+2+6*m).value = cal1ws.cell(row = 3,column = n+2+6*m).value = cal2continue#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2):                    ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelif user_input == "S1&S2":#df = df.iloc[:,1:7]df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df1.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df1.iloc[wave2start-380+2:wave2end-380+2,n].max()  cal3 = df2.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal4 = df2.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentif cal3 <= wave1standard and cal4 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2ws2.cell(row = 2,column = n+2+3*m).value = cal3ws2.cell(row = 3,column = n+2+3*m).value = cal4continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part   ws2.cell(row = 5,column = 2+3*m).value = last_part                  #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelse:print("非指定指令")except Exception as e:print(e)if user_input == "S1":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S2'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet'])            wb.save(output_file_path)elif user_input == "S1&S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else :print("请检查程序!")  elif standerd_input == "N":wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2")        #设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center')   titlesS1 = ['data1','data2','data3']    titlesS2 = ['data4','data5','data6']  titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*****************************************************************#读取指定文件夹#file_dir = os.getcwd()file_dir = Summarypathcurrent_path = os.path.dirname(os.path.abspath(__file__))#file_dir = r"D:\Users\gxcaoty\Desktop\39526-905\一车间"root, dirs, files = get_allfile_msg(file_dir)allFile_url = get_allfile_url(root, files)dir_numbers = len(dirs)    #file_dir下的文件夹个数count = 0for root,dirs,files in os.walk(file_dir):for file_path in glob.glob(os.path.join(root,'*.csv')):if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {m} 个文件!")#print(files_chose)try:last_part = extract_last_part_of_path(xl)#print(last_part)  #filename为文件名filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1":df = df.iloc[:,1:4]df = df.astype(float)#print(df)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S2":df = df.iloc[:,4:7]df = df.astype(float)#print(df)#文件名输出区域ws2.cell(row = 5,column = 2+3*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#print(df)#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2):                    ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelif user_input == "S1&S2":#df = df.iloc[:,1:7]df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part   ws2.cell(row = 5,column = 2+3*m).value = last_part                  #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelse:print("非指定指令")except Exception as e:print(e)if user_input == "S1":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S2'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet'])            wb.save(output_file_path)elif user_input == "S1&S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else :print("请检查程序!") else:print("非指定指令!")elif mode == "3":zippath = input("请输入需解压的文件路径:\n")item = input("请输入汇总件号:(例如:39642A) \n")standerd_input = input("是否需要标准? \n")if standerd_input == "Y":parent_path = zippathfile_flag = '.zip'flag = 1while flag:for root,dirs,files in os.walk(parent_path):for name in files:if name.endswith(file_flag):new_ws = start_dir_make(root,name.replace(file_flag,""))zip_path = os.path.join(root,name)flag = decompress(zip_path,new_ws)del_old_zip(zip_path)rem_dir_extra(root,name.replace(file_flag,""))print(f'{root}\\{name}'.join(['文件:','\n解压完成\n']))rem_dir_extra(os.path.split(parent_path)[0],os.path.split(parent_path)[1])print("解压完成,请检查!!")print("请输入汇总model,S1或S2或S1S2或S1&S2")wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2")#设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center')   titlesS1 = ['data1','data2','data3']    titlesS2 = ['data4','data5','data6']  titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 1,column = 1).value = '判定'ws.cell(row = 1,column = 1).alignment = alignmentws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 1,column = 1).value = '判定'ws1.cell(row = 1,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 1,column = 1).value = '判定'ws2.cell(row = 1,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*****************************************************************#读取指定文件夹#file_dir = os.getcwd()file_dir = parent_pathcurrent_path = os.path.dirname(os.path.abspath(__file__))#file_dir = r"D:\Users\gxcaoty\Desktop\39526-905\一车间"root, dirs, files = get_allfile_msg(file_dir)allFile_url = get_allfile_url(root, files)dir_numbers = len(dirs)    #file_dir下的文件夹个数user_input = input("请输入S1或S2或S1S2或S1&S2\n")count = 0for root,dirs,files in os.walk(file_dir):for file_path in glob.glob(os.path.join(root,'*.csv')):if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {m} 个文件!")#print(files_chose)try:last_part = extract_last_part_of_path(xl)#print(last_part)  #filename为文件名filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1":df = df.iloc[:,1:4]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max()  if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S2":df = df.iloc[:,4:7]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws2.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max()  if cal1 <= wave1standard and cal2 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws2.cell(row = 2,column = n+2+3*m).value = cal1ws2.cell(row = 3,column = n+2+3*m).value = cal2continue#文件名输出区域ws2.cell(row = 5,column = 2+3*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws.cell(row = 2,column = 1).value = combinedwave1ws.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,6):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max()  if cal1 <= wave1standard and cal2 <= wave2standard :ws.cell(row = 1,column = n+2+6*m).value = "OK"ws.cell(row = 1,column = n+2+6*m).alignment = alignmentelse:ws.cell(row = 1,column = n+2+6*m).value = "NG"ws.cell(row = 1,column = n+2+6*m).alignment = alignment#print(ave1,ave2)ws.cell(row = 2,column = n+2+6*m).value = cal1ws.cell(row = 3,column = n+2+6*m).value = cal2continue#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2):                    ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelif user_input == "S1&S2":#df = df.iloc[:,1:7]df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df1.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df1.iloc[wave2start-380+2:wave2end-380+2,n].max()  cal3 = df2.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal4 = df2.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentif cal3 <= wave1standard and cal4 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2ws2.cell(row = 2,column = n+2+3*m).value = cal3ws2.cell(row = 3,column = n+2+3*m).value = cal4continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part   ws2.cell(row = 5,column = 2+3*m).value = last_part                  #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelse:print("非指定指令")except Exception as e:print(e)if user_input == "S1":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S2'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet'])            wb.save(output_file_path)elif user_input == "S1&S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else :print("请检查程序!")  elif standerd_input == "N":parent_path = zippathfile_flag = '.zip'flag = 1while flag:for root,dirs,files in os.walk(parent_path):for name in files:if name.endswith(file_flag):new_ws = start_dir_make(root,name.replace(file_flag,""))zip_path = os.path.join(root,name)flag = decompress(zip_path,new_ws)del_old_zip(zip_path)rem_dir_extra(root,name.replace(file_flag,""))print(f'{root}\\{name}'.join(['文件:','\n解压完成\n']))rem_dir_extra(os.path.split(parent_path)[0],os.path.split(parent_path)[1])print("解压完成,请检查!!")print("请输入汇总model,S1或S2或S1S2或S1&S2")wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2")#设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center')   titlesS1 = ['data1','data2','data3']    titlesS2 = ['data4','data5','data6']  titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*****************************************************************#读取指定文件夹#file_dir = os.getcwd()file_dir = parent_pathcurrent_path = os.path.dirname(os.path.abspath(__file__))#file_dir = r"D:\Users\gxcaoty\Desktop\39526-905\一车间"root, dirs, files = get_allfile_msg(file_dir)allFile_url = get_allfile_url(root, files)dir_numbers = len(dirs)    #file_dir下的文件夹个数user_input = input("请输入S1或S2或S1S2或S1&S2\n")count = 0for root,dirs,files in os.walk(file_dir):for file_path in glob.glob(os.path.join(root,'*.csv')):if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {m} 个文件!")#print(files_chose)try:last_part = extract_last_part_of_path(xl)#print(last_part)  #filename为文件名filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1":df = df.iloc[:,1:4]df = df.astype(float)#print(df)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S2":df = df.iloc[:,4:7]df = df.astype(float)#print(df)#文件名输出区域ws2.cell(row = 5,column = 2+3*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#print(df)#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part                     #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2):                    ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelif user_input == "S1&S2":#df = df.iloc[:,1:7]df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part   ws2.cell(row = 5,column = 2+3*m).value = last_part                  #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelse:print("非指定指令")except Exception as e:print(e)if user_input == "S1":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S2'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet'])            wb.save(output_file_path)elif user_input == "S1&S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else :print("请检查程序!")  else:print("非指定指令!")elif mode == "4":parent_path = input("请输入汇总路径:\n")#parent_path = r"D:\Users\gxcaoty\Desktop\桌面文件\2025.2.21\TO柳洋text\39827A"file_dir = parent_pathitem_1 = input("请输入汇总机种:(例如:39642A)\n")item_p = input("请输入汇总P数: (例如:5)\n")item_2 = int('90'+str(item_p))standerd_input = input("是否需要标准? \n")if standerd_input == "Y":folder_count = sum(1 for _ in os.scandir(file_dir) if _.is_dir())print(folder_count)user_input = input("请输入汇总model,S1或S2或S1S2或S1&S2 \n")#standerd_input = input("是否需要标准?\n")   with os.scandir(file_dir) as it:for entry in it:if entry.is_dir():print(entry.name)file_dir1 = file_dir+'\\'+entry.nameprint(file_dir1)file_dir2 = file_dir1.replace("\\","")count = 0wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2")        #设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center')   titlesS1 = ['data1','data2','data3']    titlesS2 = ['data4','data5','data6']  titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 1,column = 1).value = '判定'ws.cell(row = 1,column = 1).alignment = alignmentws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 1,column = 1).value = '判定'ws1.cell(row = 1,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 1,column = 1).value = '判定'ws2.cell(row = 1,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*******************************for root,dirs,files in os.walk(file_dir1):for file_path in glob.glob(os.path.join(root,'*.csv')):for j in range(901,item_2+1):item = item_1 + '-'  + str(j)if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {c} 个文件!")try:last_part = extract_last_part_of_path(xl)filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1&S2":df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df1.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df1.iloc[wave2start-380+2:wave2end-380+2,n].max()  cal3 = df2.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal4 = df2.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentif cal3 <= wave1standard and cal4 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2ws2.cell(row = 2,column = n+2+3*m).value = cal3ws2.cell(row = 3,column = n+2+3*m).value = cal4continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part   ws2.cell(row = 5,column = 2+3*m).value = last_part                  #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws.cell(row = 2,column = 1).value = combinedwave1ws.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,6):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max()  cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max()  if cal1 <= wave1standard and cal2 <= wave2standard :ws.cell(row = 1,column = n+2+6*m).value = "OK"ws.cell(row = 1,column = n+2+6*m).alignment = alignmentelse:ws.cell(row = 1,column = n+2+6*m).value = "NG"ws.cell(row = 1,column = n+2+6*m).alignment = alignment#print(ave1,ave2)ws.cell(row = 2,column = n+2+6*m).value = cal1ws.cell(row = 3,column = n+2+6*m).value = cal2continue#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part                 #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2):                    ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelse :print("指定错误,请重新运行!")except Exception as e:print(e) if user_input == "S1&S2":output_file_path=os.path.join(entry,f'Summaryout{item_1}{"-"}{user_input}{entry.name}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(entry,f'Summaryout{item_1}{"-"}{user_input}{entry.name}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else:print("指令错误,请重新运行!")elif standerd_input == "N":print("请输入汇总model,S1或S2或S1S2或S1&S2") folder_count = sum(1 for _ in os.scandir(file_dir) if _.is_dir())print(folder_count)user_input = input("请输入汇总model,S1或S2或S1S2或S1&S2 \n")#standerd_input = input("是否需要标准?\n")   with os.scandir(file_dir) as it:for entry in it:if entry.is_dir():print(entry.name)file_dir1 = file_dir+'\\'+entry.nameprint(file_dir1)file_dir2 = file_dir1.replace("\\","")count = 0wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2")        #设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center')   titlesS1 = ['data1','data2','data3']    titlesS2 = ['data4','data5','data6']  titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*******************************for root,dirs,files in os.walk(file_dir1):for file_path in glob.glob(os.path.join(root,'*.csv')):for j in range(901,item_2+1):item = item_1 + '-'  + str(j)if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {c} 个文件!")try:last_part = extract_last_part_of_path(xl)filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1&S2":df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part   ws2.cell(row = 5,column = 2+3*m).value = last_part                  #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2):                    ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2):                    ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part                 #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2):                    ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelse:print("指令错误,请重新运行!")except Exception as e:print(e) if user_input == "S1&S2":output_file_path=os.path.join(entry,f'Summaryout{item_1}{"-"}{user_input}{entry.name}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(entry,f'Summaryout{item_1}{"-"}{user_input}{entry.name}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else:print("指令错误,请重新运行!")else:print("非指定指令!!")

总结

分享:
我们的一生,就是一趟旅行,沿途有无尽的坎坷泥泞,也有看不完的春花秋月,如果我们的心灵总是呗灰暗的风尘遮挡,变失去了生机;

http://www.dtcms.com/wzjs/320874.html

相关文章:

  • 凡科做的网站要收费吗抖音seo推荐算法
  • 大金seo浑江区关键词seo排名优化
  • 网站开发费的税率是多少数据分析师报考条件
  • 宁波网络推广的公司报价佛山优化网站关键词
  • 网站建设的利益自建网站
  • 做的好看的网站站长工具查询域名
  • 龙岗网站建设_公司推广下载百度搜索
  • 郑州网站建设找伟置上海关键词优化公司bwyseo
  • 深圳优定软件网站建设十大成功营销策划案例
  • asp.net mvc5网站开发之美北京seo网站管理
  • 长春网站建设dbd3某网站搜索引擎优化
  • 新乡百度网站推广工具seo快速软件
  • 成都家具企业网站建设营销顾问
  • 兰州网站设计哪个平台好网络营销的有哪些特点
  • 做智能网站系统下载地址2024年阳性最新症状
  • 河北省建设机械协会是真的网站吗购买模板建站
  • 国外房屋设计网站长沙网络推广网站制作
  • 北京做网站网络公司b站怎么推广
  • 阿里巴巴网站更新怎么做佛山网络排名优化
  • 福州网站开发风格seo优化员
  • 关于网站制作报价个人网站模板建站
  • 掘金网站建设企业文化理念
  • 杭州品牌网站建设合肥网站排名提升
  • 酒类公司网站模板保定seo推广外包
  • 做led开关电源上什么网站好营销型网站优化
  • 苏州建网站哪家百度云登录入口
  • linux搭建个人网站域名停靠
  • 安徽网站建设 网新大数据培训包就业靠谱吗
  • 做个网站要钱吗搜索引擎优化内容包括哪些方面
  • 天津哪里能做网站高权重友情链接