用公式字符写入gsheets的pygsheets数据将数据作为公式

时间:2019-04-05 08:18:38

标签: python-3.x google-sheets google-sheets-api pygsheets

使用pygsheets将数据写入gsheets时-我的值之一包含+字符。例如+myvalue

然后导出数据时,我得到的是#NAME?的输出,而不是背景值。#NAME?,当然,编辑栏包含正确的值。+myvalue

这并不是完全出乎意料的-但是,当使用工作表方法并手动导入包含这些值的CSV时,不会显示#NAME?错误,而是可以在字段中看到+ myvalue。 (除非我对其进行编辑。)

这是我用于“导入” csv的代码-当然,它只是读取csv并加载值:

# Authorise with GSheets Service Account
gc = pygsheets.authorize(service_file=service_account_file)

# Open spreadsheet
sh = gc.open_by_key(spreadsheet_key)

# Open Worksheet
#wks = sh.add_worksheet(spreadsheet_hosts_worksheet) # Create Worksheet
wks = sh.worksheet_by_title(worksheet_name)

# Generate list "data" with Values from CSV
with open(inputFile, 'r') as f:
  #reader = csv.reader(f, skipinitialspace=True, delimiter=',', quotechar='"')
  reader = csv.reader(f, delimiter=',', quotechar='"')
  data = list(reader)

# Empty Worksheet
wks.clear()

# Append Values
wks.update_values(crange='A1', values=data)

# Freeze Top Row
wks.frozen_rows=1

我可以更改更新方法,以便采用诸如文本之类的公式-像CSV import上的GSheets函数一样吗?

我的样本数据:

['host_name', 'alias', 'address', 'parents', 'use', 'display_name', 'hostgroups', 'contacts', '_ADDINFO', '_SNOWGROUP', '_RTTCRIT', '_RTTWARN', 'contact_groups', 'notes', 'notes_url', 'check_command', 'first_notification_delay', 'check_interval', 'max_check_attempts', 'retry_interval', 'config_filename']
['host', 'destiny islands', '1.1.1.1', 'host.mypalace.com,host.mapalace2.com', 'tmpl_network_device', 'Gingerbread lane', 'hgrp_grandad', '+myvalue', 'ACTION - Don't forget to smile', 'test', '70', '20', '', '', '', '', '', '', '', '', '/folder/filename']

1 个答案:

答案 0 :(得分:1)

如何使用const randomInteger = (min, max) => { const range = max - min; const maxGeneratedValue = 0xFFFFFFFF; const possibleResultValues = range + 1; const possibleGeneratedValues = maxGeneratedValue + 1; const remainder = possibleGeneratedValues % possibleResultValues; const maxUnbiased = maxGeneratedValue - remainder; if (!Number.isInteger(min) || !Number.isInteger(max) || max > Number.MAX_SAFE_INTEGER || min < Number.MIN_SAFE_INTEGER) { throw new Error('Arguments must be safe integers.'); } else if (range > maxGeneratedValue) { throw new Error(`Range of ${range} (from ${min} to ${max}) > ${maxGeneratedValue}.`); } else if (max < min) { throw new Error(`max (${max}) must be >= min (${min}).`); } else if (min === max) { return min; } let generated; do { generated = crypto.getRandomValues(new Uint32Array(1))[0]; } while (generated > maxUnbiased); return min + (generated % possibleResultValues); }; console.log(randomInteger(-8, 8)); // -2 console.log(randomInteger(0, 0)); // 0 console.log(randomInteger(0, 0xFFFFFFFF)); // 944450079 console.log(randomInteger(-1, 0xFFFFFFFF)); // Error: Range of 4294967296 covering -1 to 4294967295 is > 4294967295. console.log(new Array(12).fill().map(n => randomInteger(8, 12))); // [11, 8, 8, 11, 10, 8, 8, 12, 12, 12, 9, 9]

当我看到the script时,默认值为parse=False。在这种情况下,parse=True使用valueInputOption。使用USER_ENTERED时,parse=False使用valueInputOption。这样,RAW就不会+myvalue

修改后的脚本:

#NAME?

参考文献: