Excel Power Query是将Excel文件与多个表/工作表组合在一起的最佳方式,其中工作表可能不存在于所有工作簿中

vwhgwdsa  于 2023-11-20  发布在  其他
关注(0)|答案(1)|浏览(86)

我正在使用Excel Power Query整合SharePoint文档库中的Excel文件数量(300+)
每个文件都有一个或多个表/目录。例如。
文件1:表1、表2、表3文件2:表1、表2文件3:表1、表3
我想在所有工作簿中只合并合并表3,而忽略所有其他表。如何才能最好地实现这一点?
当尝试合并时,我收到一个错误,说明未找到密钥
我找到了下面的帖子,但m代码似乎在我的文件Excel Power Query - What's the best way to combine Excel Files with multiple Worksheets where WorkSheet may not exist in all Workbooks中不起作用
Thanks in advance

5kgi1eie

5kgi1eie1#

这只合并了目录中每个工作簿的表3

let Source = Folder.Files("C:\directoryname\subdirectoryname\"),
#"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".xlsx")),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Name", "Content"}),
#"Added Custom" = Table.AddColumn(#"Removed Other Columns", "GetFileData", each Excel.Workbook([Content],true)),
#"Added Custom1" = Table.AddColumn( #"Added Custom", "GetFileData2", each Table.SelectRows([GetFileData], each [Name]="Table3")),
#"Expanded GetFileData" = Table.ExpandTableColumn(#"Added Custom1", "GetFileData2", {"Data", "Hidden", "Item", "Kind", "Name"}, {"Data", "Hidden", "Item", "Kind", "Sheet"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded GetFileData",{"Content", "Hidden", "Item", "Kind","GetFileData"}),
List = List.Union(List.Transform(#"Removed Columns"[Data], each Table.ColumnNames(_))),
#"Expanded Data" = Table.ExpandTableColumn(#"Removed Columns", "Data", List,List)
in  #"Expanded Data"

字符串
如果这不起作用,请解释您看到的错误

相关问题