Я пытаюсь использовать скрипт приложений Google, чтобы создать викторины Google Forms и тесты из данных Google Sheets, начиная со следующего учебного года. < /p>
function createQuizFromSheet() {
// Get the active spreadsheet and sheet
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
const quizTitle = sheet.getName();
// Get all the data from the sheet, skipping the header row
const data = sheet.getDataRange().getValues().slice(1);
// Create a new Google Form
const form = FormApp.create(quizTitle);
form.setIsQuiz(true); // Turn the form into a quiz
// Loop through each row of data (each question)
data.forEach(row => {
// Extract question details from the row
const questionTitle = row[0];
const choices = row.slice(1, 5); // Choices A-D
const correctAnswerLetter = row[5];
const points = row[6];
// Convert the letter to index for correct choice
let correctAnswerIndex = 0;
if (correctAnswerLetter === "B") correctAnswerIndex = 1;
if (correctAnswerLetter === "C") correctAnswerIndex = 2;
if (correctAnswerLetter === "D") correctAnswerIndex = 3;
// Add multiple choice question to the form
const item = form.addMultipleChoiceItem()
.setTitle(questionTitle);
// Create choices, mark the correct one and set points
const choiceItems = [];
for(let i = 0; i< choices.length; i++){
if (choices){ //only create if the choice is not blank
choiceItems.push(item.createChoice(choices, i === correctAnswerIndex));
}
}
item.setChoices(choiceItems);
item.setPoints(points);
});
// Get and log the form's published URL
const formUrl = form.getPublishedUrl();
Logger.log('Form URL: ' + formUrl);
// Optional: Display form URL in the spreadsheet
// sheet.getRange(1, 8).setValue('Form URL'); // Set header
// sheet.getRange(2, 8).setValue(formUrl); // Output URL
}
< /code>
Мой скрипт отлично работает с двумя исключениями: < /p>
Сценарий не публикует URL -адрес новой оценки форм Google. Поэтому я могу получить доступ только к форме из моего Google Drive. Если сценарий читает столбцы I через L, мне интересно, есть ли способ запрограммировать сценарий, чтобы игнорировать эти данные.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... exceptions
Мой скрипт Google Apps отлично работает только с двумя исключениями [закрыто] ⇐ Javascript
Форум по Javascript
1749305154
Anonymous
Я пытаюсь использовать скрипт приложений Google, чтобы создать викторины Google Forms и тесты из данных Google Sheets, начиная со следующего учебного года. < /p>
function createQuizFromSheet() {
// Get the active spreadsheet and sheet
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
const quizTitle = sheet.getName();
// Get all the data from the sheet, skipping the header row
const data = sheet.getDataRange().getValues().slice(1);
// Create a new Google Form
const form = FormApp.create(quizTitle);
form.setIsQuiz(true); // Turn the form into a quiz
// Loop through each row of data (each question)
data.forEach(row => {
// Extract question details from the row
const questionTitle = row[0];
const choices = row.slice(1, 5); // Choices A-D
const correctAnswerLetter = row[5];
const points = row[6];
// Convert the letter to index for correct choice
let correctAnswerIndex = 0;
if (correctAnswerLetter === "B") correctAnswerIndex = 1;
if (correctAnswerLetter === "C") correctAnswerIndex = 2;
if (correctAnswerLetter === "D") correctAnswerIndex = 3;
// Add multiple choice question to the form
const item = form.addMultipleChoiceItem()
.setTitle(questionTitle);
// Create choices, mark the correct one and set points
const choiceItems = [];
for(let i = 0; i< choices.length; i++){
if (choices[i]){ //only create if the choice is not blank
choiceItems.push(item.createChoice(choices[i], i === correctAnswerIndex));
}
}
item.setChoices(choiceItems);
item.setPoints(points);
});
// Get and log the form's published URL
const formUrl = form.getPublishedUrl();
Logger.log('Form URL: ' + formUrl);
// Optional: Display form URL in the spreadsheet
// sheet.getRange(1, 8).setValue('Form URL'); // Set header
// sheet.getRange(2, 8).setValue(formUrl); // Output URL
}
< /code>
Мой скрипт отлично работает с двумя исключениями: < /p>
Сценарий не публикует URL -адрес новой оценки форм Google. Поэтому я могу получить доступ только к форме из моего Google Drive. Если сценарий читает столбцы I через L, мне интересно, есть ли способ запрограммировать сценарий, чтобы игнорировать эти данные.>
Подробнее здесь: [url]https://stackoverflow.com/questions/79657017/my-google-apps-script-works-perfectly-with-only-two-exceptions[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия