1

我想知道是否有任何方法(阅读:hacks)使用 Google 电子表格 API,它不会强加标题行中的值以小写字母表示且没有空格的限制。我知道我可以只使用基于单元格的提要,但这会给我的应用程序带来开销,必须跟踪与特定列名对应的列号。

有没有人有替代方法?

(我还注意到Google Spreadsheet API Docs没有提及标题行名称限制,我不得不四处搜索以找出我的代码最初无法正常工作的原因)

4

2 回答 2

7

您不必实际更改电子表格中的任何标题并受制于某些限制。基本上,API 将您的标题转换为“小写无空格”格式,您可以这样访问它们。因此,尝试访问带有标题“我的标题”的列将通过查询“myheader”列来工作。原始电子表格中的标题保持不变并采用所需的格式。

于 2012-07-23T01:44:41.197 回答
2
#header_names = list of header names
spreadclient = gdata.spreadsheets.client.SpreadsheetsClient(source='Your App Name')

#Add a line to authenticate the spreadsheet client

spreadsheet_key = spreadsheet.GetId().split("%3A")[1]
worksheets = spreadclient.GetWorksheets(spreadsheet_key)
#get worksheet id
wsid =  worksheets.entry[0].GetWorksheetId()
#header row can only be accessed via cellfeed
for i,name in enumerate(header_names):
    cellentry= spreadclient.GetCell(spreadsheet_key, worksheet_id=wsid, row_num=1, col_num=1+i)
    #update value
    cellentry.cell.input_value = name #TODO: do batch update instead
    spreadclient.update(cellentry)
于 2012-10-14T11:54:23.490 回答