Fix import

This commit is contained in:
r.mubarakzyanov 2026-03-31 17:15:43 +03:00
parent 0be7109df4
commit abb4200215
2 changed files with 22 additions and 2 deletions

View File

@ -575,6 +575,10 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
while (headers.length > 0 && headers[headers.length - 1] === '') { while (headers.length > 0 && headers[headers.length - 1] === '') {
headers.pop(); headers.pop();
} }
headers = headers.map((h, i) => {
h = h.replace(/[\r\n\t]+/g, ' ').trim();
return h === '' ? `__empty_${i + 1}__` : h;
});
console.log("Intestazioni estratte (manual):", headers); console.log("Intestazioni estratte (manual):", headers);
availableXlsColumns = [...headers]; availableXlsColumns = [...headers];
usedColumnsFromDB = []; usedColumnsFromDB = [];
@ -707,8 +711,11 @@ $xlsHeaders = $template['xls_headers'] ? json_decode($template['xls_headers'], t
while (headers.length > 0 && headers[headers.length - 1] === '') { while (headers.length > 0 && headers[headers.length - 1] === '') {
headers.pop(); headers.pop();
} }
// Final clean: ensure no whitespace-only entries sneak through // Final clean + name empty columns to match __empty_N__ convention
headers = headers.map(h => h.replace(/[\r\n\t]+/g, ' ').trim()); headers = headers.map((h, i) => {
h = h.replace(/[\r\n\t]+/g, ' ').trim();
return h === '' ? `__empty_${i + 1}__` : h;
});
console.log("Logical headers:", headers, `(${headers.length} columns from ${rawRow.length} physical)`); console.log("Logical headers:", headers, `(${headers.length} columns from ${rawRow.length} physical)`);
availableXlsColumns = [...headers]; availableXlsColumns = [...headers];
usedColumnsFromDB = []; usedColumnsFromDB = [];

View File

@ -74,6 +74,16 @@ try {
$startRow = max(1, $header_row); $startRow = max(1, $header_row);
$startColumn = max(1, $start_column); $startColumn = max(1, $start_column);
// Advance startColumn to first non-empty cell in header row (match JS behavior)
for ($sc = $startColumn; $sc <= $highestColumnIndex; $sc++) {
$cl = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($sc);
$cv = trim((string)($worksheet->getCell($cl . $header_row)->getCalculatedValue() ?? ''));
if ($cv !== '') {
$startColumn = $sc;
break;
}
}
// Debug dei parametri // Debug dei parametri
error_log("Processing - template_id: $template_id, startRow: $startRow, startColumn: $startColumn, highestRow: $highestRow, highestColumn: $highestColumn, highestColumnIndex: $highestColumnIndex"); error_log("Processing - template_id: $template_id, startRow: $startRow, startColumn: $startColumn, highestRow: $highestRow, highestColumn: $highestColumn, highestColumnIndex: $highestColumnIndex");
@ -127,6 +137,9 @@ try {
$headerRowData[] = ($cellValue !== '') ? $cellValue : '__empty_' . $logicalNum . '__'; $headerRowData[] = ($cellValue !== '') ? $cellValue : '__empty_' . $logicalNum . '__';
} }
error_log("Logical headers: " . json_encode($headerRowData));
error_log("Logical cols (physical indices): " . json_encode($logicalCols));
// Find which logical columns have real headers // Find which logical columns have real headers
$headerFilledIndices = []; $headerFilledIndices = [];
foreach ($headerRowData as $idx => $hVal) { foreach ($headerRowData as $idx => $hVal) {