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

View File

@@ -0,0 +1,11 @@
let
Rename = (Source as table) as table =>
let
OldColumnNames = Table.ColumnNames(Source),
NewColumnNames = List.Transform(OldColumnNames, fReplaceFunction),
ZipColumnNames = List.Zip({OldColumnNames, NewColumnNames}),
SetDefaultColumnNames = Table.RenameColumns(Source, ZipColumnNames)
in
SetDefaultColumnNames
in
Rename

View File

@@ -0,0 +1,27 @@
( sInputText as nullable text,
optional bWholeCell as nullable logical,
optional sTag as nullable text,
optional tSubstitution as nullable table) as text =>
let
bIsWholeCell = if (bWholeCell = null) then true else bWholeCell,
bIsTagged = not (sTag = null),
tSubstitution = if tSubstitution = null then
if bIsTagged then
try Table.SelectRows(fP("RENAMING_RULES"), each ([#"#"] = sTag)) otherwise fP("RENAMING_RULES")
else
fP("RENAMING_RULES")
else
tSubstitution,
tSubstBuffer = Table.Buffer(tSubstitution),
ReplacedText = List.Accumulate(Table.ToRows(tSubstBuffer), sInputText, (state, substitution) =>
if bIsWholeCell then
if (state = substitution{0}) then
substitution{1}
else
state
else
Text.Replace(state, substitution{0}, substitution{1}))
in
ReplacedText