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
| import openpyxl as oxl
def Graphes(Essai, DonneesEssai):
CheminFichier = Chemin vers mon fichier
FichierExcel = oxl.load_workbook(CheminFichier)
OngletEssai = FichierExcel[Essai]
#Vérifie l'existence des feuilles des graphes sinon les crée
if "Graph_Param1" not in FichierExcel.sheetnames:
FichierExcel.create_chartsheet("Graph_Param1")
if "Graph_Param2" not in FichierExcel.sheetnames:
FichierExcel.create_chartsheet("Graph_Param2")
#Assigne le nom des onglets
OngletGrapheParam1 = FichierExcel["Graph_Param1"]
OngletGrapheParam2 = FichierExcel["Graph_Param2"]
#Retrouver les colonnes utiles
for col in range(1,len(DonneesEssai.columns)+1):
if OngletEssai.cell(14,col).value == "Time (s)":
ColonneTemps = col
elif OngletEssai.cell(14,col).value == "Param2":
ColonneParam2 = col
elif OngletEssai.cell(14,col).value == "Param1":
ColonneParam1 = col
#Renseigne le graphe Param1
GrapheParam1 = oxl.chart.ScatterChart(scatterStyle="smooth")
GrapheParam1.title = "Param1 during test"
GrapheParam1.x_axis.title = "Test time (sec)"
GrapheParam1y_axis.title = "Param1"
xvalues = oxl.chart.Reference(OngletEssai, min_col = ColonneTemps, min_row=15, max_row=len(DonneesEssai))
Param1values = oxl.chart.Reference(OngletEssai, min_col = ColonneParam1, min_row=15, max_row=len(DonneesEssai))
series = oxl.chart.Series(Param1values, xvalues, title=Essai)
GrapheParam1.series.append(series)
OngletGrapheParam1.add_chart(GrapheParam1)
#Renseigne le graphe Usure
GrapheParam2 = oxl.chart.ScatterChart(scatterStyle="smooth")
GrapheParam2 .title = "Param2 evolution"
GrapheParam2 x_axis.title = "Test time (sec)"
GrapheParam2 .y_axis.title = "Param2 "
Param2values = oxl.chart.Reference(OngletEssai, min_col = ColonneParam2, min_row=15, max_row=len(DonneesEssai))
series = oxl.chart.Series(Param2values, xvalues, title=Essai)
GrapheParam2.series.append(series)
OngletGrapheParam2.add_chart(GrapheParam2)
FichierExcel.save(CheminFichier) |
Partager