Here is a code snippet:
import ast
from oauth2client import file, client, tools
from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
from apiclient.discovery import build
from apiclient import discovery
SCOPE = 'https://www.googleapis.com/auth/spreadsheets'
CREDJSON = "some-cred-file-downloaded-from-dev-console.json"
def google_credentials(jsoncred=CREDJSON, scope=SCOPE):
return ServiceAccountCredentials.from_json_keyfile_name(jsoncred, scope)
def csv_arrays(creds, key):
(SHEETS, sheets) = sheets_fetch(creds, key)
wks = sheets
def create_filename(arg):
filename = key.prefix + "_" + arg.get("properties, {}).get("title","Sheet1")
filename = filename.replace(" ", "_")
print (filename)
return filename
return [(create_filename(ws), ast.literal_eval(repr(SHEETS.spreadsheets().values().get(spreadsheetId=key.key, range=(ws.get("properties", {}).get("title", "Sheet1"))).execute().get('values',[])))) for ws in wks] #.decode("utf-8")
def sheets_fetch(creds, key):
print('Now doing:', key)
SHEETS = build('sheets', 'v4', http=creds.authorize(Http()))
sheet_metadata = SHEETS.spreadsheets().get(spreadsheetId=key.key).execute()
sheets = sheet_metadata.get('sheets', '')
return (SHEETS, sheets)
I have no problems getting the content of the cells. My problem is that they come formatted (as this is the default value) and I want them UNFORMATTED?
How do I set the option in the query of the return statement from the csv_array function?
https://developers.google.com/sheets/reference/rest/v4/ValueRenderOption
As a side note, is there a way to get the cells value in other way than as a string ast-ed to a list?