Skip to content

Commit

Permalink
Update ggsheet.py
Browse files Browse the repository at this point in the history
Remove gen_script() because you no longer need it.
  • Loading branch information
PerfecXX authored Sep 15, 2024
1 parent 69a16f3 commit 4bffe2b
Showing 1 changed file with 1 addition and 172 deletions.
173 changes: 1 addition & 172 deletions ggsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ujson
import os

__version__ = '0.0.3'
__version__ = '0.0.4'
__author__ = 'Teeraphat Kullanankanjana'

class MicroGoogleSheet():
Expand Down Expand Up @@ -165,174 +165,3 @@ def deleteColumn(self,column=1):
response = requests.get(url)
response.close()
return response.status_code

def gen_scriptFile(self):
code = """
/*
Author: Teeraphat Kullanankanjana
Version: 0.0.3
*/
function doGet(e) {
// Extract parameters from the request
var sheet_id = e.parameter.sheet_id;
var sheet_name = e.parameter.sheet_name;
var mode = e.parameter.mode;
// Open the spreadsheet and get the sheet
var ss = SpreadsheetApp.openById(sheet_id);
var sheet = ss.getSheetByName(sheet_name);
// Update a single cell
if (mode == "updateCell") {
var row = e.parameter.row;
var column = e.parameter.column;
var data = e.parameter.data;
var cell = sheet.getRange(row, column);
cell.setValue(data);
}
// Update a row with multiple values
else if (mode == "updateRow") {
var row = e.parameter.row;
var data = [];
var count = 0;
while (e.parameter["data" + count]) {
count++;
}
for (var i = 0; i < count; i++) {
var key = "data" + i;
var value = e.parameter[key];
data.push(value);
}
var range = sheet.getRange(row, 1, 1, data.length);
range.setValues([data]);
}
// Append a row with multiple values
else if (mode == "appendRow") {
var data = [];
var count = 0;
while (e.parameter["data" + count]) {
count++;
}
for (var i = 0; i < count; i++) {
var key = "data" + i;
var value = e.parameter[key];
data.push(value);
}
var lastRow = sheet.getLastRow();
var row = e.parameter.row || lastRow + 1; // If row parameter is not provided, append to last row + 1
if (row > 0) {
sheet.insertRowBefore(row);
lastRow = row - 1;
}
sheet.getRange(lastRow + 1, 1, 1, data.length).setValues([data]);
}
// Append a column with multiple values
else if (mode == "appendColumn") {
var data = [];
var count = 0;
while (e.parameter["data" + count]) {
count++;
}
for (var i = 0; i < count; i++) {
var key = "data" + i;
var value = e.parameter[key];
data.push([value]); // wrap the value in an array to create a column
}
var lastColumn = sheet.getLastColumn();
var column = e.parameter.column || lastColumn + 1; // If column parameter is not provided, append to last colum + 1
if (column > 0) {
sheet.insertColumnBefore(column);
lastColumn = column - 1;
}
sheet.getRange(1, lastColumn + 1, data.length, 1).setValues(data);
}
// Update a column with multiple values
else if (mode == "updateColumn") {
var column = e.parameter.column;
var data = [];
var count = 0;
while (e.parameter["data" + count]) {
count++;
}
for (var i = 0; i < count; i++) {
var key = "data" + i;
var value = e.parameter[key];
data.push([value]); // wrap the value in an array to create a column
}
var range = sheet.getRange(1, column, data.length, 1);
range.setValues(data);
}
// Get the value of a specific cell
else if (mode == "getCell") {
var row = e.parameter.row;
var column = e.parameter.column;
var cell = sheet.getRange(row, column);
var value = cell.getValue();
var html = "<html><head><title>Get The data </title></head><body><h1>start</h1><h1>" + value + "</h1><h1>finish</h1></body></html>";
return HtmlService.createHtmlOutput(html);
}
// Get the values of a specific row
else if (mode == "getRow") {
var row = e.parameter.row;
var range = sheet.getRange(row, 1, 1, sheet.getLastColumn());
var values = range.getValues()[0];
var heading = "";
for (var i = 0; i < values.length; i++) {
heading += values[i] + " ";
}
var html = "<html><head><title>Get Row Data</title></head><body><h1>start</h1><h1>" + heading + "</h1><h1>finish</h1></body></html>";
return HtmlService.createHtmlOutput(html);
}
// Get the values of a specific column
else if (mode == "getColumn") {
var column = e.parameter.column;
var range = sheet.getRange(1, column, sheet.getLastRow(), 1);
var values = range.getValues();
var heading = "";
for (var i = 0; i < values.length; i++) {
heading += values[i] + " ";
}
var html = "<html><head><title>Get Column Data</title></head><body><h1>start</h1><h1>" + heading + "</h1><h1>finish</h1></body></html>";
return HtmlService.createHtmlOutput(html);
}
// Delete a specific row
else if (mode == "deleteRow") {
var row = e.parameter.row;
sheet.deleteRow(row);
}
// Delete a specific column
else if (mode == "deleteColumn") {
var column = e.parameter.column;
sheet.deleteColumn(column);
}
// Clear the content of a specific cell
else if (mode == "deleteCell") {
var row = e.parameter.row;
var column = e.parameter.column;
var cell = sheet.getRange(row, column);
cell.clearContent();
}
}
"""
with open('script.txt', 'w') as file:
file.write(code)

0 comments on commit 4bffe2b

Please sign in to comment.