Search Here

Import/Export/Download Data from Table into Excel File in Odoo14

 In this article, you will see how to import data coming from different tables into an excel file with a button click. To achieve this we are going to use pandas python library.

Import/Export/Download Data from Table into Excel File in Odoo14

How to Import/Export Data in Excel File From Odoo

We are going to import data from the PostgreSQL table into Excel File on button click. To import or download data into a spreadsheet (excel) from odoo14 we are going to use the pandas library. 

Read More: How to use self.env.cr.copy_from function to save data in database

The idea is first we fetch data from database using SQL query, then using pandas we will write the data (coming from the query) into excel file.

Read More: Write binary data into zip file and download it on button click in odoo

How to Read SQL Query using Pandas

df = pd.read_sql(query, self.env.cr.connection, index_col=['Student'])

How to Write and Prepare Data into Excel File using Pandas

io = BytesIO()
writer = pd.ExcelWriter(io)
df.to_excel(writer, "Student Info")
writer.save()
io.seek(0)
read_data = io.read()
io.close()
encoded_data = base64.encodestring(read_data)

Read More: Integration and Syncing of Data from Odoo 8 to Odoo 13

Import/Export Data from Table into Excel File in Odoo14


Post a Comment

0 Comments