Untitled
unknown
plain_text
3 years ago
1.1 kB
11
Indexable
const fs = require('fs');
const xlsx = require('xlsx');
fs.readFile('results.txt', 'utf8', (err, data) => {
if (err) throw err;
// Split the file into an array of lines
const lines = data.split('\n');
// Create an array to hold the extracted data
const extractedData = [];
// Iterate over each line
lines.forEach(line => {
// Extract the relevant information from the line
const studentNumber = line.slice(0, 9);
const identityNumber = line.slice(9, 20);
const studentName = line.slice(20, 42);
const answer = line.slice(42, 92);
// Add the extracted data to the array
extractedData.push({ studentNumber, identityNumber, studentName, answer });
});
// Create a new workbook
const workbook = xlsx.utils.book_new();
// Add a worksheet to the workbook
const worksheet = xlsx.utils.aoa_to_sheet(extractedData);
xlsx.utils.book_append_sheet(workbook, worksheet, 'Results');
// Write the workbook to an Excel file
xlsx.writeFile(workbook, 'results.xlsx');
});
Editor is loading...