0

I used gspread to get some data from a Google docs spreadsheet.

Here is a snippet of the code:

worksheet_2 = sp1.get_worksheet(1)
worksheet_1 = sp1.get_worksheet(0)

val = worksheet_2.acell('F2')

print val

when I print val the output is: <Cell R2C6 '76'>.

I am just after the val its self which in this case is 76.

Q: How can manipulate the string with python to just get 76 (or the number inside the single quotes) from <Cell R2C6 '76'> or with gspread?

I will then use this value with a letter and concatenate them to be used for updating a cell.

Ideally: The number will be concatenated with a letter to be used in the following line in to append new information, something like this:

val = worksheet_2.acell('F2')

letter = A

cell_location = letter+val

print cell_location

worksheet_1.update_acell('cell_location',"Sheet 111")
3kstc
  • 1,871
  • 3
  • 29
  • 53
  • you can use regex library `re` with a pattern like `"'[^']+'"` to match anything inside of the quotes or `"'\d+'"` to match only numbers – R Nar Nov 01 '15 at 23:37

1 Answers1

1

There is a specific command to just get the value:

val = worksheet_2.acell('H2').value

The overall code would something like this:

worksheet_1 = sp1.get_worksheet(0)
worksheet_2 = sp1.get_worksheet(1)

val = worksheet_2.acell('H2').value

column = "B"
cell_coordinate = column+val
print cell_coordinate

worksheet_1.update_acell(cell_coordinate,"Sheet 111")

The first two lines are for the individual worksheets of the spreadsheet. val = worksheet_2.acell('H2').value gets only the value from cell H2 and assigns that value to the variable val. The variable column is assigned B and val and column variables are concatenated together before being printed as cell_coordinate. This coordinates are used to print "sheet 111" in the new cell_coordinate

3kstc
  • 1,871
  • 3
  • 29
  • 53