function copyTo() {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let ws = ss.getActiveSheet();
// по умолчанию копирует справа от активного листа, при -1 слева.
ss.insertSheet("Тест", ws.getIndex());
// ss.insertSheet("Тест", ws.getIndex() - 1);
SpreadsheetApp.flush();
}
function copyTo() {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet1 = ss.getSheetByName("Лист1");
let sheet2 = ss.getSheetByName("Лист2");
let data = sheet2.getRange(1, 1, 3, 1).getValues();
sheet1.getRange(sheet2.getLastRow() + 1, 1, 3, 1).setValues(data);
}
let bot_url = "https://t.me/EZP_test_bot" // ссылка на вашего бота
let share_twitter_button = {
inline_keyboard: [
[{
text: "Поделится в twitter✅ ",
url: "https://twitter.com/share?url=" + bot_url
}]
]
};
function sendMessage(from_chat_id, text, keyboard, id_msg) { // Отправляет сообщение используя sendMessage
var data = {
method: "sendMessage",
chat_id: String(from_chat_id),
text: text,
parse_mode: "HTML",
reply_markup: JSON.stringify(keyboard),
reply_to_message_id: String(id_msg)
};
var options = {
method: 'POST',
payload: data,
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/sendMessage', options);
console.log(JSON.parse(response.getContentText(), null, 7))
}
let keyboard_contact = {
keyboard: [
[{
text: "Авторизоваться",
request_contact: true
}]
],
resize_keyboard: true,
one_time_keyboard: true
};
let keyboard_menu_inline = {
inline_keyboard: [
[{
text: "Услуги ",
callback_data: "services"
}, {
text: "Оплата ",
url: "https://google.com",
callback_data: "pay"
}],
[{
text: "Статус ✅ ",
url: "https://google.com"
}, {
text: "Обратная связь ",
callback_data: "support"
}]
]
};
sendMessage(from_chat_id, text, keyboard)
function onOpen() {
SpreadsheetApp.getUi()
.createAddonMenu()
.addItem('goTo', 'goTo')
.addToUi()
}
function goTo() {
let htmlOutput = HtmlService
.createHtmlOutput(
`<script>
window.open("https://google.com");
google.script.host.close();
</script>`)
.setWidth(20)
.setHeight(20);
SpreadsheetApp.getUi().showModelessDialog(htmlOutput, 'Переход');
}
let ID = "<id вашей папки>";
function createFolder() {
let mainFolder = DriveApp.getFolderById(ID);
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let foldersNames = sheet.getRange(2, 1, sheet.getLastRow(), 3).getValues();
let folders = mainFolder.getFolders();
let arr = [];
while (folders.hasNext()) {
let folder = folders.next();
arr.push({
"name": folder.getName(),
"folderID": folder.getId(),
"lastUpdated": folder.getLastUpdated()
})
}
let res = arr.map(item => item.name);
foldersNames.forEach((el, index) => {
if (typeof el[0] === "string" && res.indexOf(el[0]) === -1 && el[0] != "") {
let nFolder = mainFolder.createFolder(el[0]);
sheet.getRange(index + 2, 2, 1, 2).setValues([[nFolder.getId(), nFolder.getLastUpdated()]]);
console.log(`New folder created!
name: ${el[0]}
creation date: ${nFolder.getLastUpdated()}
`)
}
})
}
function downloadData() {
let mainFolder = DriveApp.getFolderById(ID);
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let foldersNames = sheet.getRange(2, 1, sheet.getLastRow(), 3).getValues().map(item => item[0]);
let folders = mainFolder.getFolders();
let arr = [];
while (folders.hasNext()) {
let folder = folders.next();
arr.push({
"name": folder.getName(),
"folderID": folder.getId(),
"lastUpdated": folder.getLastUpdated()
})
}
arr.forEach(el => {
if (foldersNames.indexOf(el.name) === -1 && foldersNames.indexOf(el.folderID) === -1) {
sheet.getRange(sheet.getLastRow() + 1, 1, 1, 3).setValues([[el.name, el.folderID, el.lastUpdated]]);
}
})
console.log(arr)
}
function onEdit(e){
let row = e.range.getRow();
let column = e.range.getColumn();
let cache = CacheService.getScriptCache();
cache.putAll({
"row": `${row}`,
"column": `${column}`
});
}
function onOpen() {
let cache = CacheService.getScriptCache();
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let row = cache.get("row");
let column = cache.get("column");
sheet.getRange(+row, +column).activate();
SpreadsheetApp.flush();
}
function onEdit(e) {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let row = e.range.getRow();
let column = e.range.getColumn();
let value = e.source.getActiveSheet().getRange(row, 1).getValue();
let checkbox = SpreadsheetApp.newDataValidation().requireCheckbox().setAllowInvalid(false).build();
if (column == 1 && value !== "") {
sheet.getRange(row, 2).setDataValidation(checkbox).setValue(false);
}
}