Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: speed up to_excel #42652

Closed
PeterTrefonasIv opened this issue Jul 21, 2021 · 1 comment
Closed

ENH: speed up to_excel #42652

PeterTrefonasIv opened this issue Jul 21, 2021 · 1 comment
Labels
Closing Candidate May be closeable, needs more eyeballs Duplicate Report Duplicate issue or pull request Enhancement IO Excel read_excel, to_excel

Comments

@PeterTrefonasIv
Copy link

PeterTrefonasIv commented Jul 21, 2021

Is your feature request related to a problem?

to_excel could be faster

Describe the solution you'd like

openpyxl's write only workbook is very fast and should be used
https://openpyxl.readthedocs.io/en/stable/optimized.html

# Your code here, if applicable
def to_excel_fast(df,name):
	wb = openpyxl.Workbook(write_only = True)
	ws=wb.create_sheet()
	ws.title = "df"

	#Set up header row
	col_row = []
	BOLD_FONT = openpyxl.styles.Font(bold=True)
	BOTTOM_LEFT_RIGHT_BORDER = openpyxl.styles.Border(bottom=openpyxl.styles.Side(style='thin'),left=openpyxl.styles.Side(style='thin'),right=openpyxl.styles.Side(style='thin'))
	CENTER_ALIGNMENT_NO_WRAP = openpyxl.styles.Alignment(horizontal='center')
	for column in df.columns:
		newCell = openpyxl.cell.WriteOnlyCell(ws,value=column)
		newCell.font = BOLD_FONT
		newCell.border = BOTTOM_LEFT_RIGHT_BORDER
		newCell.alignment = CENTER_ALIGNMENT_NO_WRAP
		col_row.append(newCell)
	ws.append(col_row)

	#Add data
	for i in range(len(df)):
		ws.append(tuple(df.iloc[i]))
	wb.save(name)
@PeterTrefonasIv PeterTrefonasIv added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 21, 2021
@phofl
Copy link
Member

phofl commented Jul 21, 2021

Duplicate of #41681

@phofl phofl marked this as a duplicate of #41681 Jul 21, 2021
@phofl phofl added Closing Candidate May be closeable, needs more eyeballs Duplicate Report Duplicate issue or pull request IO Excel read_excel, to_excel and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs Duplicate Report Duplicate issue or pull request Enhancement IO Excel read_excel, to_excel
Projects
None yet
Development

No branches or pull requests

3 participants