Demo 26 - Rigorous Spreadsheet Semantic Validation

Abstract

This demo showcases rigorous semantic validation functionality when importing spreadsheet data. Through \strictcell commands and type declarations in the \spreadsheet directive, the compiler requires extracted data to strictly match expected types (number, string, currency, date, etc.). Inconsistencies generate clear error messages, preventing silent document corruption.

1 Full Table Import with Type Check (Strict)

Below we import table data.xlsx expecting exact structure: number, string, currency, number. Since the spreadsheet has intentional errors in data rows, the rendered table will flag explicit errors and the compiler would alert the author.

Table 1. Full Import (Excel) via Macro
ID Produto Receita (Esperado Moeda) Qtd (Esperado Num)
1 Cadeira Gamer [MC-WARN: Expected currency] [MC-WARN: Expected number]
2 Mouse R$ 120.00 50
3 [MC-WARN: Expected string] R$ 300.00 5
Source: Validation spreadsheet (data.xlsx)

And the corresponding version processed from LibreOffice (.ods) for visual and semantic comparison:

Table 2. Full Import (ODS)
ID Produto Receita (Esperado Moeda) Qtd (Esperado Num)
1 Cadeira Gamer [MC-WARN: Expected currency] [MC-WARN: Expected number]
2 Mouse R$120,00 50
3 [MC-WARN: Expected string] R$300,00 5
Source: Validation spreadsheet (data.ods)

2 Standard Import (Without Type Check)

For comparison purposes, see how the same table is rendered if we use standard import (without the types attribute). The spreadsheet is ingested with its inconsistencies, potentially introducing semantically incorrect data (such as “10 un” instead of the number 10) into your final document silently:

Table 3. Standard Import (Excel)
ID Produto Receita (Esperado Moeda) Qtd (Esperado Num)
1 Cadeira Gamer 1500.5 10 un
2 Mouse R$ 120.00 50
3 R$ 300.00 5
Source: Validation spreadsheet (data.xlsx) without type checking

The LibreOffice (.ods) version:

Table 4. Standard Import (ODS)
ID Produto Receita (Esperado Moeda) Qtd (Esperado Num)
1 Cadeira Gamer 1500,5 10 un
2 Mouse R$120,00 50
3 R$300,00 5
Source: Validation spreadsheet (data.ods) without type checking

3 Dynamic Formula Evaluation

In this complex example, we import the Formulas sheet, which contains dynamic columns such as Total (using SUM), Average (using AVERAGE), and Performance (using IF). MarkCharm and its internal spreadsheet engine (formulas) calculate the equations in real time during import.

The cells continue to respect both the currency format and correct type extraction (including conditional logic returning a string).

Table 5. Dynamic Formulas (Excel)
Vendedor Vendas Q1 Vendas Q2 Total Média Desempenho (IF)
Ana R$ 5,000.00 R$ 6,000.00 R$ 11,000.00 R$ 5,500.00 Excelente
Bruno R$ 2,000.00 R$ 3,000.00 R$ 5,000.00 R$ 2,500.00 Bom
Carlos R$ 8,000.00 R$ 9,000.00 R$ 17,000.00 R$ 8,500.00 Excelente
Source: Formulas sheet (data.xlsx)

And the same dynamic test evaluating functions within a native .ods file:

Table 6. Dynamic Formulas (ODS)
Vendedor Vendas Q1 Vendas Q2 Total Média Desempenho (IF)
Ana R$5.000,00 R$6.000,00 R$11.000,00 R$5.500,00 Excelente
Bruno R$2.000,00 R$3.000,00 R$5.000,00 R$2.500,00 Bom
Carlos R$8.000,00 R$9.000,00 R$17.000,00 R$8.500,00 Excelente
Source: Formulas sheet (data.ods)

4 Individual Cell Import (Inline)

It is also possible to check types in individual cells via \strictcell and in \cell{..., expect="..."}:

From Excel (.xlsx):

And identical behavior from LibreOffice (.ods):


5 Strict Style Preservation (Rich Styling)

MarkCharm's xlsx_loader (and its counterpart ods_loader) is not just a simple text extractor — it seamlessly maps the visual architecture and styling of spreadsheets directly into inline HTML.

Our engine natively processes the following layout metadata from the source spreadsheet:

