nithinmurali / pygsheets

Google Sheets Python API v4
https://pygsheets.readthedocs.io/en/latest
Other
1.51k stars 220 forks source link

setFormula for a pygsheet range #499

Closed LuigiBrito closed 3 years ago

LuigiBrito commented 3 years ago

When adding formulas to a range, I have to loop through the range and do a cell.formula = "=FORMULA". In GSheets API, there's already an implemented setformula for a range.

Hoping that setFormula be added to pygsheets

nithinmurali commented 3 years ago

In GSheets API, there's already an implemented setformula for a range.

hmm, can you please provide a link to the docs of the same?

nithinmurali commented 3 years ago

if you want to apply formulae, use the code below

# set a formula and extend it to more cells
cell = wks.cell('C1')
cell.value = '=A1+B1'
wks.apply_format('C1:C10', cell, 'userEnteredValue.formulaValue')
rrfaria commented 2 years ago

I did same thing and got an error:

When I use your example:

cell = wks.cell('F2')
cell.value = '=B2+1'
wks.apply_format('F3:F300', cell, 'userEnteredValue.formulaValue')
AttributeError: 'Worksheet' object has no attribute 'apply_format'

I also tried different

cell = wks.cell('F2')
cell.formula = '=B2+1'
wks.get_values("F3","F300",returnas="range").apply_format(cell)

but got another error:

AttributeError: 'str' object has no attribute 'get_json'