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

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[] {
const highlights: HighlightedCell[] = []
const colors = [
'bg-blue-200 border-blue-400',
'bg-green-200 border-green-400',
'bg-purple-200 border-purple-400',
'bg-red-200 border-red-400',
'bg-yellow-200 border-yellow-400',
'bg-indigo-200 border-indigo-400',
'bg-pink-200 border-pink-400',
'bg-orange-200 border-orange-400',
'bg-blue-200 text-blue-600',
'bg-green-200 text-green-600',
'bg-purple-200 text-purple-600',
'bg-red-200 text-red-600',
'bg-yellow-200 text-yellow-600',
'bg-indigo-200 text-indigo-600',
'bg-pink-200 text-pink-600',
'bg-orange-200 text-orange-600',
]
let colorIndex = 0

View File

@@ -21,7 +21,7 @@ export function useMultiSheetEngine({
const workbookRef = useRef<Workbook | null>(null)
const [isCalculating, setIsCalculating] = useState(false)
const [revision, setRevision] = useState(0) // Новый счетчик для обновлений
const debouncedRecalcTimeoutRef = useRef<number | null>(null)
const debouncedRecalcTimeoutRef = useRef<NodeJS.Timeout | null>(null)
const isRecalculatingRef = useRef(false)
// Храним изначальные данные шаблона для сравнения
@@ -149,8 +149,21 @@ export function useMultiSheetEngine({
const cellName = columnToLabel(col) + (row + 1)
const qualifiedName = `${sheetName}!${cellName}`
// Устанавливаем значение в движке без пересчета
workbookRef.current.setCell(qualifiedName, value)
// Конвертируем пустую строку в null
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 qualifiedName = `${sheetName}!${cellName}`
// Устанавливаем значение в движке
workbookRef.current.setCell(qualifiedName, value)
// Конвертируем пустую строку в null
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()

View File

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