Skip to content

Instantly share code, notes, and snippets.

View linglung's full-sized avatar

linglung

  • C+ Java
View GitHub Profile
@linglung
linglung / GoogleSheetJson.md
Created October 22, 2018 09:42 — forked from ronaldsmartin/GoogleSheetJson.md
Google Spreadsheet JSON Queries

SheetAsJSON + Filtering

This is an extension of DJ Adams' excellent SheetAsJSON Google Apps Script, which provides a way to GET a published Google Spreadsheet as a JSON feed. This version allows generic filtering for terms, more specific control over which rows to parse, and correct MIME type for JSONP output.

Minimal Usage

The following parameters are required for the script to work.

https://script.google.com/macros/s/AKfycbzGvKKUIaqsMuCj7-A2YRhR-f7GZjl4kSxSN1YyLkS01_CfiyE/exec?
+ id=<spreadsheet key>
+ sheet=<sheet name on spreadsheet>
@linglung
linglung / _jsonPuller.md
Created October 17, 2018 19:29 — forked from jalcantarab/_jsonPuller.md
A Google apps script to pull json from a spreadsheet

JSON Puller - Google Apps Script

Transforms the data of a given Spreadsheet Sheet to JSON.

  • The frozen rows are taken as keys for the JSON.
  • The data taken for the values is only that after the frozen rows

Set up:

exportJSON(Spreadsheet) - transforms the data in the given sheet to JSON.

@linglung
linglung / GetDataFromXPath
Created October 17, 2018 10:07 — forked from vs4vijay/GetDataFromXPath
Extract Data from XPath via Google Apps Script
function getDataFromXpath(path, url) {
var data = UrlFetchApp.fetch(url);
var text = data.getContentText();
var xmlDoc = Xml.parse(text, true);
// Replacing tbody tag because app script doesnt understand.
path = path.replace("/html/","").replace("/tbody","","g");
var tags = path.split("/");
Logger.log("tags : " + tags);
// getting the DOM of HTML
@linglung
linglung / getTableByXpath.gs
Created October 17, 2018 10:07 — forked from KenDUemura/getTableByXpath.gs
Google Apps Script for parse table element from HTML string parsed with XmlService and returns 2D array
/*
PARAMS:
text XML (In this gist, namespace needs to be 'http://www.w3.org/1999/xhtml')
path XPATH (So far tested with simple indexed lookup /html/body/table[3])
RETURNS:
Array[][] (Table data)
Missing th/thead/tfoot support
*/
@linglung
linglung / main.js
Created October 16, 2018 19:33 — forked from mhawksey/main.js
Using Google Apps Script to proxy YouTube Analytics Channel report data http://mashe.hawksey.info/?p=16234
// instead of var results = YouTubeAnalytics.Reports.query(ids, start-date, end-date, metrics, optionalArgs);
var params = {"method" : "post",
"payload" : {'ids' : query.ids,
"startDate" : startDate,
"endDate": endDate,
"metrics": query.metrics,
"options": JSON.stringify(options)
}
};
var yt_data = UrlFetchApp.fetch("https://script.google.com/macros/s/YOUR_APP_ID/exec", params);
@linglung
linglung / convertSheet2Json.gs
Created October 13, 2018 19:19 — forked from daichan4649/convertSheet2Json.gs
spreadsheet のデータを JSON として読み込む(Google Apps Script)
function convertSheet2Json(sheet) {
// first line(title)
var firstRange = sheet.getRange(1, 1, 1, sheet.getLastColumn());
var firstRowValues = firstRange.getValues();
var titleColumns = firstRowValues[0];
// after the second line(data)
var lastRow = sheet.getLastRow();
var rowValues = [];
for(var rowIndex=2; rowIndex<=lastRow; rowIndex++) {
@linglung
linglung / README.md
Created June 16, 2018 13:15 — forked from unnikked/README.md
How to host your Telegram bot on Google App Script

Telegram Bot on Google App Script

This is the source code of one of my blog post. To read the full blog post please click here.

@linglung
linglung / submit.md
Created May 1, 2018 09:25 — forked from tanaikech/submit.md
CLEAN method for Google Apps Script

CLEAN method for Google Apps Script

This is a sample script which works the same action with the CLEAN method of VBA. The CLEAN method of VBA removes the characters of 0-31, 127, 129, 141, 143, 144, 157. Although I had looked for such method for Google Apps Script, I couldn't find it. So I created this. If this is useful for you, I'm glad.

function cleanForGAS(str) {
  if (typeof str == "string") {
    var escaped = escape(str.trim());
    for (var i = 0; i <= 31; i++) {
      var s = i.toString(16);
 var re = new RegExp("%" + (s.length == 1 ? "0" + s : s).toUpperCase(), "g");
@linglung
linglung / google-script-add-fonts.gs
Created April 27, 2018 00:17 — forked from ociredefz/google-script-add-fonts.gs
Google apps script to set different fonts in the sheets.
/**
* Google Script - Add Fonts.
* Add other fonts in Google Spreadsheet.
*
* a) Open 'Script editor'
* b) Add this script
* c) Save and run 'onOpen'
* d) Go to some 'Spreadsheet' project
* e) Click to 'Font Editor' and then to 'Change Font'
*/
@linglung
linglung / Code.gs
Created April 26, 2018 06:38 — forked from rheajt/Code.gs
google apps script convert column number to letter
function columnToLetter(column, row) {
var temp, letter = '';
while (column > 0) {
temp = (column - 1) % 26;
letter = String.fromCharCode(temp + 65) + letter;
column = (column - temp - 1) / 26;
}
return letter + row;
}