Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
When using the XlsxWriter engine, the vertical alignment is ignored, the text is aligned to the bottom. The horizontal alignment as well as the whitespace/wrapping are correctly applied.
Expected output
This doesn't occur, when the OpenPyXL engine is chosen, i.e. when using:
with pd.ExcelWriter('test.xlsx', engine='openpyxl') as writer:
df.to_excel(writer, sheet_name='Test sheet')
The expected output is correctly generated:
Some observations
The problem doesn't occur resp. the expected output can be generated solely using the XlsxWriter engine without using pandas styling:
From pandas/io/formats/excel.py, I assume, that the vertical alignment setting middle is mapped to center, such that 'vertical-align': 'center'. Furthermore, from pandas/io/excel/_xlsxwriter.py, I guess, that the corresponding settings from the OpenPyXL engine are used and (partially) mapped to the correct names used in the XlsxWriter engine, cf. the correct mapping to valign. Now, my assumption is, that the (OpenPyXL's) center setting isn't properly translated to the XlsxWriter's vcenter setting, because, for example, 'vertical-align: top' generates the proper output also for the XlsxWriter engine.
Code sample, a copy-pastable example if possible
Problem description
When using the XlsxWriter engine, the vertical alignment is ignored, the text is aligned to the bottom. The horizontal alignment as well as the whitespace/wrapping are correctly applied.
Expected output
This doesn't occur, when the OpenPyXL engine is chosen, i.e. when using:
The expected output is correctly generated:
Some observations
The problem doesn't occur resp. the expected output can be generated solely using the XlsxWriter engine without using pandas styling:
From pandas/io/formats/excel.py, I assume, that the vertical alignment setting
middle
is mapped tocenter
, such that'vertical-align': 'center'
. Furthermore, from pandas/io/excel/_xlsxwriter.py, I guess, that the corresponding settings from the OpenPyXL engine are used and (partially) mapped to the correct names used in the XlsxWriter engine, cf. the correct mapping tovalign
. Now, my assumption is, that the (OpenPyXL's)center
setting isn't properly translated to the XlsxWriter'svcenter
setting, because, for example,'vertical-align: top'
generates the proper output also for the XlsxWriter engine.Output of
pd.show_versions()