Код: Выделить всё
function onFormSubmit(e) {
generatePrefilledLinks();
}
function generatePrefilledLinks() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getDataRange().getValues();
const headers = data[0];
const dateIndex = headers.indexOf("Workout Date");
const typeIndex = headers.indexOf("Workout Type");
if (dateIndex === -1 || typeIndex === -1) {
throw new Error("Headers 'Workout Date' and/or 'Workout Type' not found.");
}
const baseURL = "https://docs.google.com/forms/d/e/1FAIpQLScojqj2IUfZSpyOATMsJKuTbr_iSGJ3NginEBY4wCwWddp8-A/viewform";
const linkCol = headers.length + 1;
sheet.getRange(1, linkCol).setValue("Prefilled Exercise Log Link");
const lastRowIndex = data.length - 1;
const workoutDate = encodeURIComponent(data[lastRowIndex][dateIndex]);
const workoutType = encodeURIComponent(data[lastRowIndex][typeIndex]);
const prefillURL = `${baseURL}?entry.1754835796=${workoutDate}&entry.2111064850=${workoutType}`;
sheet.getRange(lastRowIndex + 1, linkCol).setValue(prefillURL);
}
< /code>
», как вы можете видеть, когда я заполняю форму A It Expulatization в нижнем правом« Заголовок Log Log Logne Craj Он не работает, и я получаю пустой экран текущего экрана.function doGet() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getDataRange().getValues();
if (data.length < 2) {
return HtmlService.createHtmlOutput("No responses found.");
}
const lastRow = data.length - 1; // last row (0-indexed)
const lastCol = data[0].length - 1; // last column (0-indexed)
const lastValue = data[lastRow][lastCol].trim(); // Trim any leading or trailing spaces
// Log for debugging purposes
Logger.log("Last value: " + lastValue);
// Ensure the last value is a valid URL and redirect directly
const htmlContent = `
Redirecting to the workout log...
`;
// Return HTML content
return HtmlService.createHtmlOutput(htmlContent);
}
Получить код ссылки
Я развернулся и имею его на любом с ссылкой, а исполнитель -« я », не уверен, куда еще идти.
Подробнее здесь: https://stackoverflow.com/questions/795 ... gle-sheets
Мобильная версия