如何使用 Power Query 从 SharePoint 库中的(许多)文档中获取数据
How to get data from within (many) documents in SharePoint library with Power Query
此处为初级 Power BI
如何查看 SharePoint 列表中的每个 excel 文件并从预定义的单元格中提取内容。
我目前正在访问一些包含 .xlsx 文件的 Intranet Sharepoint 库,我正在使用这些文件的元数据做一些报告。例如,一个库包含 10 个 excel 文件,因此我可以绘制出上传者、上传时间以及分配给的类别...
但是,Power Query 是否有办法查看每个文件,从 excel 的单元格 A1 中获取值,并将其添加为新列“CellA1Content” ?即,根据文件内容制作您自己的元数据并将它们添加到导入的元数据 table.
我发现了一些我可能需要的功能:
File.Contents
Excel.CurrentWorkbook
但是,我对 Power Query 的精通程度还不够高,无法将它们组合在一起(如果可能的话)。我将不得不执行某种 foreach 操作。
编辑:解决方案
这成功了。我在 excel 中选择了第一个非隐藏 sheet 并且我还制作了函数以便我可以传递列号和行号。
主查询:
let
Source = SharePoint.Contents("http://mysharepoint", [Implementation=null, ApiVersion=15]),
... ... ...
//Open each excel and get cell D5
#"AddedColumn1" = Table.AddColumn(#"Filtered Rows", "AddedColumn1", each GetCellContent([Content],4,5))
in
AddedColumn1
Power BI 中的空白查询,称为 GetCellContent:
let
Source = (binaryParameter,col,row) => let
Source = Excel.Workbook(binaryParameter, null, false),
UnhiddenSheets = Table.SelectRows(Source, each if [Hidden]=false and [Kind]="Sheet" then true else false),
Sheet = UnhiddenSheets{0}[Data],
Column = Table.SelectColumns(Sheet,{Text.Combine({"Column",Number.ToText(col)})}),
Cell = Record.Field(Column{row-1}, Text.Combine({"Column",Number.ToText(col)}) )
in
Cell
in
Source
You'll need a Function used in a column like this.
这是我对你的问题的本地解释,没有共享点。虽然共享相同的逻辑。
主查询
let
Source = Folder.Contents("YourDirectory"),
#"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".xlsx")),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Content", "Name"}),
#"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Row1Col1", each PullRow1Col1([Content]))
in
#"Added Custom"
PullRow1Col1:
let
Source = (binaryParameter) => let
Source = Excel.Workbook(binaryParameter, null, false),
Sheet1_sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
Column1 = Sheet1_sheet{0}[Column1]
in
Column1
in
Source
此处为初级 Power BI
如何查看 SharePoint 列表中的每个 excel 文件并从预定义的单元格中提取内容。
我目前正在访问一些包含 .xlsx 文件的 Intranet Sharepoint 库,我正在使用这些文件的元数据做一些报告。例如,一个库包含 10 个 excel 文件,因此我可以绘制出上传者、上传时间以及分配给的类别...
但是,Power Query 是否有办法查看每个文件,从 excel 的单元格 A1 中获取值,并将其添加为新列“CellA1Content” ?即,根据文件内容制作您自己的元数据并将它们添加到导入的元数据 table.
我发现了一些我可能需要的功能:
File.Contents
Excel.CurrentWorkbook
但是,我对 Power Query 的精通程度还不够高,无法将它们组合在一起(如果可能的话)。我将不得不执行某种 foreach 操作。
编辑:解决方案
这成功了。我在 excel 中选择了第一个非隐藏 sheet 并且我还制作了函数以便我可以传递列号和行号。
主查询:
let
Source = SharePoint.Contents("http://mysharepoint", [Implementation=null, ApiVersion=15]),
... ... ...
//Open each excel and get cell D5
#"AddedColumn1" = Table.AddColumn(#"Filtered Rows", "AddedColumn1", each GetCellContent([Content],4,5))
in
AddedColumn1
Power BI 中的空白查询,称为 GetCellContent:
let
Source = (binaryParameter,col,row) => let
Source = Excel.Workbook(binaryParameter, null, false),
UnhiddenSheets = Table.SelectRows(Source, each if [Hidden]=false and [Kind]="Sheet" then true else false),
Sheet = UnhiddenSheets{0}[Data],
Column = Table.SelectColumns(Sheet,{Text.Combine({"Column",Number.ToText(col)})}),
Cell = Record.Field(Column{row-1}, Text.Combine({"Column",Number.ToText(col)}) )
in
Cell
in
Source
You'll need a Function used in a column like this.
这是我对你的问题的本地解释,没有共享点。虽然共享相同的逻辑。
主查询
let
Source = Folder.Contents("YourDirectory"),
#"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".xlsx")),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Content", "Name"}),
#"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Row1Col1", each PullRow1Col1([Content]))
in
#"Added Custom"
PullRow1Col1:
let
Source = (binaryParameter) => let
Source = Excel.Workbook(binaryParameter, null, false),
Sheet1_sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
Column1 = Sheet1_sheet{0}[Column1]
in
Column1
in
Source