In the method loadData of SheetAPI, it allows user add string compare condition to the sheet. .
Here comes the code example
SHEET_API.loadData(SHEET_API_HD, {
fileName: 'Condition Json File',
sheets: [{
name: 'First tab',
color: 'orange',
id: 1
},{
name: 'Second tab',
id: 2
}],
floatings: [{
sheet:1,
name:"condition1",
ftype:"cdt",
json: "{"name":"boolstyle","rng":[{"span":[1,2,2,4,4],"type":1}],"opt":{"type":"include","base":"test","style":{"cbgc":"rgb(248,105,107)","ccolor":"rgb(150,0,0)"}},"id":"condition-2"}"
}],
cells: [
{sheet: 1, row: 2, col: 2, json: {data:100}},
{sheet: 1, row: 2, col: 3, json: {data:"test"}},
{sheet: 1, row: 2, col: 4, json: {data:"me"}},
{sheet: 1, row: 3, col: 2, json: {data:120}},
{sheet: 1, row: 3, col: 3, json: {data:220}},
{sheet: 1, row: 3, col: 4, json: {data:"test123"}},
{sheet: 1, row: 4, col: 2, json: {data:"ok"}},
{sheet: 1, row: 4, col: 3, json: {data:170}},
{sheet: 1, row: 4, col: 4, json: {data:110}}
]
});
The above code will insert a range of cells from B2:D4 by adding value condition include string "test".
For condition, loadData json object includes at least 4 names: fileName, sheets, floatings and cells.
Name | Property | Example | Description |
---|---|---|---|
File name | fileName | fileName: 'Example Sheet' | Define the file name for this sheet file. |
Sheet object | sheets | sheets: [{},{}] | Set defined sheet tabs information for this file. |
Floating object | floatings | floatings: [{},{}] | Set defined floatings information for this file. |
Cell object | cells | cells: [{},{}] | Set defined cell information for each tab. |
You can also call setCondition API and use the following code to update the condition in the existing sheet.
SHEET_API.setCondition(SHEET_API_HD, [[1, 25, 3, 27, 5]], 'boolstyle', {
type:"include",
base:"test",
style:{"cbgc":"rgb(248,105,107)","ccolor":"rgb(150,0,0)"}
});
To add string include condition, the following json object need to be added into floatings.
{
sheet:1, // the sheet id of added condition
name:"condition1", // name should be unique
ftype:"cdt", // define condition type
json: "{\"name\":\"boolstyle\",\"rng\":[{\"span\":[1,2,2,4,4],\"type\":1}],\"opt\":{\"type\":\"include\",\"base\":\"test\",\"style\":{\"cbgc\":\"rgb(248,105,107)\",\"ccolor\":\"rgb(150,0,0)\"}},\"id\":\"12345670\"}"
}
For each json object inside condition floating, it is a string with the following format.
name // boolstyle
rng
span // [sheetId, x1, y1, x2, y2] which define sheetId and a range of cells need to be added condition
type // 1
opt
type // include
base // the value to be compared
style // referred to the decorated color.
cbgc // cell background color if condition meet
ccolor // cell font color if condition meet
id // unique in this sheet file
To add number equal condition, the following json object need to be added into floatings.
{
sheet:1, // the sheet id of added condition
name:"condition2", // name should be unique
ftype:"cdt", // define condition type
json: "{\"name\":\"boolstyle\",\"rng\":[{\"span\":[1,2,2,4,4],\"type\":1}],\"opt\":{\"type\":\"repeat\",\"base\":0,\"style\":{\"cbgc\":\"rgb(248,105,107)\",\"ccolor\":\"rgb(150,0,0)\"}},\"id\":\"1234560\"}"
}
For each json object inside condition floating, it is a string with the following format.
name // boolstyle
rng
span // [sheetId, x1, y1, x2, y2] which define sheetId and a range of cells need to be added condition
type // 1
opt
type // repeat
base // 0
style // referred to the decorated color.
cbgc // cell background color if condition meet (repeat value)
ccolor // cell font color if condition meet (repeat value)