As the documentation says, when you want to save more than one sheet in the same file you need to declare the Excelwriter object
with pd.ExcelWriter('teste.xlsx') as writer:
df1.to_excel(writer, sheet_name='df1')
df2.to_excel(writer, sheet_name='df2')
In your case
with pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter') as writer:
dCliente.to_excel(writer,sheet_name='DIM_CLIENTES', index=False)
dProjeto.to_excel(writer,sheet_name='DIM_PROJETOS', index=False)
dTask.to_excel(writer,sheet_name='DIM_TAREFAS', index=False)
fFATO.to_excel(writer,sheet_name='FATO', index=False)
dUsers.to_excel(writer,sheet_name='DIM_USUARIOS', index=False)
You can set another engine this way
with pd.ExcelWriter('pandas_simple.xlsx', engine='openpyxl') as writer:
dCliente.to_excel(writer,sheet_name='DIM_CLIENTES', index=False)
dProjeto.to_excel(writer,sheet_name='DIM_PROJETOS', index=False)
dTask.to_excel(writer,sheet_name='DIM_TAREFAS', index=False)
fFATO.to_excel(writer,sheet_name='FATO', index=False)
dUsers.to_excel(writer,sheet_name='DIM_USUARIOS', index=False)
In your code you assign to the Writer object, thus: writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter') as writer:
Using with, you ensure that the object is opened and closed correctly being unnecessary xlswriter.close()
, since it doesn’t even contain the close method. The right name is xlsxwriter, and only by accessing the Workbook can you use . close or . save.
Example taken from the documentation:
import xlsxwriter
workbook = xlsxwriter.Workbook('filename.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write(0, 0, 'Hello Excel')
workbook.close()
because it does not use
df.to_excel
?– Lucas
has the possibility to save in several tabs ??
– Paulo Henrique
yes, see documentation: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_excel.html
– Lucas