added end column for XLS in template and import

This commit is contained in:
2026-06-18 16:50:38 +02:00
parent 4dc010d80e
commit 955b663322
6 changed files with 225 additions and 6 deletions
@@ -4,6 +4,35 @@ require_once 'class/db-functions.php';
$response = ["success" => false, "message" => ""];
function excelColumnToIndex($column)
{
$column = strtoupper(trim((string)$column));
if ($column === '') {
return null;
}
// Numeric column index, example: 40
if (ctype_digit($column)) {
$index = (int)$column;
return $index > 0 ? $index : null;
}
// Excel column letters, example: A, AN, XFC
if (!preg_match('/^[A-Z]+$/', $column)) {
return null;
}
$index = 0;
$length = strlen($column);
for ($i = 0; $i < $length; $i++) {
$index = ($index * 26) + (ord($column[$i]) - ord('A') + 1);
}
return $index;
}
try {
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
throw new Exception("Invalid request method.");
@@ -19,6 +48,8 @@ try {
: null;
$start_column = trim($_POST['start_column'] ?? '');
$xls_end_column = strtoupper(trim($_POST['xls_end_column'] ?? ''));
$xls_end_column = $xls_end_column !== '' ? $xls_end_column : null;
$xls_sheet_index = isset($_POST['xls_sheet_index']) && $_POST['xls_sheet_index'] !== ''
? intval($_POST['xls_sheet_index'])
@@ -60,6 +91,24 @@ try {
throw new Exception("XLS Sheet Number cannot be negative.");
}
$startColumnIndex = excelColumnToIndex($start_column);
if ($startColumnIndex === null) {
throw new Exception("Start Column is not valid. Use Excel column letters like A, AN or a positive number.");
}
if ($xls_end_column !== null) {
$endColumnIndex = excelColumnToIndex($xls_end_column);
if ($endColumnIndex === null) {
throw new Exception("Last Column is not valid. Use Excel column letters like AN or a positive number.");
}
if ($endColumnIndex < $startColumnIndex) {
throw new Exception("Last Column cannot be before Start Column.");
}
}
$api_config_id = null;
}
@@ -71,6 +120,7 @@ try {
$header_row = null;
$start_column = null;
$xls_end_column = null;
$xls_sheet_index = null;
}
@@ -78,6 +128,7 @@ try {
if ($source_type === 'PDF') {
$header_row = null;
$start_column = null;
$xls_end_column = null;
$xls_sheet_index = null;
$api_config_id = null;
}
@@ -109,6 +160,7 @@ try {
source_type = ?,
header_row = ?,
start_column = ?,
xls_end_column = ?,
xls_sheet_index = ?,
api_config_id = ?,
description = ?,
@@ -131,6 +183,7 @@ try {
$source_type,
$header_row,
$start_column,
$xls_end_column,
$xls_sheet_index,
$api_config_id,
$description,