我也是Python和xlwings的新手。 我需要逐步为命名范围中的每个单元格分配不同的值。
xw.Range('命名范围')。value = [new_cell_values_as_list_of_lists]
这是如何将值分配给全范围Named range的示例。 这不是我现在所需要的。
我已经搜索了xlwings-docs,stackoverflow等但是没有任何想法......也没有
xw.Range(1,'Named range', 22).value = 'yes'也不
xw.Range(1, 'Named range', '22').value = 'yes'不工作。 请帮帮我。
I'm a novice with both Python and xlwings too. I need to assign a different value for each cell in named range step by step.
xw.Range('Named range').value = [new_cell_values_as_list_of_lists]
This is an example how to assign values to full range Named range. This is not what I need for now.
I've searched the xlwings-docs, stackoverflow and so but without any idea... Ways neither
xw.Range(1,'Named range', 22).value = 'yes'nor
xw.Range(1, 'Named range', '22').value = 'yes'do not work. Please help me.
最满意答案
在xlwings的未来版本中,您应该能够直接在Range上使用切片表示法,但就目前而言,可能最简单,最有效的方法(只有一个读写操作)是读取整个Range,对它进行操作Python端并将整个Range写回:
values = xw.Range(1, 'Named range').value values[1][1] = 'yes' xw.Range(1, 'Named range').value = values或者,根据您的情况,这可能也是可能的:
first_col = xw.Range(1, 'Named range').column first_row = xw.Range(1, 'Named range').row xw.Range(1, (first_col + 1, first_row + 1)).value = 'yes'In a future version of xlwings, you should be able to use slice notation on a Range directly, but for now, probably the easiest and most efficient method (only one read and write operation) is to read in the whole Range, do manipulations on the Python side and write the whole Range back:
values = xw.Range(1, 'Named range').value values[1][1] = 'yes' xw.Range(1, 'Named range').value = valuesAlternatively, depending on your situation, this might also be a possibility:
first_col = xw.Range(1, 'Named range').column first_row = xw.Range(1, 'Named range').row xw.Range(1, (first_col + 1, first_row + 1)).value = 'yes'更多推荐
发布评论