HOW TO UPLOAD AND READ XLSX FILE
ุงูุณูุงู ุนูููู ๐
ุงูููุงุฑุฏู ููุดูู ุฅุฒุงู ูุฑูุน ู ููุฑุฃ ูุงูู XLSX ุจุฅุณุชุฎุฏุงู ุงูุฌุงูุง ุฅุณูุฑุจุช ๐
ุขุฎุฑ ุจุฑูุฌูุช ุฅุดุชุบูุช ุนููู ูุงู ู ุทููุจ ู ูู ุฃุฑูุน ู ุฃูุฑุฃ ูุงูู XLSX ู ุฃุนุฑุถู ูู ุฌุฏูู ุนุดุงู ูุธูุฑ ููููุฒุฑ, ุงููุงูู ุฏุง ุจูููู ููู ุจูุงูุงุช ุงูุทูุงุจ ู ุนู ูุช ุณูุฑุด ู ูููุช sheetJS, ู ุงูู ูุถูุน ูุงู ู ูุชุบูุฑ ุจุดูู ูุจูุฑ ูุฃู ููู ุตู ุฏุฑุงุณู ู ูุงุฏ ุฎุงุตุฉ ุจูู ู ููู ู ุงุฏุฉ ุงูุฏุฑุฌุฉ ุงูุฎุงุตุฉ ุจููุง ูุง ูุงู ูุงุฒู ุฃุนู ู ุญุงุฌุฉ ู ูุฎุชุฑู ุฉ ุชู ุดู ู ุน ุงูู ูุถูุน ุฏุง, ุจุฑุถู ูุงู ููู ุฏุฑุฌุฉ ุญุฏ ุฃูุตู ูุง ูุงู ูุงุฒู ุฃุดูู ุนูู ูู ุงูุฏุฑุฌุงุช ุงููู ุจูุฑุฃูุง ู ู ุงููุงูู ุจุญูุซ ุฅููุง ุชููู ุฃูู ู ู ุฃู ุชุณุงูู ุงูุญุฏ ุงูุฃูุตู ูุง ุชุนุงููุง ูุฏุง ูุดูู ุงูููุฏ ุดููู ููุจูู ุนุงู ู ุฅุฒุงู ๐ค
var yourColumnsNames = ["name", "arabic", "english", "art", "music"];
var maxDegrees = [20, 30, 30, 15];
ุฃููุงู ูุฏุง ุฏูู ุงูู ูุชุบูุฑุงุช ุงููู ูุณุชุฎุฏู ูู ูู ูู ุดุบูู, ุฃูู ู ูุชุบูุฑ ุฏุง ููู ุฃุณู ุงุก ุงูุฃุนู ุฏู ุงููู ู ุชููุน ุฅููุง ุชููู ู ูุฌูุฏุฉ ูู ุงููุงูู, ู ุชุงูู ู ูุชุบูุฑ ุฏุง ููู ุงูุญุฏ ุงูุฃูุตู ููู ุฏุฑุฌุฉ ู ูุฌูุฏุฉ ูู ุงููุงูู, ุทุจุนุงู ุงูุจูุงูุงุช ุฏู ุจุชููู ู ุชุฎุฒูุฉ ุนูู ุงูุณูุณุชู ู ู ุฎูุงู ุงูุฃุฏู ู ๐คด
function setStudentMarksDataRow(rowNumber, currentRow = null) { var body = null, column = 0;const prefix = `<tr id="student_row_data_${rowNumber}"><td><label>${rowNumber} </label><td><td><input type="text" class="form-control" name="students_names[]" style="width:400px;" value="${currentRow ? currentRow[yourColumnsNames[column]] : ''}"></td>`; column += 1; // `-1` to exclude the `name` column for (; column < yourColumnsNames.length - 1; column++) { body += `<td><input type="number" class="form-control input_mark_${rowNumber}" name="marks[]" value="${currentRow ? currentRow[yourColumnsNames[column]] : ''}" min="0" onchange="checkInputMaxDegree(${rowNumber});"></td>`; }return `${prefix}${body}<td><input type="number" class="form-control" id="marks_sum_${rowNumber}" name="marks[]" value="${currentRow ? currentRow[yourColumnsNames[column]] : ''}" min="0" readonly></td></tr>`; }
ุซุงููุงู ุงูุฏุงูุฉ ุฏู ู ู ุฎูุงููุง ุจูุฑุฃ ูู ุตู ูู ุงููุงูู ู ุจุนุฑุถู ูู ุฌุฏูู ุนุดุงู ูุธูุฑ ููููุฒุฑ ๐
function getMarksSum(rowNumber) {
var marksInputs = document.getElementsByClassName(`input_mark_${rowNumber}`);
var marksSum = 0;
for (var i = 0; i < marksInputs.length; i++) {
var currentValue = isNaN(parseInt(marksInputs[i].value)) ? 0 : parseInt(marksInputs[i].value);
marksSum += currentValue;
}
document.getElementById(`marks_sum_${rowNumber}`).value = marksSum;
}
ุซุงูุซุงู ุนู ูุช ุฏุงูุฉ ู ู ุฎูุงููุง ุจุฌู ุน ูู ุงูุฏุฑุฌุงุช ุงููู ุชู ูุฑุงุกุชูุง ู ุจุนุฏูู ุจุนุฑุถูุง ูู ู ูุฑุจุน ูุตู ๐
function checkInputMaxDegree(rowNumber) {
var validMaxDegreesCount = 0;
for (var i = 0; i < $("input[name='marks[]']").length; i++) {
if (parseInt($("input[name='marks[]']")[i].value) > parseInt(maxDegrees[i % maxDegrees.length])) {
$('#button_error').text(`the current value must be less than or equal ${maxDegrees[i % maxDegrees.length]}.`);
validMaxDegreesCount += 1;
} else {
validMaxDegreesCount -= 1;
}
}
if (validMaxDegreesCount * -1 >= $("input[name='marks[]']").length) {
getMarksSum(rowNumber);
}
}
ุฑุงุจุนุงู ุนู ูุช ุฏุงูุฉ ู ู ุฎูุงููุง ุจุดูู ุนูู ุงูุญุฏ ุงูุฃูุตู ููู ุฏุฑุฌุฉ โฌ
$('input[type=file]').change(function () {
const uploadedFile = $(this)[0].files[0];
if (uploadedFile.name.split('.').pop() == 'xlsx') {
var reader = new FileReader();
if (reader.readAsBinaryString) {
reader.onload = function (e) {
var workbook = XLSX.read(e.target.result, { type: 'binary' }), columnNotExists = false;
// Read the first sheet ONLY
var sheetRows = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[workbook.SheetNames[0]]);
// You can check the columns count in the sheet
if (Object.keys(sheetRows[0]).length != yourColumnsNames.length) {
console.log('please make sure that the columns count are equivalent.');
return false;
}
// You can check the columns name also
Object.keys(sheetRows[0]).forEach(function (key, index) {
if (yourColumnsNames[index] != key) {
console.log(`column ${yourColumnsNames[index]} not exists.`);
columnNotExists = true;
}
});
if (columnNotExists) {
return false;
}
$("tbody").html(null);
// Loop over each row and get the sum of each mark
sheetRows.map(function (row, index) {
$("tbody").append(setStudentMarksDataRow(index + 1, row));
getMarksSum(index + 1);
checkInputMaxDegree(index + 1);
});
};
reader.readAsBinaryString(uploadedFile);
}
} else {
console.log("file extension is invalid.");
}
});
ู ุฏู ูุงูุช ุขุฎุฑ ุญุงุฌุฉ ู ุนุงูุง ู ูู ุฅูู ุจูุฑุฃ ุงููุงูู ุงูู ุฑููุน ู ุจุณุชุฎุฏู ูู ุงูุฏูุงู ุงููู ููู ุฏู ุฃุซูุงุก ุนู ููุฉ ุงููุฑุงุกุฉ ๐
ู ุฃุฎูุฑุงู ูููู ุงูุจุฑูุฌูุช ๐
ู ุจูุฏุง ุฃููู ุฎูุตุช ู ุฃุชู ูู ุชููู ุฅุณุชูุฏุช โ
AI Assistant
Choose AI provider
Text Tools
Make content clear and easy to read
Have a Question?
Get clear answers based on this content