import pandas as pd from pptx import Presentation from pptx.util import Inches import os from pptx.enum.text import MSO_VERTICAL_ANCHOR from pptx.enum.text import PP_ALIGN from pptx.util import Pt import tkinter as tk from tkinter import filedialog excel = filedialog.askopenfilename(filetypes=[("Excel files", "*.xlsx")]) df=pd.read_excel(excel) linha_juntada = df.loc[0].combine_first(df.loc[1]) df.loc[0] = linha_juntada df.columns = df.iloc[0] df = df.drop(index=[0, 1]) df = df[1:] df = df.drop(columns=['Camaradagem','Total (Máx 6)', 'Sentido de Responsabilidade','Honestidade','Aplicação', 'Civilidade', 'Aprumo e Atavio','Pontualidade']) df = df.rename(columns={'Coluna1': 'NovaColuna1', 'Coluna3': 'NovaColuna3'}) df.columns.values[0] = 'Numero' df.columns.values[1] = 'Nome' df.columns.values[2] = 'Nota Graduados' df.columns.values[11] = 'Apagar1' df.columns.values[13] = 'Apagar2' df.columns.values[14] = 'Apagar3' df.columns.values[15] = 'Nota Quatitativa' df.columns.values[16] = 'Nota Qualitativa' df.columns.values[17] = 'Apagar4' df['Nota Quatitativa']=df['Nota Quatitativa'].round(2) df.fillna(0, inplace=True) df['Suspensão Frequência'] = df['Suspensão Frequência (1)'] + df['Suspensão Frequência (2)'] df = df.drop(columns=['Nota Graduados','Apagar1', 'Apagar2','Apagar3','Apagar4', 'Suspensão Frequência (1)', 'Suspensão Frequência (2)']) Alunosmtbom = df[df['Nota Qualitativa'] == 'MUITO BOM'] Alunossuf = df[df['Nota Qualitativa'] == 'SUFICIENTE'] Alunosmed = df[df['Nota Qualitativa'] == 'MEDIOCRE'] Alunosmau = df[df['Nota Qualitativa'] == 'MAU'] numero_aluno = df.loc[df['Nota Qualitativa'] == 'MUITO BOM', 'Numero'].values def get_safe_value(lista, indice, valor_padrao=0): return lista[indice] if indice < len(lista) else valor_padrao numero_aluno_0 = get_safe_value(numero_aluno, 0) numero_aluno_1 = get_safe_value(numero_aluno, 1) numero_aluno_2 = get_safe_value(numero_aluno, 2) numero_aluno_3 = get_safe_value(numero_aluno, 3) numero_aluno_4 = get_safe_value(numero_aluno, 4) caminho_pptx = 'Apresentação Comportamentos.pptx' caminho_fotos = 'Fotos' presentation = Presentation(caminho_pptx) if numero_aluno_0 is not None: for slide in presentation.slides: for shape in slide.shapes: if shape.has_text_frame: for paragraph in shape.text_frame.paragraphs: for run in paragraph.runs: if "N1" in run.text: run.text = run.text.replace("N1", str(numero_aluno_0)) foto_aluno_0 = os.path.join(caminho_fotos, f"{numero_aluno_0}.JPG") if os.path.exists(foto_aluno_0): slide.shapes.add_picture(foto_aluno_0, Inches(0), Inches(2.8), width=Inches(2), height=Inches(3)) else: print(f"Foto do aluno {numero_aluno_0} não encontrada.") if "N2" in run.text and numero_aluno_1 is not None: run.text = run.text.replace("N2", str(numero_aluno_1)) foto_aluno_1 = os.path.join(caminho_fotos, f"{numero_aluno_1}.JPG") if os.path.exists(foto_aluno_1): slide.shapes.add_picture(foto_aluno_1, Inches(2), Inches(2.8), width=Inches(2), height=Inches(3)) else: print(f"Foto do aluno {numero_aluno_1} não encontrada.") if "NN" in run.text and numero_aluno_2 is not None: run.text = run.text.replace("NN", str(numero_aluno_2)) foto_aluno_2 = os.path.join(caminho_fotos, f"{numero_aluno_2}.JPG") if os.path.exists(foto_aluno_2): slide.shapes.add_picture(foto_aluno_2, Inches(4), Inches(2.8), width=Inches(2), height=Inches(3)) else: print(f"Foto do aluno {numero_aluno_2} não encontrada.") if "NX" in run.text and numero_aluno_3 is not None: run.text = run.text.replace("NX", str(numero_aluno_3)) foto_aluno_3 = os.path.join(caminho_fotos, f"{numero_aluno_3}.JPG") if os.path.exists(foto_aluno_3): slide.shapes.add_picture(foto_aluno_3, Inches(6), Inches(2.8), width=Inches(2), height=Inches(3)) else: print(f"Foto do aluno {numero_aluno_3} não encontrada.") if "PP" in run.text and numero_aluno_4 is not None: run.text = run.text.replace("PP", str(numero_aluno_4)) foto_aluno_4 = os.path.join(caminho_fotos, f"{numero_aluno_4}.JPG") if os.path.exists(foto_aluno_4): slide.shapes.add_picture(foto_aluno_4, Inches(8), Inches(2.8), width=Inches(2), height=Inches(3)) else: print(f"Foto do aluno {numero_aluno_4} não encontrada.") numero_aluno1 = df.loc[df['Nota Qualitativa'] == 'SUFICIENTE', 'Numero'].values rs=df.loc[df['Nota Qualitativa'] == 'SUFICIENTE', 'Repreensão Simples'].values ra=df.loc[df['Nota Qualitativa'] == 'SUFICIENTE', 'Repreensão Registada'].values sf=df.loc[df['Nota Qualitativa'] == 'SUFICIENTE', 'Suspensão Frequência'].values numero_aluno1_0 = get_safe_value(numero_aluno1, 0) numero_aluno1_1 = get_safe_value(numero_aluno1, 1) numero_aluno1_2 = get_safe_value(numero_aluno1, 2) numero_aluno1_3 = get_safe_value(numero_aluno1, 3) numero_aluno1_4 = get_safe_value(numero_aluno1, 4) if numero_aluno1_0 is not None: for slide in presentation.slides: for shape in slide.shapes: if shape.has_text_frame: for paragraph in shape.text_frame.paragraphs: for run in paragraph.runs: if "N3" in run.text: run.text = run.text.replace("N3", str(numero_aluno1_0)) foto_aluno1_0 = os.path.join(caminho_fotos, f"{numero_aluno1_0}.JPG") if os.path.exists(foto_aluno1_0): slide.shapes.add_picture(foto_aluno1_0, Inches(0.2), Inches(1.5), width=Inches(1.5), height=Inches(2.2)) else: print(f"Foto do aluno {numero_aluno1_0} não encontrada.") if "N4" in run.text and numero_aluno1_1 is not None: run.text = run.text.replace("N4", str(numero_aluno1_1)) foto_aluno1_1 = os.path.join(caminho_fotos, f"{numero_aluno1_1}.JPG") if os.path.exists(foto_aluno1_1): slide.shapes.add_picture(foto_aluno1_1, Inches(0.2), Inches(4.5), width=Inches(1.5), height=Inches(2.2)) else: print(f"Foto do aluno {numero_aluno1_1} não encontrada.") if "AA" in run.text: run.text = run.text.replace("AA", str(numero_aluno1_2)) foto_aluno1_2 = os.path.join(caminho_fotos, f"{numero_aluno1_2}.JPG") if os.path.exists(foto_aluno1_2): slide.shapes.add_picture(foto_aluno1_2, Inches(0.2), Inches(1.5), width=Inches(1.5), height=Inches(2.2)) else: print(f"Foto do aluno {numero_aluno1_2} não encontrada.") if "AB" in run.text and numero_aluno1_3 is not None: run.text = run.text.replace("AB", str(numero_aluno1_3)) foto_aluno1_3 = os.path.join(caminho_fotos, f"{numero_aluno1_3}.JPG") if os.path.exists(foto_aluno1_3): slide.shapes.add_picture(foto_aluno1_3, Inches(0.2), Inches(4.5), width=Inches(1.5), height=Inches(2.2)) else: print(f"Foto do aluno {numero_aluno1_3} não encontrada.") if shape.has_table: table = shape.table for row in table.rows: for cell in row.cells: if "RS1" in cell.text: cell.text = cell.text.replace("RS1", str(rs[0]) if len(rs) > 0 else "0") if "RS2" in cell.text: cell.text = cell.text.replace("RS2", str(rs[1]) if len(rs) > 1 else "0") if "RA1" in cell.text: cell.text = cell.text.replace("RA1", str(ra[0]) if len(ra) > 0 else "0") if "RA2" in cell.text: cell.text = cell.text.replace("RA2", str(ra[1]) if len(ra) > 1 else "0") if "SF1" in cell.text: cell.text = cell.text.replace("SF1", str(sf[0]) if len(sf) > 0 else "0") if "SF2" in cell.text: cell.text = cell.text.replace("SF2", str(sf[1]) if len(sf) > 1 else "0") if "RSAA1" in cell.text: cell.text = cell.text.replace("RSAA1", str(rs[0]) if len(rs) > 0 else "0") if "RSAA2" in cell.text: cell.text = cell.text.replace("RSAA2", str(rs[1]) if len(rs) > 1 else "0") if "RAAA1" in cell.text: cell.text = cell.text.replace("RAAA1", str(ra[0]) if len(ra) > 0 else "0") if "RAAA2" in cell.text: cell.text = cell.text.replace("RAAA2", str(ra[1]) if len(ra) > 1 else "0") if "SFAA1" in cell.text: cell.text = cell.text.replace("SFAA1", str(sf[0]) if len(sf) > 0 else "0") if "SFAA2" in cell.text: cell.text = cell.text.replace("SFAA2", str(sf[1]) if len(sf) > 1 else "0") cell.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER cell.text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE numero_aluno2 = df.loc[df['Nota Qualitativa'] == 'MEDIOCRE', 'Numero'].values rs2=df.loc[df['Nota Qualitativa'] == 'MEDIOCRE', 'Repreensão Simples'].values ra2=df.loc[df['Nota Qualitativa'] == 'MEDIOCRE', 'Repreensão Registada'].values sf2=df.loc[df['Nota Qualitativa'] == 'MEDIOCRE', 'Suspensão Frequência'].values if len(numero_aluno2) >= 2: numero_aluno1_0 = numero_aluno2[0] numero_aluno1_1 = numero_aluno2[1] elif len(numero_aluno2) == 1: numero_aluno1_0 = numero_aluno2[0] numero_aluno1_1 = None else: print("Nenhum aluno com 'MEDIOCRE' encontrado.") numero_aluno1_0 = None numero_aluno1_1 = None if numero_aluno1_0 is not None: for slide in presentation.slides: for shape in slide.shapes: if shape.has_text_frame: for paragraph in shape.text_frame.paragraphs: for run in paragraph.runs: if "N5" in run.text: run.text = run.text.replace("N5", str(numero_aluno1_0)) foto_aluno1_0 = os.path.join(caminho_fotos, f"{numero_aluno1_0}.JPG") if os.path.exists(foto_aluno1_0): slide.shapes.add_picture(foto_aluno1_0, Inches(0.2), Inches(1.5), width=Inches(1.5), height=Inches(2.2)) else: print(f"Foto do aluno {numero_aluno1_0} não encontrada.") if "N6" in run.text and numero_aluno1_1 is not None: run.text = run.text.replace("N6", str(numero_aluno1_1)) foto_aluno1_1 = os.path.join(caminho_fotos, f"{numero_aluno1_1}.JPG") if os.path.exists(foto_aluno1_1): slide.shapes.add_picture(foto_aluno1_1, Inches(0.2), Inches(4.5), width=Inches(1.5), height=Inches(2.2)) else: print(f"Foto do aluno {numero_aluno1_1} não encontrada.") if shape.has_table: table = shape.table for row in table.rows: for cell in row.cells: if "RS3" in cell.text: cell.text = cell.text.replace("RS3", str(rs2[0]) if len(rs2) > 0 else "0") if "RS4" in cell.text: cell.text = cell.text.replace("RS4", str(rs2[1]) if len(rs2) > 1 else "0") if "RA3" in cell.text: cell.text = cell.text.replace("RA3", str(ra2[0]) if len(ra2) > 0 else "0") if "RA4" in cell.text: cell.text = cell.text.replace("RA4", str(ra2[1]) if len(ra2) > 1 else "0") if "SF3" in cell.text: cell.text = cell.text.replace("SF3", str(sf2[0]) if len(sf2) > 0 else "0") if "SF4" in cell.text: cell.text = cell.text.replace("SF4", str(sf2[1]) if len(sf2) > 1 else "0") cell.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER cell.text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE numero_aluno3 = df.loc[df['Nota Qualitativa'] == 'MAU', 'Numero'].values rs3=df.loc[df['Nota Qualitativa'] == 'MAU', 'Repreensão Simples'].values ra3=df.loc[df['Nota Qualitativa'] == 'MAU', 'Repreensão Registada'].values sf3=df.loc[df['Nota Qualitativa'] == 'MAU', 'Suspensão Frequência'].values if len(numero_aluno3) >= 2: numero_aluno1_0 = numero_aluno3[0] numero_aluno1_1 = numero_aluno3[1] elif len(numero_aluno3) == 1: numero_aluno1_0 = numero_aluno3[0] numero_aluno1_1 = None else: print("Nenhum aluno com 'MAU' encontrado.") numero_aluno1_0 = None numero_aluno1_1 = None if numero_aluno1_0 is not None: for slide in presentation.slides: for shape in slide.shapes: if shape.has_text_frame: for paragraph in shape.text_frame.paragraphs: for run in paragraph.runs: if "N7" in run.text: run.text = run.text.replace("N7", str(numero_aluno1_0)) foto_aluno1_0 = os.path.join(caminho_fotos, f"{numero_aluno1_0}.JPG") if os.path.exists(foto_aluno1_0): slide.shapes.add_picture(foto_aluno1_0, Inches(0.2), Inches(1.5), width=Inches(1.5), height=Inches(2.2)) else: print(f"Foto do aluno {numero_aluno1_0} não encontrada.") if "N8" in run.text and numero_aluno1_1 is not None: run.text = run.text.replace("N8", str(numero_aluno1_1)) foto_aluno1_1 = os.path.join(caminho_fotos, f"{numero_aluno1_1}.JPG") if os.path.exists(foto_aluno1_1): slide.shapes.add_picture(foto_aluno1_1, Inches(0.2), Inches(4.5), width=Inches(1.5), height=Inches(2.2)) else: print(f"Foto do aluno {numero_aluno1_1} não encontrada.") if shape.has_table: table = shape.table for row in table.rows: for cell in row.cells: if "RS5" in cell.text: cell.text = cell.text.replace("RS5", str(rs3[0]) if len(rs3) > 0 else "0") if "RS6" in cell.text: cell.text = cell.text.replace("RS6", str(rs3[1]) if len(rs3) > 1 else "0") if "RA5" in cell.text: cell.text = cell.text.replace("RA5", str(ra3[0]) if len(ra3) > 0 else "0") if "RA6" in cell.text: cell.text = cell.text.replace("RA6", str(ra3[1]) if len(ra3) > 1 else "0") if "SF5" in cell.text: cell.text = cell.text.replace("SF5", str(sf3[0]) if len(sf3) > 0 else "0") if "SF6" in cell.text: cell.text = cell.text.replace("SF6", str(sf3[1]) if len(sf3) > 1 else "0") cell.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER cell.text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE MT1 = df['Nota Qualitativa'].value_counts().get('MUITO BOM', 0) B1 = df['Nota Qualitativa'].value_counts().get('BOM', 0) S1 = df['Nota Qualitativa'].value_counts().get('SUFICIENTE', 0) M1 = df['Nota Qualitativa'].value_counts().get('MEDIOCRE', 0) MAU1 = df['Nota Qualitativa'].value_counts().get('MAU', 0) moda = df['Nota Qualitativa'].mode() for slide in presentation.slides: for shape in slide.shapes: if shape.has_table: table = shape.table for row in table.rows: for cell in row.cells: if "MT1" in cell.text: cell.text = cell.text.replace("MT1", str(MT1)) if "B1" in cell.text: cell.text = cell.text.replace("B1", str(B1)) if "S1" in cell.text: cell.text = cell.text.replace("S1", str(S1)) if "M1" in cell.text: cell.text = cell.text.replace("M1", str(M1)) if "MAU1" in cell.text: cell.text = cell.text.replace("MAU1", str(MAU1)) if "NG" in cell.text: cell.text = cell.text.replace("NG", str(moda[0])) cell.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER cell.text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE caminho_salvar = 'Apresentação Comportamentos2.pptx' presentation.save(caminho_salvar) print(f"Arquivo PowerPoint atualizado salvo em: {caminho_salvar}")