24. With or WithOut Net
Open files offline
To turn on offline access:
● You must be connected to the internet.
● Use the Google Chrome browser.
● Don't use private browsing.
● Install and enable Google Docs offline Chrome extension.
● Make sure you have enough free space on your device.
Open Google Docs, Sheets, and Slides offline
1. Open Chrome. Make sure you're signed in to Chrome.
2. Go to drive.google.com/drive/settings.
3. Check the box next to Sync Google Docs, Sheets ... files
https://support.google.com/drive/answer/2375012?co=GENIE.Platform%3DDesktop&hl=en
37. Apps Script Observe code
Bounds
Script
Special Methods:
● getActiveSpreadsheet()
● getActiveSheet()
● getActiveRange()
● getActiveCell()
● setActiveSheet(sheet)
● setActiveRange(range)
https://developers.google.com/apps-script/guides/bound
Allow bound scripts to refer
to their parent file without
referring to the file's ID
Let the script determine the user's
current Sheet, selected Range of
cells, or selected individual Cell
Let the script change
getActive* selections
38. function formatStyle() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
//var sheet = ss.getSheetByName( 'Sheet1' );
var range1 = sheet.getRange( 'A1:C1' );
var range2 = sheet.getRange(2, 1, 1, 3); //(row, column, numRows, numColumns)
range1.mergeAcross()
.setBackground( 'green' )
.setValue( 'report' )
.setFontSize(12);
range2.setBackground( '#3bf59b' )
.setValues( [['Name', 'LastName', 'Value']] )
.setFontSize(10);
sheet.getRange(1, 1, 2, 3)
.setBorder(true, true, true, true, true, true) /(top, left, bottom, right, vertical, horizontal)
.setHorizontalAlignment( ['left', 'left', 'right'] )
.setVerticalAlignment( 'bottom' )
.setFontWeight( 'bold' );
var columnWidth = [150, 150, 80];
for ( var i = 0; i < columnWidth.length; i++ ) {
sheet.setColumnWidth(i+1,columnWidth[i]);
}
sheet.setFrozenRows(2);
SpreadsheetApp.flush();
}
Observe code
run =
video1
39. function formatStyle() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
//var sheet = ss.getSheetByName( 'Sheet1' );
var range1 = sheet.getRange( 'A1:C1' );
var range2 = sheet.getRange(2, 1, 1, 3); //(row, column, numRows, numColumns)
range1.mergeAcross()
.setBackground( 'green' )
.setValue( 'report' )
.setFontSize(12);
range2.setBackground( '#3bf59b' )
.setValues( [['Name', 'LastName', 'Value']] )
.setFontSize(10);
sheet.getRange(1, 1, 2, 3)
.setBorder(true, true, true, true, true, true) /(top, left, bottom, right, vertical, horizontal)
.setHorizontalAlignment( ['left', 'left', 'right'] )
.setVerticalAlignment( 'bottom' )
.setFontWeight( 'bold' );
var columnWidth = [150, 150, 80];
for ( var i = 0; i < columnWidth.length; i++ ) {
sheet.setColumnWidth(i+1,columnWidth[i]);
}
sheet.setFrozenRows(2);
SpreadsheetApp.flush();
}
Observe code
40. function formatStyle() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
//var sheet = ss.getSheetByName( 'Sheet1' );
var range1 = sheet.getRange( 'A1:C1' );
var range2 = sheet.getRange(2, 1, 1, 3); //(row, column, numRows, numColumns)
range1.mergeAcross()
.setBackground( 'green' )
.setValue( 'report' )
.setFontSize(12);
range2.setBackground( '#3bf59b' )
.setValues( [['Name', 'LastName', 'Value']] )
.setFontSize(10);
sheet.getRange(1, 1, 2, 3)
.setBorder(true, true, true, true, true, true) /(top, left, bottom, right, vertical, horizontal)
.setHorizontalAlignment( ['left', 'left', 'right'] )
.setVerticalAlignment( 'bottom' )
.setFontWeight( 'bold' );
var columnWidth = [150, 150, 80];
for ( var i = 0; i < columnWidth.length; i++ ) {
sheet.setColumnWidth(i+1,columnWidth[i]);
}
sheet.setFrozenRows(2);
SpreadsheetApp.flush();
}
Observe code
count from 0 (0, 1, 2)
count from 0 (0, 1, 2)
41. function onOpen(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
//var sheet = ss.getSheetByName( 'Sheet1' );
var range1 = sheet.getRange( 'A1:C1' );
var range2 = sheet.getRange(2, 1, 1, 3); //(row, column, numRows, numColumns)
range1.mergeAcross()
.setBackground( 'green' )
.setValue( 'report' )
.setFontSize(12);
range2.setBackground( '#3bf59b' )
.setValues( [['Name', 'LastName', 'Value']] )
.setFontSize(10);
sheet.getRange(1, 1, 2, 3)
.setBorder(true, true, true, true, true, true) /(top, left, bottom, right, vertical, horizontal)
.setHorizontalAlignment( ['left', 'left', 'right'] )
.setVerticalAlignment( 'bottom' )
.setFontWeight( 'bold' );
var columnWidth = [150, 150, 80];
for ( var i = 0; i < columnWidth.length; i++ ) {
sheet.setColumnWidth(i+1,columnWidth[i]);
}
sheet.setFrozenRows(2);
SpreadsheetApp.flush();
}
Observe code
Trigger
onOpen()
open file
42. Apps Script Observe code
● Add data
● Create and apply formulas
● Create charts
● Apply SQL queries
● ...
Customize your
work tools :)
43. Observe code/**
* A custom function that calculate tot price.
*
* @param {values} range of two cells
* @return {tot_price} Un_Price * Q_ty
*/
function TOTPRICE(values) {
var tot_pr = 1;
for ( var i = 0; i < values[0].length; i++) {
tot_pr *= values[0][i]; //tot_pr = tot_pr * values[0][i];
}
return tot_pr;
}
Custom function
Create a function with formula
video2
44. Observe code/**
* A custom function that calculate tot price.
*
* @param {values} range of two cells
* @return {tot_price} Un_Price * Q_ty
*/
function TOTPRICE(values) {
var tot_pr = 1;
for ( var i = 0; i < values[0].length; i++) {
tot_pr *= values[0][i]; //tot_pr = tot_pr * values[0][i];
}
return tot_pr;
}
Custom function
Create a function with formula
45. Observe codefunction addChart() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range1 = sheet.getRange("A1:B6")
var chart = sheet.newChart()
.setChartType(Charts.ChartType.LINE)
.addRange(range1)
.setPosition(1, 4, 0, 0) //(anchorRowPos,anchorColPos,offsetX, offsetY)
.build();
sheet.insertChart(chart);
}
Embedded a Chart
video3
46. Observe codefunction addChart() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range1 = sheet.getRange("A1:B6")
var chart = sheet.newChart()
.setChartType(Charts.ChartType.LINE)
.addRange(range1)
.setPosition(1, 4, 0, 0) //(anchorRowPos,anchorColPos,offsetX, offsetY)
.build();
sheet.insertChart(chart);
}
Embedded a Chart
47. Observe code
function addProfit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getActiveSheet();
var range = sh.getRange(2, 3, 20, 2).getValues();
var profits = range.map( function(row) { return [ row[0] - row[1] ]; } );
sh.getRange(2, 5, profits.length, profits[0].length).setValues(profits);
sh.getRange(1, 5).setValue("profits").setFontWeight('bold');
}
.map
Populate a Range of Values
https://www.youtube.com/watch?v=985XJOeigpA
48. Observe code
function PROFIT(sales, cogs) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getActiveSheet();
var profit = sales - cogs;
return profit;
}
method .map
49. Observe codefunction addProfit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getActiveSheet();
var range = sh.getRange(2, 3, 20, 2).getValues();
var profits = range.map( function(row) {
return [ row[0] - row[1] ];
}
);
sh.getRange(2, 5, profits.length, profits[0].length).setValues(profits);
sh.getRange(1, 5).setValue("profits").setFontWeight('bold');
}
.map
video4