pygsheets icon indicating copy to clipboard operation
pygsheets copied to clipboard

Applying many heterogenous formats to columns is annoying.

Open jyoder6 opened this issue 5 years ago • 2 comments
trafficstars

Is your feature request related to a problem? Please describe. Calculating offsets and looping over the columns is rather tedious.
Formatting the dataframe programmatically is part of my workflow for creating reproducible reports. Since the reports may have varying lengths, having to calculate offsets etc. each time is annoying.

Describe the solution you'd like I've been using my own fork on top of pygsheets to declare column-level formats and apply them at write time.

Like this:

NUMBER_FORMATS = {
    'COUNT': SheetsNumberFormat(FormatType.NUMBER, "#,##0"),
    'DOLLAR': SheetsNumberFormat(FormatType.CURRENCY, "$#,##0"),
  }

pldf = PlacedDataFrame(df,
                       column_formats={'money': NUMBER_FORMATS['DOLLAR'], 'count': NUMBER_FORMATS['COUNT']},
                       index_columns=0)
url = pldf.write_to_new_sheet(folder_hash,
                              sheet_name=sheet_name,
                              worksheet_name=worksheet_name
                              google_client=pygsheets.authorize(service_file=f.name))

I could put it into a PR if you are interested and we could discuss what changes you'd like?

Any other info

jyoder6 avatar Sep 11 '20 18:09 jyoder6

looks interesting. we can add a new arg which specifies the formats for each column.

This could be in future extended to applying more cell properties (like validation, color) since apply_format is generic.

nithinmurali avatar Sep 13 '20 11:09 nithinmurali

Great. I'll extract what I can and submit a PR.

jyoder6 avatar Sep 15 '20 19:09 jyoder6