Reputation: 43
Here is the Image of Google sheet it still keep updating the same row but i want to append the data one by one enter image description here
def AddEventReasonRecord(self, EventReasonList):
try:
GlobalObj = Global()
records = []
rows = len(EventReasonList)
sheet_tile = self.GoogleSheetTitle()
ItemRow = int(GlobalObj.LasItemRow)
if rows > 0:
for index in range(rows):
ItemRow = ItemRow + 1
sheet_row = ItemRow + 1
Obj: EventReason = EventReasonList[index]
records.append(Cell(sheet_row, 1, Obj.EventID))
records.append(Cell(sheet_row, 2, Obj.EventName))
records.append(Cell(sheet_row, 3, Obj.Description))
records.append(Cell(sheet_row, 4, Obj.Status))
records.append(Cell(sheet_row, 5, Obj.Event))
records.append(Cell(sheet_row, 6, Obj.EmpStatus))
records.append(Cell(sheet_row, 7, Obj.Position))
records.append(Cell(sheet_row, 8, Obj.PayrollEvent))
records.append(Cell(sheet_row, 9, Obj.JobPortlet))
sheet_tile.update_cells(records)
[![enter code here][1]][1]
Upvotes: 1
Views: 326
Reputation: 201378
records
to the sheet of sheet_tile
.If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
append_row
is used.When your script is modified, how about the following modification?
sheet_tile.update_cells(records)
To:
sheet_tile.append_row([e.value for e in records], value_input_option="USER_ENTERED")
As another modification pattern, how about the following pattern?
for index in range(rows):
ItemRow = ItemRow + 1
sheet_row = ItemRow + 1
Obj: EventReason = EventReasonList[index]
records.append(Cell(sheet_row, 1, Obj.EventID))
records.append(Cell(sheet_row, 2, Obj.EventName))
records.append(Cell(sheet_row, 3, Obj.Description))
records.append(Cell(sheet_row, 4, Obj.Status))
records.append(Cell(sheet_row, 5, Obj.Event))
records.append(Cell(sheet_row, 6, Obj.EmpStatus))
records.append(Cell(sheet_row, 7, Obj.Position))
records.append(Cell(sheet_row, 8, Obj.PayrollEvent))
records.append(Cell(sheet_row, 9, Obj.JobPortlet))
sheet_tile.update_cells(records)
To:
for index in range(rows):
# ItemRow = ItemRow + 1
# sheet_row = ItemRow + 1
Obj: EventReason = EventReasonList[index]
records.append(Obj.EventID)
records.append(Obj.EventName)
records.append(Obj.Description)
records.append(Obj.Status)
records.append(Obj.Event)
records.append(Obj.EmpStatus)
records.append(Obj.Position)
records.append(Obj.PayrollEvent)
records.append(Obj.JobPortlet)
sheet_tile.append_row(records, value_input_option="USER_ENTERED")
If I misunderstood your question and this was not the direction you want, I apologize.
Upvotes: 2