如何使用DataNitro将值写入Excel中的多个单元格

我正在尝试DataNitro来自动执行一些Excel任务,但是我没有掌握如何为与他人有关的多行编写新的值,

例如:我希望它从第1列中读取值,并根据条件在第2列中写入响应。

简单的例子:

difference = CellRange((2,2),(120,2)).value Status = CellRange((2,3),(120,3)).value for x in difference: if x < -10: Status = "Paused" ###here i don't know what to put else: Status = "Active" ###here i don't know what to put 

如果问题太愚蠢,谢谢,抱歉!

最好的办法是在你的循环中保留一个计数器:

 difference = CellRange((2,2),(120,2)).value # there's no need to read in the current Status value i = 0 for x in difference: if x < -10: Status = "Paused" Cell((2 + i), 3).value = "Paused" else: Status = "Active" Cell((2 + i), 3).value = "Active" i += 1 

在Python中执行此操作的更好方法是使用enumerate关键字,该关键字自动跟踪计数器:

 difference = CellRange((2,2),(120,2)).value i = 0 for i, x in enumerate(difference): if x < -10: Status = "Paused" Cell((2 + i), 3).value = "Paused" else: Status = "Active" Cell((2 + i), 3).value = "Active"