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.

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. 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!