исправлено складывание ячеек

This commit is contained in:
2025-07-22 08:50:31 +03:00
parent 2671afce26
commit a71f018608
3 changed files with 61 additions and 19 deletions

View File

@@ -251,14 +251,14 @@ export function convertReferencesToHighlights(
): HighlightedCell[] { ): HighlightedCell[] {
const highlights: HighlightedCell[] = [] const highlights: HighlightedCell[] = []
const colors = [ const colors = [
'bg-blue-200 border-blue-400', 'bg-blue-200 text-blue-600',
'bg-green-200 border-green-400', 'bg-green-200 text-green-600',
'bg-purple-200 border-purple-400', 'bg-purple-200 text-purple-600',
'bg-red-200 border-red-400', 'bg-red-200 text-red-600',
'bg-yellow-200 border-yellow-400', 'bg-yellow-200 text-yellow-600',
'bg-indigo-200 border-indigo-400', 'bg-indigo-200 text-indigo-600',
'bg-pink-200 border-pink-400', 'bg-pink-200 text-pink-600',
'bg-orange-200 border-orange-400', 'bg-orange-200 text-orange-600',
] ]
let colorIndex = 0 let colorIndex = 0

View File

@@ -21,7 +21,7 @@ export function useMultiSheetEngine({
const workbookRef = useRef<Workbook | null>(null) const workbookRef = useRef<Workbook | null>(null)
const [isCalculating, setIsCalculating] = useState(false) const [isCalculating, setIsCalculating] = useState(false)
const [revision, setRevision] = useState(0) // Новый счетчик для обновлений const [revision, setRevision] = useState(0) // Новый счетчик для обновлений
const debouncedRecalcTimeoutRef = useRef<number | null>(null) const debouncedRecalcTimeoutRef = useRef<NodeJS.Timeout | null>(null)
const isRecalculatingRef = useRef(false) const isRecalculatingRef = useRef(false)
// Храним изначальные данные шаблона для сравнения // Храним изначальные данные шаблона для сравнения
@@ -149,8 +149,21 @@ export function useMultiSheetEngine({
const cellName = columnToLabel(col) + (row + 1) const cellName = columnToLabel(col) + (row + 1)
const qualifiedName = `${sheetName}!${cellName}` const qualifiedName = `${sheetName}!${cellName}`
// Устанавливаем значение в движке без пересчета // Конвертируем пустую строку в null
workbookRef.current.setCell(qualifiedName, value) const cellValue: CellValue = value === '' ? null : value
// Если значение начинается с =, то это формула
if (typeof cellValue === 'string' && cellValue.startsWith('=')) {
workbookRef.current.setCell(qualifiedName, cellValue)
} else {
// Пытаемся конвертировать в число, если возможно
const numValue = Number(cellValue)
if (!isNaN(numValue) && cellValue !== null && cellValue !== '') {
workbookRef.current.setCell(qualifiedName, numValue)
} else {
workbookRef.current.setCell(qualifiedName, cellValue)
}
}
}, },
[] []
) )
@@ -163,8 +176,21 @@ export function useMultiSheetEngine({
const cellName = columnToLabel(col) + (row + 1) const cellName = columnToLabel(col) + (row + 1)
const qualifiedName = `${sheetName}!${cellName}` const qualifiedName = `${sheetName}!${cellName}`
// Устанавливаем значение в движке // Конвертируем пустую строку в null
workbookRef.current.setCell(qualifiedName, value) const cellValue: CellValue = value === '' ? null : value
// Если значение начинается с =, то это формула
if (typeof cellValue === 'string' && cellValue.startsWith('=')) {
workbookRef.current.setCell(qualifiedName, cellValue)
} else {
// Пытаемся конвертировать в число, если возможно
const numValue = Number(cellValue)
if (!isNaN(numValue) && cellValue !== null && cellValue !== '') {
workbookRef.current.setCell(qualifiedName, numValue)
} else {
workbookRef.current.setCell(qualifiedName, cellValue)
}
}
// Запускаем безопасный пересчет // Запускаем безопасный пересчет
safeRecalc() safeRecalc()

View File

@@ -113,9 +113,17 @@ export class Cell {
return '"#REF!"' return '"#REF!"'
} }
const cellValue = this.sheet.workbook.getCell(match).evaluate() const cellValue = this.sheet.workbook.getCell(match).evaluate()
return typeof cellValue === 'string' // Только строки оборачиваем в кавычки, числа и булевы значения - нет
? `"${cellValue}"` if (typeof cellValue === 'string') {
: String(cellValue ?? 0) return `"${cellValue}"`
} else if (
typeof cellValue === 'number' ||
typeof cellValue === 'boolean'
) {
return String(cellValue)
} else {
return '0'
}
} catch (error) { } catch (error) {
return '"#REF!"' return '"#REF!"'
} }
@@ -130,9 +138,17 @@ export class Cell {
try { try {
const qualifiedRef = `${this.sheet.name}!${match}` const qualifiedRef = `${this.sheet.name}!${match}`
const cellValue = this.sheet.workbook.getCell(qualifiedRef).evaluate() const cellValue = this.sheet.workbook.getCell(qualifiedRef).evaluate()
return typeof cellValue === 'string' // Только строки оборачиваем в кавычки, числа и булевы значения - нет
? `"${cellValue}"` if (typeof cellValue === 'string') {
: String(cellValue ?? 0) return `"${cellValue}"`
} else if (
typeof cellValue === 'number' ||
typeof cellValue === 'boolean'
) {
return String(cellValue)
} else {
return '0'
}
} catch (error) { } catch (error) {
return '"#REF!"' return '"#REF!"'
} }