Téléverser les fichiers vers "/"

This commit is contained in:
antoinewg 2026-06-15 08:33:43 -04:00
parent 8db1830ae3
commit b6d2975408
4 changed files with 65 additions and 0 deletions

Binary file not shown.

58
import_excel.py Normal file
View File

@ -0,0 +1,58 @@
import re
import shutil
import pandas as pd
from openpyxl import load_workbook
def extract_coord(url, param):
match = re.search(rf'[?&]{param}=([-\d.]+)', str(url))
return match.group(1) if match else None
def process_data(source_file_path, destination_template_path, output_path):
# Read source CSV (semicolon-delimited)
src = pd.read_csv(source_file_path, sep=';')
src.columns = src.columns.str.strip()
def build_address(row):
parts = []
if pd.notna(row.get('civique')):
parts.append(str(int(row['civique'])))
if pd.notna(row.get('appartement')):
parts.append(f"App. {row['appartement']}")
if pd.notna(row.get('rue')):
parts.append(str(row['rue']).strip())
return ' '.join(parts)
# Copy the template so we preserve its formatting/styles
shutil.copy(destination_template_path, output_path)
wb = load_workbook(output_path)
ws = wb.active
# Map column names to their Excel column index (based on header row 1)
header = {cell.value: cell.column for cell in ws[1]}
# Write each row starting at row 2
for i, row in src.iterrows():
excel_row = i + 2 # row 1 is the header
ws.cell(excel_row, header['ID de Ligne']) .value = (i + 1) * 100
ws.cell(excel_row, header['Province']) .value = 'PQ'
ws.cell(excel_row, header['Code barre']) .value = str(row['codeBar']).strip()
ws.cell(excel_row, header['Latitude']) .value = extract_coord(row['lien map targo'], 'y')
ws.cell(excel_row, header['Longitude']) .value = extract_coord(row['lien map targo'], 'x')
ws.cell(excel_row, header['Numéro Électrique']) .value = str(row['tagHydro']).strip()
ws.cell(excel_row, header['Adresse']) .value = build_address(row)
ws.cell(excel_row, header['Ville']) .value = str(row['ville']).strip()
ws.cell(excel_row, header['Traitement de poteau']) .value = 'non traitée'
wb.save(output_path)
print(f"Done! {len(src)} row(s) written into {output_path}")
if __name__ == "__main__":
SOURCE_FILE = r"C:\Users\Antoine\PycharmProjects\excel_import\selectionElements.csv"
TEMPLATE_FILE = r"C:\Users\Antoine\PycharmProjects\excel_import\CAPermitPoteauxImportation_Gabarit_fr-CA.xlsx"
OUTPUT_FILE = r"C:\Users\Antoine\PycharmProjects\excel_import\CAPermit_Final_Output.xlsx"
process_data(SOURCE_FILE, TEMPLATE_FILE, OUTPUT_FILE)

3
selectionElements.csv Normal file
View File

@ -0,0 +1,3 @@
id appart; idGouvQc; nom; civique; appartement; rue; ville; lien map targo;tagHydro;codeBar
;;PHD206+1 rue Principale;206;;Rue Principale;Saint-Stanislas-de-Kostka;https://map.targointernet.com/infrastructure/map.php?zoom=20&y=45.177910&x=-74.130135;R6M9K;5NBAZC
;;PHO182-1 rue Centrale;182;;Rue Centrale;Saint-Stanislas-de-Kostka;https://map.targointernet.com/infrastructure/map.php?zoom=20&y=45.177700&x=-74.129883;Z5RL9;6J1AQZ
1 id appart idGouvQc nom civique appartement rue ville lien map targo tagHydro codeBar
2 PHD206+1 rue Principale 206 Rue Principale Saint-Stanislas-de-Kostka https://map.targointernet.com/infrastructure/map.php?zoom=20&y=45.177910&x=-74.130135 R6M9K 5NBAZC
3 PHO182-1 rue Centrale 182 Rue Centrale Saint-Stanislas-de-Kostka https://map.targointernet.com/infrastructure/map.php?zoom=20&y=45.177700&x=-74.129883 Z5RL9 6J1AQZ

View File

@ -0,0 +1,4 @@
poteaux
id placemark; id appart; idGouvQc; nom; civique; appartement; rue; ville; code postal; lien googlemap; lien map targo;commentaire;;tagHydro;codeBar;poteaux_positions_id;poteaux_compagnies_proprios_id;poteauConjoint;decalage;isolateurDommage;etatMT;etatBT;ligneViseeOk;ecartBtOk;fissure;fissureAttache;pourriture;dommage;inclinaison;miseATerre;classe;hauteur;toronArriere
68560;;;PHD206+1 rue Principale;206;;Rue Principale;Saint-Stanislas-de-Kostka;J0S1W0;https://www.google.com/maps?t=k&q=loc:45.177910+-74.130135&z=19;https://map.targointernet.com/infrastructure/map.php?zoom=20&y=45.177910&x=-74.130135;;R6M9K;5NBAZC;1;1;1;1
68628;;;PHO182-1 rue Centrale;182;;Rue Centrale;Saint-Stanislas-de-Kostka;J0S1W0;https://www.google.com/maps?t=k&q=loc:45.177700+-74.129883&z=19;https://map.targointernet.com/infrastructure/map.php?zoom=20&y=45.177700&x=-74.129883;;Z5RL9;6J1AQZ;2;1;1;-1
1 poteaux
2 id placemark; id appart; idGouvQc; nom; civique; appartement; rue; ville; code postal; lien googlemap; lien map targo;commentaire;;tagHydro;codeBar;poteaux_positions_id;poteaux_compagnies_proprios_id;poteauConjoint;decalage;isolateurDommage;etatMT;etatBT;ligneViseeOk;ecartBtOk;fissure;fissureAttache;pourriture;dommage;inclinaison;miseATerre;classe;hauteur;toronArriere
3 68560;;;PHD206+1 rue Principale;206;;Rue Principale;Saint-Stanislas-de-Kostka;J0S1W0;https://www.google.com/maps?t=k&q=loc:45.177910+-74.130135&z=19;https://map.targointernet.com/infrastructure/map.php?zoom=20&y=45.177910&x=-74.130135;;R6M9K;5NBAZC;1;1;1;1
4 68628;;;PHO182-1 rue Centrale;182;;Rue Centrale;Saint-Stanislas-de-Kostka;J0S1W0;https://www.google.com/maps?t=k&q=loc:45.177700+-74.129883&z=19;https://map.targointernet.com/infrastructure/map.php?zoom=20&y=45.177700&x=-74.129883;;Z5RL9;6J1AQZ;2;1;1;-1