如何在 PowerQuery 中引用单元格的值 [英] How can I reference a cell's value in PowerQuery

查看:116
本文介绍了如何在 PowerQuery 中引用单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个 PowerQuery 查询,我想提供 Excel 文件中单元格的值.在这种特殊情况下,源文件名的完整路径.

有什么办法可以将其导入 PowerQuery?

解决方案

这可以使用 PowerQuery 中的命名范围和自定义函数来实现:

  1. 命名您需要引用的单元格(在编辑栏左侧的文件中输入名称) - 例如源文件
  2. 插入新的空白 PowerQuery 查询(PowerQuery 功能区 -> 来自其他来源)
  3. 在 PowerQuery 编辑器中,转到查看"->高级编辑器"并粘贴以下代码;

<前>(范围名称)=>Excel.CurrentWorkbook(){[Name=rangeName]}[Content]{0}[Column1]

  1. 将查询命名为 GetValue(右侧查询设置窗格中的名称属性)

现在您可以使用 GetValue(cellName) 访问查询中的命名单元格 - 例如

<前>= Excel.Workbook(File.Contents(GetValue("SourceFile")))

I'm having multiple PowerQuery queries that I would like to feed the value of a cell in my Excel file. In this particular case, the full path to the sourcefile name.

Is there any way I can get this into PowerQuery?

解决方案

This can be achieved using a named range and a custom function in PowerQuery:

  1. Name the cell you need to refer (type in a name into the file left of the formula bar) - e.g. SourceFile
  2. Insert a new blank PowerQuery query (PowerQuery ribbon -> From other sources)
  3. In the PowerQuery editor, go to View -> Advanced Editor and paste the following code;

(rangeName) => 
    Excel.CurrentWorkbook(){[Name=rangeName]}[Content]{0}[Column1]

  1. Name the query to GetValue (Name property in the Query settings pane on the right)

Now you can access the named cell in your queries, using GetValue(cellName) - e.g.

= Excel.Workbook(File.Contents(GetValue("SourceFile")))

这篇关于如何在 PowerQuery 中引用单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