我在这里得到的问题是,我尝试保存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'`
发布于 2018-07-25 08:42:24
replace()
方法返回被替换的字符串,但不更新传递给它的字符串。
只需替换:
target_column.replace("a", "b")
通过以下方式:
target_column = target_column.replace("a", "b")
https://stackoverflow.com/questions/51509313
复制相似问题