Sample Code

Number compare condition



In the method loadData of SheetAPI, it allows user add number 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":"greater","base":"150","style":{"cbgc":"rgb(248,105,107)","ccolor":"rgb(150,0,0)"}},"id":"condition-1"}"}
    ],
    cells: [
         {sheet: 1, row: 2, col: 2, json: {data:100}},
         {sheet: 1, row: 2, col: 3, json: {data:200}},
         {sheet: 1, row: 2, col: 4, json: {data:300}},
         {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:150}},
         {sheet: 1, row: 4, col: 2, json: {data:130}},
         {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 greater than 150.

For condition, loadData json object includes at least 4 names: fileName, sheets, floatings and cells. Detail definition of conditions are put in floatings item.

NameProperty ExampleDescription
File namefileName fileName: 'Example Sheet' Define the file name for this sheet file.
Sheet objectsheets sheets: [{},{}] Set defined sheet tabs information for this file.
Floating objectfloatings floatings: [{},{}] Set defined floatings information for this file.
Cell objectcells 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:"greater",
     base:"150",
     style:{"cbgc":"rgb(248,105,107)","ccolor":"rgb(150,0,0)"} 
});
 

Greater than condition

To add number greater than 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\":\"greater\",\"base\":\"150\",\"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     // greater
      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
  

Equal condition

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\":\"equal\",\"base\":\"150\",\"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      // equal
      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
  

Less than condition

To add number less than 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\":\"less\",\"base\":\"150\",\"style\":{\"cbgc\":\"rgb(248,105,107)\",\"ccolor\":\"rgb(150,0,0)\"}},\"id\":\"123456700\"}"
  } 

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      // less
      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
  

Between condition

To add number between condition, the following json object need to be added into floatings.

{
     sheet:1,             // the sheet id of added condition
     name:"condition4",   // name should be unique
     ftype:"cdt",         // define condition type
     json: "{\"name\":\"boolstyle\",\"rng\":[{\"span\":[1,2,2,4,4],\"type\":1}],\"opt\":{\"type\":\"between\",\"base\":{\"min\":\"220\",\"max\":\"250\"},\"style\":{\"cbgc\":\"rgb(248,105,107)\",\"ccolor\":\"rgb(150,0,0)\"}},\"id\":\"12345600\"}"
  } 

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      // between
      base      
            min      // between start number 
            max      // between end number 
      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
  

 

 


Copyright © FeyaSoft Inc. All rights reserved.