多重筛选条件 -Excel Table
Multiple Filter Criteria -Excel Table
我正在尝试使用从 PowerAutomate 传递的多个条件来过滤以下 table。我想为 "Product-1"、"Product-3"、"Product-5"、 过滤产品列 "East"、"West" “ 和 “黑色”、“白色”的颜色列。
我将三个变量从 Power-Automate 传递到办公脚本,如 product_Name 、 product_Location 和product_Color。
其中
product_Name = "Product-1", "Product-3", "Product-5"
product_Location = "东", "西"
product_Color="黑色", "白色"
我正在使用以下 office 脚本来应用过滤器,但是不能应用过滤器,因为它只过滤列为“Product-1”、“Product-3”、“Product-5” " 不是特定行。
function main(workbook: ExcelScript.Workbook,
product_Name?: string,
product_Location?: string,
product_Color?: string,
) {
let table2 = workbook.getTable("Table2");
// Apply checked items filter on table table2 column Product
table2.getColumnByName("Product").getFilter().applyValuesFilter([product_Name]);
// Apply checked items filter on table table2 column Location
table2.getColumnByName("Location").getFilter().applyValuesFilter([product_Location]);
// Apply checked items filter on table table2 column Color
table2.getColumnByName("Color").getFilter().applyValuesFilter([product_Color]);
}
Table:
Product
Location
Colour
Product-1
East
Black
Product-2
West
Red
Product-3
South
Blue
Product-4
West
Blue
Product-5
East
Yellow
Product-1
West
White
Product-2
East
Black
Product-3
West
Red
Product-4
South
Blue
Product-5
West
Blue
Product-1
East
Yellow
Product-2
West
White
Product-3
South
Black
Product-4
West
Red
Product-5
South
Blue
Product-1
West
Blue
Product-2
East
Yellow
Product-3
West
White
如何将变量用作适当的过滤器?有人可以帮忙吗?
假设您的数据在 A-C 列中并且您的 sheet 名称是 Sheet1,
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheet("Sheet1");
let table = sheet.getTable("Table2");
table.getAutoFilter().apply("A1", 0, { filterOn: ExcelScript.FilterOn.values, values: ["Product-1", "Product-3", "Product-5"] });
table.getAutoFilter().apply("B1", 1, { filterOn: ExcelScript.FilterOn.values, values: ["East", "West"] });
table.getAutoFilter().apply("C1", 2, { filterOn: ExcelScript.FilterOn.values, values: ["Black", "White"] });
}
applyValuesFilter
将字符串数组作为参数。最简单的方法是将参数更改为字符串数组 -
function main(workbook: ExcelScript.Workbook,
product_Names?: string[],
product_Locations?: string[],
product_Colors?: string[],
) {
let table2 = workbook.getTable("Table2");
// Apply checked items filter on table table2 column Product
table2.getColumnByName("Product").getFilter().applyValuesFilter(product_Names);
// Apply checked items filter on table table2 column Location
table2.getColumnByName("Location").getFilter().applyValuesFilter(product_Locations);
// Apply checked items filter on table table2 column Color
table2.getColumnByName("Color").getFilter().applyValuesFilter(product_Colors);
}
Power Automate 的值也必须更改为数组
product_Name = ["Product-1", "Product-3", "Product-5"]
product_Location = ["东", "西"]
product_Color= ["黑色", "白色"]
我正在尝试使用从 PowerAutomate 传递的多个条件来过滤以下 table。我想为 "Product-1"、"Product-3"、"Product-5"、 过滤产品列 "East"、"West" “ 和 “黑色”、“白色”的颜色列。
我将三个变量从 Power-Automate 传递到办公脚本,如 product_Name 、 product_Location 和product_Color。 其中
product_Name = "Product-1", "Product-3", "Product-5"
product_Location = "东", "西"
product_Color="黑色", "白色"
我正在使用以下 office 脚本来应用过滤器,但是不能应用过滤器,因为它只过滤列为“Product-1”、“Product-3”、“Product-5” " 不是特定行。
function main(workbook: ExcelScript.Workbook,
product_Name?: string,
product_Location?: string,
product_Color?: string,
) {
let table2 = workbook.getTable("Table2");
// Apply checked items filter on table table2 column Product
table2.getColumnByName("Product").getFilter().applyValuesFilter([product_Name]);
// Apply checked items filter on table table2 column Location
table2.getColumnByName("Location").getFilter().applyValuesFilter([product_Location]);
// Apply checked items filter on table table2 column Color
table2.getColumnByName("Color").getFilter().applyValuesFilter([product_Color]);
}
Table:
Product | Location | Colour |
---|---|---|
Product-1 | East | Black |
Product-2 | West | Red |
Product-3 | South | Blue |
Product-4 | West | Blue |
Product-5 | East | Yellow |
Product-1 | West | White |
Product-2 | East | Black |
Product-3 | West | Red |
Product-4 | South | Blue |
Product-5 | West | Blue |
Product-1 | East | Yellow |
Product-2 | West | White |
Product-3 | South | Black |
Product-4 | West | Red |
Product-5 | South | Blue |
Product-1 | West | Blue |
Product-2 | East | Yellow |
Product-3 | West | White |
如何将变量用作适当的过滤器?有人可以帮忙吗?
假设您的数据在 A-C 列中并且您的 sheet 名称是 Sheet1,
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheet("Sheet1");
let table = sheet.getTable("Table2");
table.getAutoFilter().apply("A1", 0, { filterOn: ExcelScript.FilterOn.values, values: ["Product-1", "Product-3", "Product-5"] });
table.getAutoFilter().apply("B1", 1, { filterOn: ExcelScript.FilterOn.values, values: ["East", "West"] });
table.getAutoFilter().apply("C1", 2, { filterOn: ExcelScript.FilterOn.values, values: ["Black", "White"] });
}
applyValuesFilter
将字符串数组作为参数。最简单的方法是将参数更改为字符串数组 -
function main(workbook: ExcelScript.Workbook,
product_Names?: string[],
product_Locations?: string[],
product_Colors?: string[],
) {
let table2 = workbook.getTable("Table2");
// Apply checked items filter on table table2 column Product
table2.getColumnByName("Product").getFilter().applyValuesFilter(product_Names);
// Apply checked items filter on table table2 column Location
table2.getColumnByName("Location").getFilter().applyValuesFilter(product_Locations);
// Apply checked items filter on table table2 column Color
table2.getColumnByName("Color").getFilter().applyValuesFilter(product_Colors);
}
Power Automate 的值也必须更改为数组
product_Name = ["Product-1", "Product-3", "Product-5"]
product_Location = ["东", "西"]
product_Color= ["黑色", "白色"]