Adding a new row of data to an existing ods sheet

I'm running a python script to automate some of my day-to-day tasks at work. One task I'm trying to do is simply add a row to an existing ods sheet that I usually open via LibreOffice.

This file has multiple sheets and depending on what my script is doing, it will add data to different sheets.

The thing is, I'm having trouble finding a simple and easy way to just add some data to the first unpopulated row of the sheet.

Reading about odslib3, pyexcel and other packages, it seems that to write a row, I need to specifically tell the row number and column to write data, and opening the ods file just to see what cell to write and tell the pythom script seems unproductive

Is there a way to easily add a row of data to an ods sheet without informing row number and column ?

Upvotes: 1

Views: 829

Answers (1)

BuddyCarver
BuddyCarver

Reputation: 41

If I understand the question I believe that using a .remove() and a .append() will do the trick. It will create and populate data on the last row (can't say its the most efficient though). EX if:

from pyexcel_ods3 import save_data
from pyexcel_ods3 import get_data
data = get_data("info.ods")

print(data["Sheet1"])

[['first_row','first_row'],[]]

if([] in data["Sheet1"]):
    data["Sheet1"].remove([])#remove unpopulated row
data["Sheet1"].append(["second_row","second_row"])#add new row
print(data["Sheet1"])

[['first_row','first_row'],['second_row','second_row']]

Upvotes: 1

Related Questions