How to design cell, cells (Font Family, Background, Color, Size,...)
Method
- setBackgroundRGB
- setBackground
- setBorder
- setDataValidation
- setDataValidations
- setFontColor
- setFontColors
- setFontFamilies
- setFontFamily
- setFontLine
- setFontLines
- setFontSize
setBackgroundRGB(red, green, blue)
function BackgroundColor2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B3");
cell.setBackgroundRGB(200, 115, 120);
}
setBackground(color)
function BackgroundColor1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B2");
cell.setBackground("blue");
}
setBorder(top, left, bottom, right, vertical, horizontal)
function Border1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("C3");
cell.setBorder(true, null, true, null, false, false);
}
function Border2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("D7:E8");
cell.setBorder(null, null, null, null, true, true);
}
setDataValidation(rule)
in work
setDataValidations(rules)
in work
setFontColor(color)
For one cell, more cells (range) - setFontColors
function FontColorMy2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A16");
cell.setFontColor("yellow");
}
setFontColors(colors)
For more cells (range), for one cell - setFontColor
function FontColorMy2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// set for Colors
var colors = [
["red", "black", "blue"],
["#FF0000", "#000000", "#0000FF"] ];
var cell = sheet.getRange("B7:D8");
cell.setFontColors(colors);
}
setFontFamilies(fontFamilies)
in work
setFontFamily(fontFamily)
function myFontFamily() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B2");
cell.setFontFamily("Helvetica");
}
- Arial
- Helvetica
- Times New Roman
- Georgia
- Verdana
- ....
setFontLine(fontLine)
For one cell (range), for more cells - setFontLines
- underline
- line-through
- none
function myFontLine1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B2");
cell.setFontLine("line-through"); // Note in Czech: přeškrtnuté
}
setFontLines(fontLines)
For more cells (range), for one cell - setFontLine
- underline
- line-through
- none
function myFontLine2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A2:B3");
var linesMy = [
["underline", "none"],
["underline", "line-through"] //
];
cell.setFontLines(linesMy);
}
setFontSize(size)
function FontSizeMy1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B2");
cell.setFontSize(20);
}