Skip to content

add some better api to specify number_format when dumping data to Excel #1162

@gdementen

Description

@gdementen

The current way to do it:

with open_excel(fpath) as wb:
    sheet = wb[0]
    sheet['A1'] = arr.dump()
    # we must use Excel "custom format" syntax
    sheet['B2'].xw_range.expand().number_format = '0,00'
    # OR
    sheet.range('B2').expand().number_format = '0,00'
    # OR
    sheet['B2:D3'].number_format = '0,00'

    # for percents:
    sheet['B2:D3'].number_format = '0,0%'

But it is annoying to have to specify the range of the data, or even the "starting point" of the data.

with open_excel(fpath) as wb:
    sheet = wb[0]
    sheet['A1'] = arr.dump(data_format='0,00')

Solving this issue would probably add the infrastructure necessary to solve #646 easily.

We might want to tackle this at the same time than the various Excel API refactors (#826, #900, #926, #967, #1005).

We might want to be even more ambitious and implement something like Pandas Styler but that would take a long time until we have time to design such a large system (unless we just reuse the Pandas design -- but I am unsure it applies)
https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html#Table-Visualization

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions