html table py,GitHub - martsberger/tablepyxl: A bridge between html tables and openpyxl

68747470733a2f2f7472617669732d63692e6f72672f6d617274736265726765722f7461626c657079786c2e7376673f6272616e63683d6d6173746572

tablepyxl - A python library to convert html tables to Excel

Introduction

Tablepyxl is a bridge between html tables and openpyxl.

If you can make an html table, you can make an Excel workbook.

Usage

If your html table is in a string, you can write an Excel file with the document_to_xl function:

from tablepyxl import tablepyxl

table = "

" "

"

"

"

Header 1"

"

Header 2"

"

"

"

"

"

"

"

"

"

Cell contents 1"

"

Cell contents 2"

"

"

"

"

tablepyxl.document_to_xl(table, "/path/to/file")

If your html table is in a file, read it into a string first:

from tablepyxl import tablepyxl

doc = open("/file/with/html/table", "r")

table = doc.read()

tablepyxl.document_to_xl(table, "/path/to/output")

Convert your html to an openpyxl workbook object instead of a file so that you can do further work:

from tablepyxl import tablepyxl

doc = open("/file/with/html/table", "r")

table = doc.read()

wb = tablepyxl.document_to_wb(table)

# For example, you can add another document to the same workbook

# in a new sheet:

doc2 = open("/file/with/html/table2", "r")

table2 = doc2.read()

wb = tablepyxl.document_to_wb(table, wb=wb)

Notes:

A document with more than one table will write each table to a separate sheet

Sheet names match the name attribute of the table element

Multiple tables can be added to the same sheet using the insert_table method.

Styling and Formatting

Tablepyxl intends to support all of the style and formatting options supported by Openpyxl. Here are the

currently supported styles:

Font

bold via the font-weight style, e.g.

color via the color style, e.g.

Alignment

horizontal via the text-align style

vertical via the vertical-align style

wrap_text via the white-space style

Fill

Solid background color via the background-color style

Border

style and color for the top border via border-top-style and border-top-color styles

Cell types

Cell types can be set by adding any of the following classes to the td element:

TYPE_STRING

TYPE_FORMULA

TYPE_NUMERIC

TYPE_BOOL

TYPE_CURRENCY

TYPE_NULL

TYPE_INLINE

TYPE_ERROR

TYPE_FORMULA_CACHE_STRING

TYPE_INTEGER

Number formatting

Currency is formatted using FORMAT_CURRENCY_USD_SIMPLE

Dates are formatted using 'mm/dd/yyyy'

Numeric values are formatted with commas every 3 digits if the commas are present in the html

Merging

Cells can be merged using the colspan and rowspan attributes of td elements

License

Contributors

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值