0
Google 스프레드 시트에 셀을 삽입하거나 업데이트하려고합니다. Google api와 Python을 처음 사용하기 때문에 무언가를 할 수 있습니다. 저의 삶을 위해 그것을보십시오.Gdata, Python Google 스프레드 시트 API 클라이언트로 셀 삽입
현재 내 코드는 기존 셀을 업데이트하지만 "batchRequest.AddInsert (newCell)"을 주석 처리 할 때 새 셀을 삽입하지 않습니다 (빈 셀이 비어 있음). 하지만 왼쪽에서 상태 코드 500이 반환되고 약간의 도움이 xml의 힙.
코드 (부품)
def setRowEntries(self, cohort_key=None):
cohort = self.GetCohort(cohort_key)
gd_client = gdata.spreadsheet.service.SpreadsheetsService()
gd_client.email = email
gd_client.password = password
gd_client.source = 'YOUR_APP_NAME'
# LOGIN
try:
# log in
gd_client.ProgrammaticLogin()
except socket.sslerror, e:
logging.error('Spreadsheet socket.sslerror: ' + str(e))
return False
# KEY FOR SHEET
key = '0At**************************Gc'
# LOOKUP FOR WORKSHEET KEY
GID_TABLE = {
'android_users_by_week_by_registration' : 'od6'
}
wksht_id =''
wksht_id = GID_TABLE[cohort_key]
# create a cells feed and batch request
cells = gd_client.GetCellsFeed(key, wksht_id)
batchRequest = gdata.spreadsheet.SpreadsheetsCellsFeed()
#TODO SET TITLE
#resize worksheet
# cells.col_count = len(cohort[0])
# cells.row_count = len(cohort)
rowcursor = 0
for myrow in cohort:
colcursor = 0
#print ("row ::"+str(myrow))
for mycell in myrow:
#print ("cell::"+str(mycell))
found = 0
#print ("try and place"+str(rowcursor)+','+str(colcursor))
for myentry in cells.entry:
if ((int(myentry.cell.row) == int(rowcursor+1)) and (int(myentry.cell.col) == int(colcursor+1))):
print "updating "+myentry.cell.text+" to "+str(mycell)
myentry.cell.inputValue = str(mycell)
batchRequest.AddUpdate(myentry)
found = 1
if not found:
print "inserting "+str(mycell)+" at Cell "+ str(rowcursor+1)+'_'+str(colcursor+1)
newCell = gdata.spreadsheet.SpreadsheetsCell()
newCell.cell = gdata.spreadsheet.Cell(inputValue=str(mycell), text=None, row=str(rowcursor+1), col=str(colcursor+1))
print newCEll.inpu
batchRequest.AddInsert(newCell)# the broken part
colcursor = colcursor + 1
rowcursor = rowcursor + 1
updated = gd_client.ExecuteBatch(batchRequest, cells.GetBatchLink().href)
if updated:
print "Sucessfull!"+str(updated)
else:
print "Failed!"
오류 (부분)
type="text">Internal Error</ns0:content><ns1:id xmlns:ns1="http://schemas.google.com/gdata/batch">1626</ns1:id><ns0:title type="text">Error</ns0:title><ns1:status code="500" reason="Internal Error" xmlns:ns1="http://schemas.google.com/gdata/batch" /><ns1:operation type="insert" xmlns:ns1="http://schemas.google.com/gdata/batch" /><ns0:updated>2012-10-17T09:39:18.946Z</ns0:updated></ns0:entry><ns0:entry><ns0:id>1627</ns0:id><ns0:content type="text">Internal Error</ns0:content><ns1:id xmlns:ns1="http://schemas.google.com/gdata/batch">1627</ns1:id><ns0:title type="text">Error</ns0:title><ns1:status code="500" reason="Internal Error" xmlns:ns1="http://schemas.google.com/gdata/batch" /><ns1:operation type="insert" xmlns:ns1="http://schemas.google.com/gdata/batch" /><ns0:updated>2012-10-17T09:39:18.946Z</ns0:updated></ns0:entry><ns0:entry><ns0:id>1628</ns0:id><ns0:content type="text">Internal Error</ns0:content><ns1:id xmlns:ns1="http://schemas.google.com/gdata/batch">1628</ns1:id><ns0:title type="text">Error</ns0:title><ns1:status code="500" reason="Internal Error" xmlns:ns1="http://schemas.google.com/gdata/batch" /><ns1:operation type="insert" xmlns:ns1="http://schemas.google.com/gdata/batch" /><ns0:updated>2012-10-17T09:39:18.946Z</ns0:updated></ns0:entry><ns0:entry><ns0:id>1629</ns0:id><ns0:content type="text">Internal Error</ns0:content><ns1:id xmlns:ns1="http://schemas.google.com/gdata/batch">1629</ns1:id><ns0:title type="text">Error</ns0:title><ns1:status code="500" reason="Internal Error" xmlns:ns1="http://schemas.google.com/gdata/batch" /><ns1:operation type="insert" xmlns:ns1="http://schemas.google.com/gdata/batch" /><ns0:updated>2012-10-17T09:39:18.946Z</ns0:updated></ns0:entry><ns0:entry><ns0:id>1630</ns0:id><ns0:content
나는 이해하기 구글 API 문서가 매우 어려운 발견하고 예를 몇 너무 좁게 범위이었다. 당신이 나에게 어떤 일을 잘못했는지 알려 주실 수 있으면
공식 API를 사용하는 것에 지친 경우 [도서관] (https://github.com/burnash/gspread/)을 확인하십시오. 1 년 전에 해킹했습니다. 가능한 한 간단하게 API를 유지하려고 노력했습니다. – Burnash