Updated functions
This commit is contained in:
31
.vscode/excel-pq-symbols/excel-pq-symbols.json
vendored
Normal file
31
.vscode/excel-pq-symbols/excel-pq-symbols.json
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Excel.CurrentWorkbook",
|
||||||
|
"documentation": {
|
||||||
|
"description": "Returns the contents of the current Excel workbook.",
|
||||||
|
"longDescription": "Returns tables, named ranges, and dynamic arrays. Unlike Excel.Workbook, it does not return sheets.",
|
||||||
|
"category": "Accessing data"
|
||||||
|
},
|
||||||
|
"functionParameters": [],
|
||||||
|
"completionItemKind": 3,
|
||||||
|
"isDataSource": true,
|
||||||
|
"type": "table"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Documentation",
|
||||||
|
"documentation": {
|
||||||
|
"description": "Contains properties for function documentation metadata",
|
||||||
|
"category": "Documentation"
|
||||||
|
},
|
||||||
|
"functionParameters": [],
|
||||||
|
"completionItemKind": 9,
|
||||||
|
"isDataSource": false,
|
||||||
|
"type": "record",
|
||||||
|
"fields": {
|
||||||
|
"Name": { "type": "text" },
|
||||||
|
"Description": { "type": "text" },
|
||||||
|
"Parameters": { "type": "record" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
@@ -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
|
||||||
11
power-query/fRenameColumns.m
Normal file
11
power-query/fRenameColumns.m
Normal 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
|
||||||
27
power-query/fReplaceFunction.m
Normal file
27
power-query/fReplaceFunction.m
Normal 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
|
||||||
Reference in New Issue
Block a user