简体   繁体   中英

How to add cell and font color in app script code from google sheet to web app?

enter image description here Good morning, i need a big help. I am a beginner in programming. I created a script that allows me to create a web app synchronized with the data that I put daily on my google sheet.

I would like that in addition to the data it also takes the color of the font and of the cell.

I think it's easier to understand from the pictures.

My Gs code

function doGet(request) {
  return HtmlService.createTemplateFromFile('Index').evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}


function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}





function getData(){

  const ss=SpreadsheetApp.getActive().getSheetByName("Foglio1").getDataRange().getDisplayValues()
  const data=ss.map(v => {
return{
  "AUDIOLIBRI" : v[0]
}
  })
  data.shift()

  //console.log(data)

  return data
}

i tried reading any post about it on stackoverflow and the official google guide but no concrete result

In order to pass the background-color and font of Spreadsheet to your webapp, you should use a function like following but adapt it to your case.

You didn't put a lot a code, so I don't know how you handle exactly the data. Please consider this as a possibility among others

function getValueAndFormat() {
  var ss = SpreadsheetApp.openById(SPREADSHEET_ID); //to be completed
  var sh = ss.getSheetByName(SHEET_NAME); // to be completed
  var max_row = sh.getLastRow();
  var arr = [];

  for (var x = 1; x <= max_row; x++) { //range start at 1

    var obj = {};
    obj.value = sh.getRange(x, 1).getValue(); // x is row number, 1 is column
    obj.bg_color = sh.getRange(x, 1).getBackground();
    obj.font = sh.getRange(x, 1).getFontFamily();

    arr.push(obj);
  }

  Logger.log(arr); //display the result
  // add your return, and handle the data client-side
}

REFERENCES:

Other Sources:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM