pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.7k stars 17.92k forks source link

ENH: add ExcelWriter set_column functionality for ODF Open Document Format #45140

Closed karolszk closed 2 years ago

karolszk commented 2 years ago

Hello,

Please, add possibility to setting column width: set_column support in ExcelWriter class for ODF open standard documents. Currently pandas doesn't support it. Pandas supports (and working fine) set_column for XLSX Excel files. Similar functionality will be useful for all which strongly supports open standards.

Below example explains the issue: set_column_for_odf_is_lacking2

Thank you.

phofl commented 2 years ago

Hi, thanks for your request. Please always provide copy and pasteable examples.

phofl commented 2 years ago

Just a note: All attributes of ExcelWriter are considered private

karolszk commented 2 years ago

Right @phofl . Below the copy&pastable example:

import pandas as pd df=pd.DataFrame({"a":[1,2,3],"b":[1,2,3]}) writer=pd.ExcelWriter("test.ods") # .xlsx works fine df.to_excel(writer, sheet_name='my_analysis') writer.sheets['my_analysis'].set_column(0,0,40)

phofl commented 2 years ago

So first: The ExcelWriter attributes are private (sheets here), so we can not make any guarantees. Second: writer.sheets[elem] is an odf.elem.Element in case of ods files, this is nothing we have control over. You should contact this project with your request. In case of xlsx files, we get a xlsxwriter.worksheet.Worksheet object, which seems to support this.