I am using the following code in ubuntu 20.
import pyoo
import os
import uno
import pandas as pd
os.system("/usr/lib/libreoffice/program/soffice.bin --headless --invisible --nocrashreport --nodefault --nofirststartwizard --nologo --norestore --accept='socket,host=localhost,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext'")
df=pd.Dataframe()
df['Name']=['Anil','Raju','Arun']
df['Age']=['32','34','45']
desktop = pyoo.Desktop('localhost', 2002)
doc = desktop.open_spreadsheet("/home/vivek/Documents/Libre python trial/oi_data.ods")
sh1=doc.sheets['oi_data']
sh1[1,4].value=df
doc.save()
It gives all data in a single cell as a string:
'Name age0 Anil 321 Raju 342 Arun 45'
I want to write a DataFrame in LibreOffice Calc in columns & rows of sheet like this :
Name age
0 Anil 32
1 Raju 34
2 Arun 45
example code used in xlwings in window os just for reference (I want to achieve same with simple code in Libreoffice calc in ubuntu/Linux, if possible..)
import pandas as pd
import xlwings as xlw
# Connecting with excel workbook
file=xlw.Book("data.xlsx")
# connection with excel sheet
sh1=file.sheets('sheet1')
df=pd.DataFrame()
df['Name']=['Anil','Raju','Arun']
df['Age']=['32','34','45']
sh1.range('A4').value=df