【发布时间】:2019-01-01 16:58:24
【问题描述】:
我在这里得到一个问题,我在替换其中的字符串后尝试保存 excel 文件,一切正常,但似乎没有写回 excel 文件。谁能给我解释一下?非常感谢!
from xlrd import open_workbook
from xlutils.copy import copy
rb = open_workbook('C:\\Users\\Eric\\Desktop\\test.csv')
wb = copy(rb)
sheet = rb.sheet_by_index(0)
sheet.cell_value(0, 0)
first_row_list = sheet.row_values(0)
name_index = first_row_list.index('Name')
print(name_index)
for i in range(sheet.nrows):
target_column = sheet.cell_value(i, name_index)
print(i)
target_column.replace("a", "b")
print(target_column.replace("a", "b"))
wb.save('C:\\Users\\Eric\\Desktop\\test.csv'`
【问题讨论】:
-
print(target_column.replace("a", "b")) 效果很好,它可以打印出替换的东西,但它似乎无法存储在 excel 中。此刻的任何帮助都非常感谢!!