伙计们,我被困在这种糟糕的情况下,我必须在excel中放置多个列表,在特定的单元格协调中,并且找不到任何解决方案。
目前的执行情况:
@xl_func("string key: object", macro=True)
def calc(key) -> object:
result = [[1, 2], [3, 4]]
from pyxll import xl_app, XLCell
caller = xlfCaller()
address = caller.address
xl = xl_app()
xl_range = xl.Range(address)
one_below = xl_range.GetOffset(RowOffset=1, ColumnOffset=0)
XLCell.from_range(one_below)
cell = XLCell.from_range(one_below)
cell.options(type="var", auto_resize=True).value = result
return "123"这段代码非常适合于一组数据。但是现在我想在一个特定的单元格坐标上添加多个这样的数据集。如果可能的话,如下所示:
@xl_func("string key: object", macro=True)
def calc(key) -> object:
result = [[1, 2], [3, 4]]
from pyxll import xl_app, XLCell
caller = xlfCaller()
address = caller.address
xl = xl_app()
xl_range = xl.Range(address)
one_below = xl_range.GetOffset(RowOffset=1, ColumnOffset=0)
XLCell.from_range(one_below)
cell = XLCell.from_range(one_below)
#This need to go between A1:A2 to B1:B2
cell.options(type="var", auto_resize=True).value = result
#This need to go between D1:D2 to E1:E2
cell.options(type="var", auto_resize=True).value = result2
#This need to go between F1:F2 to G1:G2
cell.options(type="var", auto_resize=True).value = result3
return "123"
Env:
Python 3.8.6 32 bit
Pyxll 5.0.5 32 bit发布于 2020-12-17 19:59:59
您可以将XLCell.from_range作为字符串传递给COM范围对象或地址。
c = XLCell.from_range("A1")
c.options(auto_resize=True).value = x此外,还可以使用Application.Range从地址获取COM范围,例如:
xl = xl_app()
r = xl.Range("A1")
r.Value = x
# or using XLCell
c = XLCell.from_range(r)
c.options(auto_resize=True).value = x如果您需要的话,您也可以在地址中包括工作簿和工作表,如"Book1Sheet1!A1“。
详情请见https://www.pyxll.com/docs/api/classes.html#pyxll.XLCell.from_range。
这篇FAQ文章也应该有助于https://support.pyxll.com/hc/en-gb/articles/360044507453-Writing-arrays-back-to-Excel
https://stackoverflow.com/questions/65346213
复制相似问题