如何使用xlwings为命名范围内的一个单元格赋值?(How assign value to one cell in named range by using xlwings?)

编程入门 行业动态 更新时间:2024-10-28 05:16:25
如何使用xlwings为命名范围内的一个单元格赋值?(How assign value to one cell in named range by using xlwings?)

我也是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 = values

Alternatively, 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'

更多推荐

本文发布于:2023-07-20 06:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1195206.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:范围内   赋值   如何使用   单元格   xlwings

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!