fix: robust xlsx column parsing via header:'A'
Switched sheet_to_json from array (header:1) to column-letter objects (header:'A'), so the parser reads B/C/D directly. Previous array destructuring broke when the sheet's range did not start at column A. Also added debug logging and a script-tag cache buster. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
024cc05b03
commit
f4ce3c97a2
9
app.js
9
app.js
@ -45,9 +45,12 @@ async function autoLoad() {
|
||||
|
||||
function loadWorkbook(buf) {
|
||||
const wb = XLSX.read(buf, { type: 'array' });
|
||||
console.log('[xlsx] sheets:', wb.SheetNames);
|
||||
const sheet = wb.SheetNames.find(n => n.toLowerCase().includes('функ')) || wb.SheetNames[0];
|
||||
const rows = XLSX.utils.sheet_to_json(wb.Sheets[sheet], { header: 1, defval: null });
|
||||
const rows = XLSX.utils.sheet_to_json(wb.Sheets[sheet], { header: 'A', defval: null });
|
||||
console.log('[xlsx] rows:', rows.length, 'sample row 2:', rows[2]);
|
||||
state.items = parseRows(rows);
|
||||
console.log('[xlsx] parsed items:', state.items.length);
|
||||
if (!state.items.length) return;
|
||||
populateGroups();
|
||||
showDashboard();
|
||||
@ -72,7 +75,9 @@ function parseRows(rows) {
|
||||
let group = 'Без группы';
|
||||
for (const row of rows) {
|
||||
if (!row) continue;
|
||||
const [_, num, desc, time] = row;
|
||||
const num = row.B;
|
||||
const desc = row.C;
|
||||
const time = row.D;
|
||||
if (!desc || String(desc).trim() === '' || String(desc).trim() === 'Функции:') continue;
|
||||
if (num == null || num === '') { group = String(desc).trim(); continue; }
|
||||
const n = Number(num);
|
||||
|
||||
@ -61,6 +61,6 @@
|
||||
|
||||
<p id="placeholder">Загрузка данных… Если дашборд не появился — нажмите «📁 Загрузить .xlsx».</p>
|
||||
|
||||
<script src="./app.js"></script>
|
||||
<script src="./app.js?v=3"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user