let
// intitulé des 2 colonnes fixes
col1Name = "Col Fixe1",
col2Name = "Col Fixe2",
// fonction permettant de récupérer les données "propres" à partir des données brutes d'une feuille
getSheetData = (col1Name as text, col2Name as text, sheetData as table) as nullable table =>
let
// ajouter une colonne permettant d'identifier la ligne des header (celle contenant les 2 intitulés de colonnes fixes)
AddColumn_HeaderFlag = Table.AddColumn(sheetData, "FlagHeaderRow", each let rowValues = Record.ToList(_) in List.Contains(rowValues, col1Name) and List.Contains(rowValues, col2Name), type logical),
// supprimer les premières lignes
DeleteFirstRows = Table.Skip(sheetData,List.PositionOf(AddColumn_HeaderFlag[FlagHeaderRow], true)),
// promouvoir les entêtes
PromoteHeaders = Table.PromoteHeaders(DeleteFirstRows, [PromoteAllScalars=true]),
// dépivoter les autres colonnes
Unpivot = Table.UnpivotOtherColumns(PromoteHeaders, {col1Name, col2Name}, "Attribut", "Valeur")
in
try Unpivot otherwise null,
excelFilePath = "C:\Folder\combiner plusieurs feuilles.xlsx",
fileContent = Excel.Workbook(File.Contents(excelFilePath), null, true),
AddColumn_CleanData = Table.AddColumn(fileContent, "CleanData", each getSheetData(col1Name, col2Name, [Data]), type nullable table),
Filter_WithCleanData = Table.SelectRows(AddColumn_CleanData, each [CleanData] <> null),
SelectColumns = Table.SelectColumns(Filter_WithCleanData,{"Name", "CleanData"}),
Expand_CleanData = Table.ExpandTableColumn(SelectColumns, "CleanData", {col1Name, col2Name, "Attribut", "Valeur"}, {col1Name, col2Name, "Attribut", "Valeur"})
in
Expand_CleanData