如何利用python将中文文档写入excel,并且单元格自动调整宽度

发布网友 发布时间:2022-04-23 08:38

我来回答

1个回答

热心网友 时间:2022-04-07 07:12

# 需安装 xlrd-0.9.2 和 xlutils-1.7.1 这两个模块
from xlwt import Workbook, Formula
import xlrd
book = Workbook()
sheet1 = book.add_sheet('Sheet 1')
sheet1.write(0,0,10)
sheet1.write(0,1,20)
sheet1.write(1,0,Formula('A1/B1'))
sheet2 = book.add_sheet('Sheet 2')
row = sheet2.row(0)
row.write(0,Formula('sum(1,2,3)'))
row.write(1,Formula('SuM(1;2;3)'))
row.write(2,Formula("$A$1+$B$1*SUM('ShEEt 1'!$A$1:$b$2)"))
book.save('formula.xls')
book = xlrd.open_workbook('formula.xls')
sheet = book.sheets()[0]
nrows=sheet.nrows
ncols=sheet.ncols
for i in range(nrows):
for j in range(ncols):
print (sheet.cell(i,j).value)

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com