使用Google Apps脚本向筛选器视图添加条件(高级工作表API) [英] Add Criteria to Filter View using Google Apps Script (Advanced Sheets API)
本文介绍了使用Google Apps脚本向筛选器视图添加条件(高级工作表API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用高级工作表API创建筛选器视图。不过,我在上面找到的所有东西都是用Python或其他语言写的,而且我也没有那么高级,我只能勉强通过谷歌搜索问题!我的其余代码搜索每天添加的新选项卡,这些代码的目的是在该选项卡上自动创建带有一些条件的筛选器视图。
我使用的是";Sheets.Spreadsheets.BatchUpdate()";方法,除了";filterSpes[]";属性之外,此代码中的所有内容都适用于我。我首先尝试了Criteria属性,但后来发现它不再使用了?请帮帮忙! 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'
}}}
}],
}
}}}
推荐答案
修改点:
}filterSpecs: [{
出错。,
需要添加。- 元素不正确。
- 即使不包括
filterViewId
,也会添加筛选器视图。但当使用filterViewId
时,您可以提供原始ID。 requests
的属性是数组。
filterSpecs
的当这些要点反映在您的请求正文中时,它将如下所示。
修改后的脚本:
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);
}
参考:
这篇关于使用Google Apps脚本向筛选器视图添加条件(高级工作表API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文