如何使用Python将.xls文件读入长字符串?我有成千上万的文件,想要替换'。'每个人都有','。
答案 0 :(得分:0)
是的,我做到了;不起作用。
嗯,它对我有用
import xlrd #for reading
import xlwt #for writing
def exceledit(path):
#Open the book:
wb = xlrd.open_workbook(path)
#Create new book
book = xlwt.Workbook(encoding="utf-8")
#Open sheet:
for i in range(0, len(wb.sheet_names())):
sh = wb.sheet_by_index(i)
sh_name = wb.sheet_names()[i]
print(sh_name)
#Create new sheet
sheet = book.add_sheet(sh_name)
#Read row:
for k in range(0, sh.nrows):
row = sh.row_values(k)
#Replace '.' with ',' in cell
for j in range(0, len(row)):
row[j] = str(row[j]).replace(".",",")
# Write row:
sheet.write(k,j,row[j])
#Save new book
book.save(path[:-4] + "_edited.xls")
exceledit('D:/files/myexcelfile.xls')
你能提供你的代码吗?