-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.gs
More file actions
116 lines (107 loc) · 3.7 KB
/
lib.gs
File metadata and controls
116 lines (107 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//## Execute API #######################################################################################################################
/**
* Used to call api and return response XML
* @param url API URL
* @param username Username
* @param password Password
* @customFunction
*/
function Invoke(url,username,password) {
var headers = {
'Authorization': 'Basic ' + Utilities.base64Encode(username + ':' + password),
'Content-Type': 'application/xml',
'Accept': 'application/xml',
'validateHttpsCertificates': false,
'muteHttpExceptions': true,
}
var opt = {
'headers': headers,
};
var response;
response = UrlFetchApp.fetch(url, opt).getContentText();
return response;
}
//## Get Active Sheet ##################################################################################################################
/**
* Get active sheet OR Get sheet by name
* @param sheetname Name of the sheet.
*/
function GetActiveSheet(sheetname) {
var spreadsheet;
if (sheetname == '') {
spreadsheet = SpreadsheetApp.getActive().getActiveSheet();
} else {
spreadsheet = SpreadsheetApp.getActive().getSheetByName(sheetname);
}
return spreadsheet;
}
//## Insert Sheet ######################################################################################################################
/**
* Create new sheet under spreadsheet
* @param sheetname Name of the sheet.
*/
function InsertSheet(sheetname) {
var spreadsheet;
spreadsheet= SpreadsheetApp.getActiveSpreadsheet().insertSheet(sheetname);
return spreadsheet;
}
//## Get items #########################################################################################################################
/**
* Get array of child items for provided parent key
* @param apiresponse XML response from called API
* @param key Parent key for which child items list required from response.
*/
function GetItems(apiresponse,key)
{
var items;
var parsedresponse = XmlService.parse(apiresponse);
items = parsedresponse.getRootElement().getChildren(key);
return items;
}
//## Clear Sheet #######################################################################################################################
/**
* Will clear sheet.
* @param sheet Sheet that needs to be cleared
*/
function ClearSheet(sheet)
{
sheet.clear({
formatOnly: true,
contentsOnly: true
});
sheet.clearNotes();
}
//## Set Cell Value ####################################################################################################################
/**
* To set value of a cell
* @param sheet Sheet contain cell on which value should set.
* @param row Row on which value should set
* @param column Column on which value should set
* @param value Value which should set in cell
*/
function SetCellValue(sheet,row,column,value)
{
sheet.getRange(row, column).setValue(value);
}
//## Get Cell Value ####################################################################################################################
/**
* To get value of a cell
* @param sheet Sheet contain cell of which value should get.
* @param row Row on which value should get
* @param column Column on which value should get
*/
function GetCellValue(sheet,row,column)
{
return sheet.getRange(row, column).getValue();
}
//## Get Child Item Value ##############################################################################################################
/**
* To get item from array
* @param array Collection of items as an array.
* @param index Index number for which item value to get
* @param key Child item key
*/
function GetChildItemValue(array,index,key)
{
return array[index].getChild(key).getText();
}