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

如何使用DataNitro将值写入Excel中的多个单元格,excel,datanitro,Excel,Datanitro,我正在尝试使用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

我正在尝试使用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)).值
状态=单元格范围((2,3)、(120,3))。值
对于不同的x:
如果x<-10:
Status=“暂停”
###我不知道该放什么
其他:
Status=“活动”
###我不知道该放什么

如果这个问题太愚蠢了,谢谢你,对不起

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

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
difference=CellRange((2,2)、(120,2)).值
#不需要读取当前状态值
i=0
对于不同的x:
如果x<-10:
Status=“暂停”
单元格((2+i),3)。value=“暂停”
其他:
Status=“活动”
单元格((2+i),3)。value=“活动”
i+=1
在Python中,更好的方法是使用关键字,它会自动跟踪计数器:

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"
difference=CellRange((2,2)、(120,2)).值
i=0
对于枚举中的i,x(差异):
如果x<-10:
Status=“暂停”
单元格((2+i),3)。value=“暂停”
其他:
Status=“活动”
单元格((2+i),3)。value=“活动”

太好了,本,谢谢!有没有办法设置从第一个单元格到最后一个填充单元格的单元格范围?如:difference=CellRange((2,2),(#last,2)).valueThere是:可以使用Cell.vertical获取列(使用Cell.horizontal获取行)。例如,差=单元格(2,2)。垂直