【日常水帖】追加内容到 excel 并且不覆盖原有的内容

from openpyxl import load_workbook
workbook = load_workbook(filename = “test.xlsx”)
sheet = workbook.active
data = [
[“唐僧”,“男”,“180cm”],
[“孙悟空”,“男”,“188cm”],
[“猪八戒”,“男”,“175cm”],
[“沙僧”,“男”,“176cm”],
]
for row in data:
sheet.append(row)
sheet.row_dimensions[1].height = 50 # 设置高度 第一行
sheet.column_dimensions[“B”].width = 20 # 设置宽度 B 列 不选取索引为整个 sheet 表的所有单元格
workbook.save(filename = “test.xlsx”)

可以结合爬虫循环抓取数据并追加到 excel