如何正确地将预格式化文本从网站导入 Excel 并且它看起来仍然像预格式化文本?

问题描述 投票:0回答:1

我工作的地方使用国家气象局的火灾天气预报产品为消防管理人员制作一款产品,该产品具有特定于其所在地区的火灾天气。我们一直在 Google 表格中执行此操作,但我们正在远离 Google 的所有内容,需要在 Excel 中完成此操作。

目前,该产品包括来自 RAWS(偏远地区气象站)的数据、NWS 的火灾天气预报文本摘录以及天气警报。该文件以 PDF 格式导出,每天发送两次,但也可以根据需要在我们的网站上提供。

火灾天气预报与几乎所有 NWS 文本产品一样,是 PHP 生成的网页的预格式化部分。示例:https://forecast.weather.gov/product.php?site=NWS&issuedby=CTP&product=LWX&format=txt&version=1&glossary=0

由于我对GoDaddy(我们网站所在的地方)上的PHP和WordPress了解不够,我试图让它在Excel中工作,然后将其嵌入到网页中,希望嵌入的版本能够真正更新数据链接.

现在,Power Query 运行如下所示:

let
    Source = Web.Page(Web.Contents("https://forecast.weather.gov/product.php?site=NWS&issuedby=LWX&product=FWF&format=txt&version=1&glossary=0")),
    Data = Source{0}[Data],
    Children = Data{0}[Children],
    Children1 = Children{1}[Children],
    Children2 = Children1{12}[Children],
    Children3 = Children2{7}[Children],
    #"Replaced Value" = Table.ReplaceValue(Children3,"PAZ064","$$",Replacer.ReplaceText,{"Text"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Replaced Value", "Text", Splitter.SplitTextByDelimiter("$$", QuoteStyle.None), {"Text.1", "Text.2", "Text.3", "Text.4", "Text.5", "Text.6", "Text.7", "Text.8", "Text.9", "Text.10", "Text.11", "Text.12", "Text.13", "Text.14", "Text.15", "Text.16", "Text.17", "Text.18", "Text.19", "Text.20", "Text.21", "Text.22", "Text.23", "Text.24", "Text.25", "Text.26", "Text.27", "Text.28", "Text.29", "Text.30", "Text.31", "Text.32", "Text.33", "Text.34", "Text.35", "Text.36", "Text.37", "Text.38", "Text.39", "Text.40", "Text.41", "Text.42", "Text.43", "Text.44", "Text.45", "Text.46", "Text.47", "Text.48", "Text.49", "Text.50", "Text.51", "Text.52", "Text.53", "Text.54", "Text.55", "Text.56", "Text.57", "Text.58", "Text.59", "Text.60", "Text.61", "Text.62", "Text.63", "Text.64", "Text.65", "Text.66", "Text.67", "Text.68", "Text.69", "Text.70", "Text.71", "Text.72", "Text.73", "Text.74", "Text.75", "Text.76", "Text.77", "Text.78", "Text.79", "Text.80", "Text.81", "Text.82", "Text.83", "Text.84", "Text.85", "Text.86", "Text.87", "Text.88", "Text.89", "Text.90", "Text.91", "Text.92", "Text.93", "Text.94", "Text.95", "Text.96", "Text.97", "Text.98", "Text.99", "Text.100"}),
    #"Transposed Table" = Table.Transpose(#"Split Column by Delimiter"),
    #"Removed Blank Rows" = Table.SelectRows(#"Transposed Table", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    #"Transposed Table1" = Table.Transpose(#"Removed Blank Rows"),
    #"Removed Columns" = Table.SelectColumns(#"Transposed Table1",{"Column2", "Column12", "Column19", "Column37"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Column2", "Discussion"}, {"Column12", "C & SE Montgomery, MD"}, {"Column19", "NW Prince Willam, VA"}, {"Column37", "W Mineral"}})
in
    #"Renamed Columns"

(我很抱歉没有在上面的代码中添加注释,但我不确定是否可以添加注释。)

这可以很好地导入到表格中,但是源文档中的换行符被消除了,因此

的网页数据
755
FNUS51 KLWX 191438
FWFLWX

Fire Weather Planning Forecast for W and CTL MD...E WV...N VA and DC
National Weather Service Baltimore MD/Washington DC
937 AM EST Thu Dec 19 2024

看起来像

755FNUS51 KLWX 191438FWFLWXFire Weather Planning Forecast for W and CTL MD...E WV...N VA and DCNational Weather Service Baltimore MD/Washington DC937 AM EST Thu Dec 19 2024

并发症:

  1. 这需要嵌入到网页中,所以我不能使用宏。我什至不确定在网络界面中刷新连接是否可行。
  2. 我对 PHP 的了解不够,也不了解 PHP 如何与 WordPress 交互来创建合适的插件。 (我对基本的 HTML 和 CSS 以及极其初级的 JavaScript 还算不错,所以如果我有时间学习的话我就能做到这一点。)
  3. 整体组织结构过于复杂,无法将工作簿分享给大家。
html excel wordpress html-parsing
1个回答
0
投票

有趣的是,以前从未处理过这样的问题。我的方法是将每个

CR
替换为
CR
LF
的组合,但我还改变了转换数据的方式,使其更加动态:

let
    Source = Web.Page(Web.Contents("https://forecast.weather.gov/product.php?site=NWS&issuedby=LWX&product=FWF&format=txt&version=1&glossary=0")),
    Data = Source{0}[Data],
    Children = Data{0}[Children],
    Children1 = Children{1}[Children],
    Children2 = Children1{12}[Children],
    Children3 = Children2{7}[Children],
    #"Replaced Value" = Table.ReplaceValue(Children3, "PAZ064", "$$", Replacer.ReplaceText, {"Text"}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Replaced Value", {{"Text", Splitter.SplitTextByDelimiter("$$", QuoteStyle.None)}}), "Text"),
    #"Removed Blank Rows" = Table.SelectRows(#"Split Column by Delimiter", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Blank Rows", {"Kind", "Name", "Children"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Text", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each Text.Contains([Text], "Central and Southeast Montgomery")),
    #"Replace CR with CRLF" = Table.TransformColumns(#"Filtered Rows", {{"Text", each Text.Replace(_, "#(cr)", "#(cr,lf)")}})
in
    #"Replace CR with CRLF"

PowerBI 表中的输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.