1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| import os
from tkinter import *
from tkinter.messagebox import *
from tkinter.filedialog import askopenfilename
import openpyxl
from openpyxl import *
from openpyxl.utils import get_column_letter
inputbox = Tk()
inputbox.withdraw()
file_path = filedialog.askopenfilename(filetypes=[("Fichier Excel", "*.xlsx;*.xls"),("Fichier CSV", "*.csv"),("All files", "*.*")])
var_path = str(file_path)
wb= Workbook()
wb= openpyxl.load_workbook(var_path)
# On active l'onglet courant et on le renomme
ws = wb.active
var_titre = ws.title
ws.title = 'old'
# On crée un nouvel onglet et on le renomme
ws1 = wb.create_sheet()
ws1.title = var_titre
# Préparation des fenêtres d'interface utilisateur
def code():
print(Code.get())
if Code.get() == '':
showwarning('Résultat','Code incorrect.\nVeuillez recommencer !')
Code.set('')
else:
var_code_insee=int(Code.get())
ws.cell(column=var_col, row=row, value=var_code_insee)
inputbox.destroy()
# On s'apprête à parcourir la colonne B
begrow = 1
endrow = ws.max_row
endrows1 = 0
endrows1_incrementation = 0
for row in range(begrow,endrow):
if endrows1 > 1:
endrows1_incrementation = endrows1 - 5
endrows1 = endrows1_incrementation
# CAS 1.1 : Le code n'est pas renseigné dans la colonne A alors, on demande à l'utilisateur de le renseigner
if ws['A' + format(row)].value is None and ws['B' + format(row)].value is not None:
# On gére les paramétre de la boîte de dialogue
inputbox.deiconify()
inputbox.title('Code non renseigné')
#Déclaration des variables nécessaires au traitement
var_col = 1
# Création d'un Label
Label1 = Label(inputbox, text='Code de : ' + ws['B' + format(row)].value)
Label1.pack(side = LEFT, padx = 5, pady = 5)
# Création du champ de saisie
Code= StringVar()
Champ = Entry(inputbox,textvariable= Code, bg ='bisque', fg='maroon')
Champ.focus_set()
Champ.pack(side = LEFT, padx = 5, pady = 5)
#Création d'un bouton de Validation
Bouton = Button(inputbox, text ='Valider', command = code)
Bouton.pack(side = LEFT, padx = 5, pady = 5) |
Partager