【问题标题】:Convert multiple tables from a html file to Excel preserving the CSS styles将多个表格从 html 文件转换为 Excel,保留 CSS 样式
【发布时间】:2019-03-13 14:39:33
【问题描述】:

我有一个 html 文件和一些表格,我想将此 html 转换为 Excel。实际上,我可以复制所有页面并将其粘贴到 Excel 中,但我必须在其他 html 文件中重复此过程。我可以在这个过程中使用 python 吗?

【问题讨论】:

    标签: python html excel html-table


    【解决方案1】:

    tablepyxl 应该做你想做的事。

    【讨论】:

      【解决方案2】:

      您可以在 Python 中使用 Pandas。

      import pandas as pd
      
      df = pd.read_html(html_file)
      
      writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
      
      df.to_excel(writer, sheet_name='Sheet1')
      
      writer.save()
      

      【讨论】:

      • 此文件不是表格。熊猫将其视为一个列表,这就是为什么“AttributeError:'list' 对象没有属性'to_excel'”@Irfanuddin Shafi
      • 我希望所有的 CSS 样式颜色保持相同的样式。你上面写的东西是不可能的。
      • 我不确定这是怎么做到的。希望有人回答。我的脚本只将 html 表格转换为 excel。
      猜你喜欢
      • 1970-01-01
      • 2018-01-17
      • 2019-01-14
      • 2011-11-18
      • 1970-01-01
      • 2015-04-20
      • 2020-06-08
      • 2018-02-03
      • 2023-03-18
      相关资源
      最近更新 更多