Updated functions

This commit is contained in:
2025-10-24 14:22:52 +03:00
parent 2418f93b72
commit 41c665985b
4 changed files with 109 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
let
GetSheetTable = (tblSource as table, anySheetName as any, optional intSheetNum as nullable number) as table =>
let
intSheet = if intSheetNum = null then 0 else intSheetNum,
// Преобразуем список объектов в список имен листов
// ToDo: добавить сортировку для листов/именованных таблиц или сделать обработку именованных таблиц отдельно
SheetNames = Table.Column(tblSource, "Name"),
// Функция для поиска первого совпадения по имени
FindSheetByName =
if Value.Is(anySheetName, type text) then
if List.Contains(SheetNames, anySheetName) then
Table.SelectRows(tblSource, each [Name] = anySheetName){0}[Data]
else
null
else if Value.Is(anySheetName, type list) then
let
ExistingNames = List.Intersect({anySheetName, SheetNames}),
SheetData = if List.Count(ExistingNames) > 0 then
Table.SelectRows(tblSource, each [Name] = ExistingNames{0}){0}[Data]
else
null
in
SheetData
else
null,
// Если по имени не найдено, возвращаем по номеру
Result =
if FindSheetByName <> null then
FindSheetByName
else if intSheet >= 0 and intSheet < Table.RowCount(tblSource) then
tblSource{intSheet}[Data]
else
error "Не удалось подобрать лист"
in
Result
in
GetSheetTable