Python pygsheet中的GSheet包装策略
在Pygsheet引用文档中,它显示一个wrap_策略属性Python pygsheet中的GSheet包装策略,python,google-sheets,google-sheets-api,pygsheets,Python,Google Sheets,Google Sheets Api,Pygsheets,在Pygsheet引用文档中,它显示一个wrap_策略属性 wrap_strategy How to wrap text in this cell. Possible wrap strategies: ‘OVERFLOW_CELL’, ‘LEGACY_WRAP’, ‘CLIP’, ‘WRAP’. Reference: api docs 但在实际代码中,如果我要cell.wrap\u策略='wrap'我会得到一个错误TypeError:'str'对象不可调用 实际代码段: for cell in
wrap_strategy
How to wrap text in this cell. Possible wrap strategies: ‘OVERFLOW_CELL’, ‘LEGACY_WRAP’, ‘CLIP’, ‘WRAP’. Reference: api docs
但在实际代码中,如果我要cell.wrap\u策略='wrap'
我会得到一个错误TypeError:'str'对象不可调用
实际代码段:
for cell in wsheet.range("L3:L20").pop():
cell.wrap_strategy('WRAP')
我相信你的目标如下
- 您希望使用pygsheets设置包装策略
- 当我看到时,似乎这是类Cell,在本例中,我认为在wsheet.range(“L3:L20”).pop()中的单元格的
,您可以使用:
。(在这种情况下,设置为“L20”。)Cell.wrap\u策略='wrap'
for cell in wsheet.get_values("L3", "L20", returnas="range")._data.pop():
cell.wrap_strategy = "WRAP"
修改脚本:
或者,作为另一个方向,使用下面的get_值如何
for cell in wsheet.get_values("L3", "L20", returnas="range")._data.pop():
cell.wrap_strategy = "WRAP"
注:
- 如果上述修改不是您问题的直接解决方案,您能否在不提供个人信息的情况下提供整个脚本?通过这一点,我想确认一下
参考:
补充:
从你下面的答复中,
我希望它能从L3到L20。但在这个for循环中似乎只有L20被读取。你知道怎么做吗
当我在你的问题中看到你的脚本时,你想使用wsheet.range(“L3:L20”)
的最后一个元素,因为pop()
。所以我就这么做了。从您的回复来看,当您想通过修改脚本来设置“L3:L20”的wap策略时,下面的示例脚本如何
样本1:
样本2:
我希望它能从L3到L20。但在这个for循环中似乎只有L20被读取。“你知道怎么做吗?”路易吉·麦肯齐C.布里托感谢你的回答。给您带来不便,我深表歉意。关于你的答复,我又加了一个样品。你能确认一下吗?如果这不是你所期望的方向,我道歉。没必要道歉。你太棒了,我现在明白了。我忘了为什么我会弹出它,但我打算在所有基于range@LuigiMackenzie C.Brito感谢您的回复和再次测试。我很高兴你的问题解决了。也谢谢你。
for cell in wsheet.range("L3:L20"):
cell[0].wrap_strategy = "WRAP"
for cell in wsheet.get_values("L3", "L20", returnas="range")._data:
cell[0].wrap_strategy = "WRAP"