苗火 Nicholas
[python]Edit excel by xlrd and xlwt
2021-8-26 萧
import xlrd
import xlwt

def edit_excel(fromFile, fromSheet):
w_workbook = xlwt.Workbook()
w_sheet = w_workbook.add_sheet("nicholas", cell_overwrite_ok=True)


workbook = xlrd.open_workbook(fromFile)
print(workbook.sheet_names())

sheet = workbook.sheet_names()[fromSheet]
sheet = workbook.sheet_by_index(fromSheet)

print(sheet)
row = sheet.nrows
col = sheet.ncols
print(row, col)

for i in range(0, row):
for j in range(0, col):
v = sheet.cell(i, j).value
w_sheet.write(i, j, v)
print(v," ", end="")
print(" ")
w_sheet.write(i,5, "write")
w_sheet.write(i,6, "log.anycle.com")


w_workbook.save("nicholas.xls")


edit_excel("nicholas.xls", 0)
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容