Мой скрипт Google Apps отлично работает только с двумя исключениями [закрыто]Javascript

Форум по Javascript
Ответить
Anonymous
 Мой скрипт Google Apps отлично работает только с двумя исключениями [закрыто]

Сообщение 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){ //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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»