Showing posts with label script google script. Show all posts
Showing posts with label script google script. Show all posts

Tuesday, March 17, 2020

Making custom function for spreadsheet


  1. Open a new spreadsheet, on the menu tab, choose Tools > Script editor
  2. Now you can write your own function in javascript
  3. This is a simple function that wraps HTML input tags

/**
* Generate a string for input tag.
*
* @param {"text"} type - type can be checkbox, text,....
* @param {"region"} name - name is required for php form.
* @param {"parent_form"} id -  .
* @param {"table01"} clas -  .
* @param {"country-of-birth"} placeholder - .
* @return the tring wraped with input tags.
* @customfunction
*/

function htmlInput(type,name,id,clas,placeholder){
  var outputString = '<input type=';
  var qm = '\"';//qm: quotation mark
  var space = ' ';
  outputString = outputString.concat(qm,type,qm,space);
  if(name){
    outputString = outputString.concat('name=',qm,name,qm,space);
  }
  if (id) {
    outputString = outputString.concat('id=',qm,id,qm,space);
  }
  if (clas) {
    outputString = outputString.concat('class=',qm,clas,qm,space);
  }
  if (placeholder) {
    outputString = outputString.concat('id=',qm,placeholder,qm,space);
  }
  outputString = outputString.concat('>')
  return (outputString);
}



Documentation style using JSDoc
  1. Now, you can use it in your spreadsheet