Skip to content

fix: resolve the remaining confirmed bugs (0.4.0) - #5

Open
4a4c53 wants to merge 12 commits into
mainfrom
claude/fix-remaining-bugs
Open

fix: resolve the remaining confirmed bugs (0.4.0)#5
4a4c53 wants to merge 12 commits into
mainfrom
claude/fix-remaining-bugs

Conversation

@4a4c53

@4a4c53 4a4c53 commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Resumen

Corrige 11 de los 12 errores confirmados en docs/bugs.md, uno por commit, y sube la versión a 0.4.0 porque varios cambian comportamiento documentado (sheet(), rowCount/colCount, cabeceras duplicadas).

Lectura

  • Prefijos de namespace. Archivos con <x:worksheet><x:row><x:c> (Open XML SDK, herramientas .NET) se leían como hoja vacía sin error. stripElementPrefixes() normaliza cada parte al cargarla; solo toca nombres de elemento, los atributos como r:id se conservan.
  • Fórmulas compartidas. Las celdas dependientes de <f t="shared" si="N"/> devolvían formula() === null. Nuevo src/formula.ts: se guarda la maestra por si y se desplazan las referencias relativas. Literales de texto y nombres de hoja entrecomillados intactos, partes absolutas conservadas, rangos de columna (A:A) desplazados, #REF! si sale de la cuadrícula. Limitación documentada: los rangos de fila completa (1:1) no se desplazan.
  • Archivos corruptos. <row r="abc"> producía fila NaN; <c r="A5"> dentro de <row r="1"> tomaba la fila 1 en silencio; un índice de shared string inexistente devolvía null. Los tres lanzan ahora errores que nombran la hoja y la referencia.

Escritura

  • Fechas anteriores a 1899-12-30 hacían serial negativo y Excel mostraba #####. toBuffer() lanza RangeError con la celda, para fechas planas y valores cacheados de fórmula. El serial 0 sigue siendo válido y la lectura de seriales negativos se mantiene tolerante.

API

  • Workbook.sheet(name) busca sin distinguir mayúsculas, coherente con la unicidad de addSheet y con Excel.
  • rowCount/colCount decrecen al borrar la celda del borde. Las filas reservadas por addRow() conservan su sitio aunque queden vacías.
  • toObjects() sufija cabeceras repetidas (_2, _3…) en vez de pisarlas, saltando nombres ya ocupados.
  • isSheetNameError() comprueba una marca Symbol propia en vez de cualquier Error con rule. Se exportan isSheetNameError, SheetNameError y SheetNameRule.

Empaquetado

  • stripInternal: true: el .d.ts publicado ya no expone _cells ni otros miembros internos.

No incluido

Verificación

Comprobación Resultado
pnpm test 197 tests, 0 fallos (27 nuevos)
pnpm test:coverage 99,54 % líneas · 93,28 % ramas · 100 % funciones
pnpm lint, pnpm typecheck, pnpm build limpios
Merge con main limpio (incluye ya el PR #4)

Open XML SDK and other .NET producers write <x:worksheet xmlns:x="…">
with every element prefixed. The linear scanner looks for bare tag
names, so those files silently read as empty sheets. Normalize each
part once on load by stripping the prefix from element names only;
attributes such as r:id are untouched.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A <row r="abc"> produced "fila NaN" from setCellAt with no hint of the
sheet; a <c r="A5"> inside <row r="1"> silently took the row's number;
and a shared-string index past the table (or not a number) silently
became null. All three are corrupt files and now fail with a message
naming the sheet, the row and the reference.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Excel writes a dragged formula once, on the master cell, and marks the
dependents with an empty <f t="shared" si="N"/>. Those cells read back
with formula() === null. Keep the master per si and derive each
dependent by shifting relative references (new src/formula.ts): text
literals and quoted sheet names are left alone, absolute parts are kept,
whole-column ranges shift, whole-row ranges are left as-is, and a
reference pushed off the grid becomes #REF! like Excel.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A Date before Excel's epoch serialized to a negative serial, which Excel
renders as ##### with no error. Fail toBuffer() with a RangeError naming
the cell instead, for plain and cached-formula dates alike. Serial 0
(1899-12-30) stays valid.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
addSheet() rejects 'datos' when 'Datos' exists, yet sheet('datos')
returned null. Excel itself treats sheet names case-insensitively, so
make the lookup match the uniqueness rule.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
_maxRow and _maxCol only ever grew, so clearing a far cell left the
sheet reporting (and toRows() materializing) a range that was no longer
occupied. Recompute the bounds when the deleted cell sat on the current
edge. Rows appended with addRow() keep their reservation even when they
end up empty, so the next addRow() still lands below them.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Two columns with the same header collapsed into one key and the first
column's values were silently lost. Repeated headers now get _2, _3, …
appended until unique, skipping names already taken by other columns.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
isSheetNameError() accepted any Error carrying a rule property. Mark
the errors created by validateSheetName with a non-enumerable symbol
and check for it, and export isSheetNameError, SheetNameError and
SheetNameRule from the package entry point.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
_cells, _maxRow and friends are implementation details shared between
Sheet and the writer; they no longer leak into dist/*.d.ts.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Mark the resolved items in docs/bugs.md, leave the t="e" error-cell
change as a pending design decision, and describe in the README the
case-insensitive sheet lookup, shrinking rowCount/colCount, suffixed
duplicate headers, pre-1900 date validation, shared-formula
reconstruction, namespace-prefixed parts and the new reader checks.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants