|
简单思考 不知有没有帮助
1. 检视网址 是否改变的只是 http://www.boc.cn/sourcedb/whpj/后面的部分?
2. 网页总数是否总是为10页?
如果前两个判断均为是, 那么建立自定义一个函数是否会解决困扰呢?
步骤如下:
1. 建立查询 从网页:http://www.boc.cn/sourcedb/whpj/index.html
2. 建立自定义函数 fnGetwhpj(以下为代码)
(Website)=>
let
Source = Web.Page(Web.Contents(Website)),
Data0 = Source{0}[Data],
#"Changed Type" = Table.TransformColumnTypes(Data0,{{"货币名称", type text}, {"现汇买入价", type number}, {"现钞买入价", type number}, {"现汇卖出价", type number}, {"现钞卖出价", type number}, {"中行折算价", type number}, {"发布日期", type date}, {"发布时间", type time}})
in
#"Changed Type"
3. 建立一个网页地址工作表 Web(见附图)4. 鼠标点击Web工作表内任一包含内容单元格 建立查询,从当前工作簿 (代码见步骤描述之后)
5. 增加自定义列 ,函数为 = fnGetwhpj([Website])
6. 展开自定义列内容, 并对各列进行数值格式上的设置
7. 关闭并上载至Excel
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Website", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each fnGetwhpj([Website])),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"货币名称", "现汇买入价", "现钞买入价", "现汇卖出价", "现钞卖出价", "中行折算价", "发布日期", "发布时间"}, {"货币名称", "现汇买入价", "现钞买入价", "现汇卖出价", "现钞卖出价", "中行折算价", "发布日期", "发布时间"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"发布时间", type time}, {"发布日期", type date}, {"中行折算价", type number}, {"现钞卖出价", type number}, {"现汇卖出价", type number}, {"现钞买入价", type number}, {"现汇买入价", type number}, {"货币名称", type text}}),
#"Sorted Rows" = Table.Sort(#"Changed Type1",{{"货币名称", Order.Ascending}, {"发布时间", Order.Descending}})
in
#"Sorted Rows"
数据表见附件
|
|