问题
I have a link of a website from where I want to pull out data through power query. Every time, this link will get changed as per need. So I need to use power query every time. Is there any way to build up power query which shows that I'll change link and data will be refreshed? Is it possible that I paste link in cell A1 of sheet 1 and I fetch data to sheet 2? Please guide me.
回答1:
Click on the cell with the URL, then open menu Power Query > Excel Data > From Table (uncheck "My table has headers")
In the Power Query editor, right click on the URL cell of the table and "drill down" to get the text value.
Now you need to do some manual M code transformation to treat this variable as a datasource. Go to View > Show formula bar, then click the fx button to add a custom step. Add the datasource call, e.g. for web pages:
= Web.Page(Web.Contents(Column1))
You might need to answer some questions about data privacy (after all, you're copying a variable from your Excel workbook and sending it to the internet!).
You can edit the link in sheet 1, and when you refresh your query you'll see sheet 2 is changed.
EDIT:
Your full query should look like:
let
Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
Column1 = #"Changed Type"{0}[Column1],
Custom1 = Web.Page(Web.Contents(Column1))
in
Custom1
来源:https://stackoverflow.com/questions/31489903/how-to-pull-out-data-using-power-query-from-1-cell-link-pasted-in-cell-a1-from