cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to export the output data in the Excel format into the dbfs location

Heman2
Valued Contributor II

Is there any way to export the โ€‹output data in the Excel format into the dbfs?, I'm only able to do it in the CSV format

1 ACCEPTED SOLUTION

Accepted Solutions

Harish2122
Contributor

@Hemanth A try this code.

import openpyxl

wb = openpyxl.load_workbook('/dbfs/PATH/test.xlsx')

ws = wb.active

for row in ws.iter_rows():

print([col.value for col in row])

ws['A1']='A1'

wb.save('/dbfs/PATH/test.xlsx')

โ€‹

# Load its modified version and print values

wb = openpyxl.load_workbook('/dbfs/PATH/test.xlsx')

ws = wb.active

for row in ws.iter_rows():

print([col.value for col in row])

โ€‹

โ€‹

View solution in original post

4 REPLIES 4

Harish2122
Contributor

@Hemanth A try this code.

import openpyxl

wb = openpyxl.load_workbook('/dbfs/PATH/test.xlsx')

ws = wb.active

for row in ws.iter_rows():

print([col.value for col in row])

ws['A1']='A1'

wb.save('/dbfs/PATH/test.xlsx')

โ€‹

# Load its modified version and print values

wb = openpyxl.load_workbook('/dbfs/PATH/test.xlsx')

ws = wb.active

for row in ws.iter_rows():

print([col.value for col in row])

โ€‹

โ€‹

Hubert-Dudek
Esteemed Contributor III

If you are on Azure just create a logic app (or Power Automate) which will be triggered by Rest API call and will do convertion.

If you want you can also save the dataframe directly to Excel using native spark code. It is really easy:

df1 = df.to_pandas_on_spark()
df1.to_excel("output.xlsx")

Ajay-Pandey
Esteemed Contributor III

Hi @Hemanth Aโ€‹ databricks does not support excel format if you really want to export excel files you have to use python or pandas for the same.

Ajay Kumar Pandey

Sobreiro
New Contributor II

The easiest way I fount is to create a dashboard and export from there. It will enable a context menu with options to export to some file types including csv and excel. 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group