我正在嘗試使用高級作業表 API 創建過濾器視圖。我能在上面找到的所有東西都是用 Python 或其他語言撰寫的,而且我不是那么先進,我幾乎無法通過谷歌搜索問題完成它!我的其余代碼搜索每天添加的新選項卡,此代碼的目的是在具有某些條件的選項卡上自動創建過濾器視圖。
我正在使用“Sheets.Spreadsheets.batchUpdate()”方法,除了“filterSpecs[]”屬性之外,這段代碼中的所有內容都對我有用。我先嘗試了條件屬性,但后來發現它不再使用了?請幫忙!
const resource = {
requests: {
addFilterView: {
filter: {
filterViewId: '0000000',
title: 'Chris Johnson',
range: {
sheetId: st1.toString(),
startRowIndex: 0,
endRowIndex: 500,
startColumnIndex: 0,
endColumnIndex: 8
}
filterSpecs: [{
3: {condition: {
type: 'TEXT_CONTAINS',
values: {
userEnteredValue: 'Chris Johnson'
}}}
}],
}
}}}
uj5u.com熱心網友回復:
修改點:
}filterSpecs: [{有錯誤。,需要添加。- 的元素
filterSpecs不正確。 - 即使
filterViewId不包括在內,也會添加過濾器視圖。但是在filterViewId使用的時候,可以給原ID。 - 的屬性
requests是一個陣列。
當這些點反映在您的請求正文中時,它變成如下。
修改后的腳本:
function myFunction() {
const spreadsheetId = "###"; // Please set your Spreadsheet ID.
const resource = {
"requests": [
{
"addFilterView": {
"filter": {
"filterViewId": 12345,
"title": "Chris Johnson",
"range": {
"sheetId": 0,
"startRowIndex": 0,
"endRowIndex": 500,
"startColumnIndex": 0,
"endColumnIndex": 8
},
"filterSpecs": [
{
"filterCriteria": {
"condition": {
"type": "TEXT_CONTAINS",
"values": [
{
"userEnteredValue": "Chris Johnson"
}
]
}
},
// "columnIndex": 0 // If you want to use the column, please use this.
}
]
}
}
}
]
};
Sheets.Spreadsheets.batchUpdate(resource, spreadsheetId);
}
參考:
- AddFilterViewRequest
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/416494.html
標籤:
下一篇:JSON物件陣列回傳未定義
