我是使用 Smartsheet 的新手,我正在尝试访问列的值并将它们存储在列表中,并且我能够通过索引访问这些值。在我的用例中,人们可以从智能表中删除随机列,这可能会导致我的索引编号在读取数据时受到影响。例如 - 我的 smartsheet 如下所示:
输入电压 | 所有者 | 使用 | 地点
123 abc 测试 CA
456 xyz 产品 TX
到目前为止我用来访问数据的代码是:
import smartsheet
from simple_smartsheet import Smartsheet
from simple_smartsheet.models import Sheet, Column, Row, Cell, ColumnType
from pprint import pprint
import pandas as pd
import re
import sasl
import json
from fastparquet import write
# from influxdb import InfluxDBClient
import thrift_sasl
import prestodb
import s3fs
import boto3
from pyhive import hive
smartsheet = smartsheet.Smartsheet('adjgdjcdjchbdclkcn')
# Get current user
#user_profile = smartsheet.Users.get_current_user()
# Get all columns.
MySheet = smartsheet.Sheets.get_sheet(1234567891234567)
Vin = []
Owner = []
Use = []
Location = []
def Data():
for RowIndex in range(0, len(MySheet.rows)):
Vin.append(MySheet.rows[RowIndex].cells[2].display_value)
Use.append(MySheet.rows[RowIndex].cells[3].display_value)
Owner.append(MySheet.rows[RowIndex].cells[4].display_value)
Location.append(MySheet.rows[RowIndex].cells[5].display_value)
print(Vin)
print(Use)
Print(Owner)
Print(Location)
我想要的结果是(使用列名而不是索引):
输入电压 = [123, 456]
所有者 = [abc, xyz]
使用 = [测试,产品]
位置 = [加利福尼亚州,德克萨斯州]
现在,不是通过索引访问值,而是如何使用列名将值附加到列表中?非常感谢任何帮助或领导。先感谢您!