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

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

问题描述

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

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.

有什么办法可以将其添加到PowerQuery中吗?

Is there any way I can get this into PowerQuery?

推荐答案

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

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

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


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

  1. 将查询命名为GetValue(右侧查询设置"窗格中的名称"属性)
  1. Name the query to GetValue (Name property in the Query settings pane on the right)

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

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天全站免登陆