Below, we import a heavily styled spreadsheet (packed with background colors, white or red text, merged categories, and a 'Grand Total' row with thick borders). Notice how individual alignment options (right-aligned text), colors, and borders were captured perfectly. By default, the table adapts fluidly to the page layout (ignoring Excel's fixed heights and widths for a more responsive look):

Table 7. Untitled
Tabela de Estilos Avançados (Bordas e Cores)
ID Produto Categoria Preço Estoque Status
1 Notebook Eletrônicos 3500 15 Ativo
2 Mouse Gamer RGB 150 50 Ativo
3 Cadeira Ergonomica Móveis 800 0 Esgotado
4 Mesa de Escritório 1200 5 Ativo
5 Teclado Mecânico (Red) Acessórios 300 10 Promoção
6 Monitor Ultrawide (Blue) 2100 2 Limitado
7 Headset Pro (Green) 450 30 Lançamento
Total Geral 8500
Source: Base styled spreadsheet (styled_table.xlsx)

Faithfully extracted version from LibreOffice (.ods):

Table 8. Untitled
Tabela de Estilos Avançados (Bordas e Cores)
ID Produto Categoria Preço Estoque Status
1 Notebook Eletrônicos 3500 15 Ativo
2 Mouse Gamer RGB 150 50 Ativo
3 Cadeira Ergonomica Móveis 800 0 Esgotado
4 Mesa de Escritório 1200 5 Ativo
5 Teclado Mecânico (Red) Acessórios 300 10 Promoção
6 Monitor Ultrawide (Blue) 2100 2 Limitado
7 Headset Pro (Green) 450 30 Lançamento
Total Geral 8500
Source: Base styled spreadsheet (styled_table.ods)

6 Extreme Palette Performance (Magic Square)

To stress-test the RGB -> HEX color extraction engine, below we generate a classic 5x5 Magic Square (where the sum of all rows, columns, and diagonals yields the same value: 65).

Each cell has a distinct rainbow color, dynamically filled based on its numeric value. The font color automatically adapts between black and white depending on background luminance:

Chart 1. Magic Square (Excel)
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Source: Styled magic square (styled_table.xlsx)

The ODS version:

Chart 2. Magic Square (ODS)
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Source: Styled magic square (styled_table.ods)

7 Raw Mode Import

Often you only want to import data without bringing along the heavy formatting embedded by spreadsheet users (such as gaudy colors or fonts diverging from the document standard). For these scenarios, the styled="false" flag was introduced in the MarkCharm infrastructure.

Below we have the exact same table and A1:F10 region imported without styles (notice how colors, fixed dimensions, borders, and typography have all been suppressed to inherit the clean native appearance of the document):

Table 9. Untitled
Tabela de Estilos Avançados (Bordas e Cores)
ID Produto Categoria Preço Estoque Status
1 Notebook Eletrônicos 3500 15 Ativo
2 Mouse Gamer RGB 150 50 Ativo
3 Cadeira Ergonomica Móveis 800 0 Esgotado
4 Mesa de Escritório 1200 5 Ativo
5 Teclado Mecânico (Red) Acessórios 300 10 Promoção
6 Monitor Ultrawide (Blue) 2100 2 Limitado
7 Headset Pro (Green) 450 30 Lançamento
Total Geral 8500
Source: Base spreadsheet in raw mode (styled_table.xlsx)

Raw extraction via LibreOffice (.ods):

Table 10. Untitled
Tabela de Estilos Avançados (Bordas e Cores)
ID Produto Categoria Preço Estoque Status
1 Notebook Eletrônicos 3500 15 Ativo
2 Mouse Gamer RGB 150 50 Ativo
3 Cadeira Ergonomica Móveis 800 0 Esgotado
4 Mesa de Escritório 1200 5 Ativo
5 Teclado Mecânico (Red) Acessórios 300 10 Promoção
6 Monitor Ultrawide (Blue) 2100 2 Limitado
7 Headset Pro (Green) 450 30 Lançamento
Total Geral 8500
Source: Base spreadsheet in raw mode (styled_table.ods)

8 Geometry and Alignment Stress Test

Below, we import a “Scorecard” that tests the limits of the spreadsheet extractor. It showcases extreme vertical alignments (Top, Middle, Bottom), combined horizontal alignments, and varied border thicknesses (thin gray vs. thick black).

To prove that geometry was faithfully extracted (row heights of 40px and 60px, asymmetric column widths), we pass the flag geometry="true".

Additionally, we intentionally pass both title_cell="A1" and title="My Failed Title" flags at the same time. You will be able to see in the compiler log the warning [WARNING] MCW-SPR-001 reporting this collision (where title_cell takes precedence):

Chart 3. Scorecard (Excel)
Top Left Center Middle Bottom Right
Rotated? Merged B3:C3
Source: Stress scorecard (styled_table.xlsx)

LibreOffice (.ods) version:

Chart 4. Scorecard (ODS)
Top Left Center Middle Bottom Right
Rotated? Merged B3:C3
Source: Stress scorecard (styled_table.ods)

9 Grayscale Conversion via LibreOffice (.ods)

For academic reports requiring print or sober color palettes, MarkCharm allows neutralizing loud spreadsheet colors (backgrounds, text, and borders) while preserving the original structure.

Below, we extract the same colorful spreadsheet styled_table and the Magic Square, using the native LibreOffice (.ods) version and activating the grayscale="true" directive. The engine dynamically calculates YIQ luminance to convert all RGB colors seamlessly into grayscale:

Table 11. Grayscale (Excel)
Tabela de Estilos Avançados (Bordas e Cores)
ID Produto Categoria Preço Estoque Status
1 Notebook Eletrônicos 3500 15 Ativo
2 Mouse Gamer RGB 150 50 Ativo
3 Cadeira Ergonomica Móveis 800 0 Esgotado
4 Mesa de Escritório 1200 5 Ativo
5 Teclado Mecânico (Red) Acessórios 300 10 Promoção
6 Monitor Ultrawide (Blue) 2100 2 Limitado
7 Headset Pro (Green) 450 30 Lançamento
Total Geral 8500
Source: Native Excel grayscale spreadsheet (styled_table.xlsx)
Table 12. Grayscale (ODS)
Tabela de Estilos Avançados (Bordas e Cores)
ID Produto Categoria Preço Estoque Status
1 Notebook Eletrônicos 3500 15 Ativo
2 Mouse Gamer RGB 150 50 Ativo
3 Cadeira Ergonomica Móveis 800 0 Esgotado
4 Mesa de Escritório 1200 5 Ativo
5 Teclado Mecânico (Red) Acessórios 300 10 Promoção
6 Monitor Ultrawide (Blue) 2100 2 Limitado
7 Headset Pro (Green) 450 30 Lançamento
Total Geral 8500
Source: Native LibreOffice grayscale spreadsheet (styled_table.ods)
Chart 5. Grayscale Magic Square (Excel)
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Source: Native Excel grayscale magic square (styled_table.xlsx)
Chart 6. Grayscale Magic Square (ODS)
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Source: Native LibreOffice grayscale magic square (styled_table.ods)

10 Caveats and Usage Requirements

Note

When currency is required, a cell with a pure number that lacks active accounting/currency formatting in Excel will be considered invalid. This reinforces visual semantics for the spreadsheet operator.


11 Dynamic Metadata Extraction and Collision Detection

MarkCharm now supports extracting not only the title, but also the Source, Notes, and Observations (Misc) directly from your spreadsheet (both .xlsx and .ods), ensuring that if the value is updated in Excel, the document automatically reflects it.

In the table below, we extract metadata dynamically by pointing to arbitrary cells merely as a proof of concept (e.g. A1 as source). We also trigger an intentional error by declaring title_cell="A1" twice. The compiler will emit the warning [WARNING] MCW-SPR-004: Multiple assignments for attribute 'title_cell'. Additionally, we include static markdown text Source: My Static Source right after the table. The compiler will emit warning MCW-SPR-002 notifying that the spreadsheet's dynamic version (source_cell) won the collision and overwrote the static text!

Excel Version (.xlsx):

Table 13. Collision Detection (Excel)
ID Produto Receita (Esperado Moeda) Qtd (Esperado Num)
1 Cadeira Gamer 1500.5 10 un
2 Mouse R$ 120.00 50
3 R$ 300.00 5
Source: ID
Notes: Produto

LibreOffice Version (.ods):

Table 14. Collision Detection (ODS)
ID Produto Receita (Esperado Moeda) Qtd (Esperado Num)
1 Cadeira Gamer 1500,5 10 un
2 Mouse R$120,00 50
3 R$300,00 5
Source: ID
Notes: Produto