[英]Setting values in openpyxl load_workbook, use_iterators
I want to read a xlsx file, change all the values less than say 0.0001 to 0.01. 我想读取一个xlsx文件,将所有小于0.0001的值更改为0.01。 I can read the values and print them, but I can't change them ? 我可以读取并打印这些值,但是不能更改它们?
import pylab
from openpyxl import load_workbook
wb = load_workbook(filename = 'TF-Automation.xlsx', use_iterators=True)
ws = wb.get_sheet_by_name(name = 'Huvudmatris')
for row in ws.iter_rows():
for cell in row:
if cell.internal_value < 0.00001:
cell.set_value = 0.000001
print cell.internal_value
from the documentation : http://pythonhosted.org/openpyxl/api.html 从文档中获取: http : //pythonhosted.org/openpyxl/api.html
openpyxl.reader.excel.load_workbook(filename,use_iterators=False)[source] :
Open the given filename and return the workbook Parameters: filename (string) – the path to open use_iterators (bool) – use lazy load for cells Return type: openpyxl.workbook.Workbook
When using lazy load, all worksheets will be
openpyxl.reader.iter_worksheet.IterableWorksheet
and the returned workbook will be read-only. 使用延迟加载时,所有工作表openpyxl.reader.iter_worksheet.IterableWorksheet
, 返回的工作簿为只读。
don't use use_iterators=True
. 不要使用use_iterators=True
。 Also, if you need to call .save(filename)
if you want to update the xlsx with your new values. 另外,如果要使用新值更新xlsx,则需要调用.save(filename)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.