xls

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import xlrd  
from xlutils.copy import copy

# 需要导入xls文件路径
excel_path = r"D:\Users\zx\Desktop\information.xls"

rexcel = xlrd.open_workbook(excel_path, formatting_info=True)
excel = copy(rexcel)

# 获取第0页
table = excel.get_sheet(0)

# 纵坐标, 横坐标
rows = rexcel.sheets()[0].nrows
cols = rexcel.sheets()[0].ncols

# 样式
style = xlwt.easyxf('pattern: pattern solid, fore_colour red')

# 写入
# 横坐标, 纵坐标, 值, 样式
table.write(row, col, tag, style)

# 保存
excel.save(r"D:\Users\zx\Desktop\information.xls")

xls和csv

1
2
3
4
import pandas as pd

dt = pd.DataFrame(peo)
dt.to_excel(peo_url, index=0)