简体   繁体   English

openpyxl如何将单元格设置为“忽略错误”?

[英]openpyxl How to set cell to 'ignore error'?

I'm setting a row of cells to a formula like: 我正在将一行单元格设置为如下公式:

TweleveWeekRollingFormula = "=AVERAGE(B" + str(ExcelRowNumber + 20) + ":B" + str(ExcelRowNumber + 31) + ")"

This works fine but causes excel to display a small green triangle in the cells top left corner: 这工作正常,但导致excel在单元格左上角显示一个小的绿色三角形: Excel中显示错误

I can clear the error manually in excel by clicking on the cells popup menu (!) and selecting 'Ignore Error'. 我可以通过单击单元格弹出菜单(!)并选择“忽略错误”在excel中手动清除错误。 Is there a way to do this with openpyxl? 有没有办法用openpyxl做到这一点? (and not display the green triangle) (而不是显示绿色三角形)

Those numbers are strings. 这些数字是字符串。 The way you are going to make this go away as well as ensure that you won't have calculation errors is by setting those number values to floats (since you want decimals). 您要使其消失的方式以及确保您不会有计算错误的方法是将这些数值设置为浮点数(因为您需要小数)。 They are being entered in as strings. 它们以字符串形式输入。 You don't want that. 你不希望这样。 The only reason why it works fine now is because Excel converts those string to numbers for the formula successfully. 它现在工作正常的唯一原因是因为Excel成功地将这些字符串转换为公式的数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM