几个小时后,我设法自己完成了肮脏的工作。
所以我有从已经打开的谷歌电子表格获得的单元格范围内的数据:
cell_list = worksheet.range('A1:J8')
这包含<Cell R1C1 'Sandero'>
但也<Cell R1C2 '23'>
等等。
现在,为了从<Cell R1C1
零件中获取稍后在项目中用于创建图形的坐标 (1,1),我意识到最好的方法是这样的:
for cell in cell_list: # will check all elements of the worksheet range A1:J8
print cell # for example at one point this is <Cell R1C1 'Sandero'>
print cell.value # Sandero
cella = re.findall(r'\d+',str(cell)) # will take only numbers from <Cell R1C1 'Sandero'>
print cella[:2] # will give you the first two elements of list cella.
#In this case '1','1'. This is exactly what I need.
# to specify [:2] it's important if it would be <Cell R1C2 '23'>.
# Otherwise cella would return '1','2','23'. Nasty.
# I need only coordinates to use them as index in graf.
然后必须小心将我的坐标引用为int(cella[0])
,int(cella[1])
因为我将它们作为字符串从re.findall(r'\d+',str(cell))
我相信我的解决方案非常混乱且过于复杂,但至少它有效。我仍在等待该堆栈溢出,所以我希望有人有更好的主意。