cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
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. 

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.