r

rexllent

@preview

Parsing xlsx file into a typst table, powered by wasm.

v0.4.1
MIT

🦖 ReXLlenT

Universe badge GitHub repository badge Test workflow badge

ReXLlenT is a typst package that helps you:

  • Convert Excel xlsx tables to typst tables, powered by wasm.
  • Convert Spreet parsed tables to typst tables. (Supports excel/opendocument spreadsheets but doesn't support parsing styles or merge cells.)

Usage

Start by importing the package:

#import "@preview/rexllent:0.4.1": xlsx-parser

Then you can use xlsx-parser function to convert your xlsx Excel table to typst table. Here is an example:

#xlsx-parser(read("test.xlsx", encoding: none))

By passing sheet-index parameter, you can specify the sheet index to parse. The default value is 0.

#xlsx-parser(read("test.xlsx", encoding: none), sheet-index: 1)

You can also select specific columns to parse:

#xlsx-parser(read("test.xlsx", encoding: none), selected-cols: "A,C,F")

By toggling parameters below, you can customize the output table:

  • selected-cols: Comma-separated list of columns to include (for example: "A,C,F"). You can also pass an array like ("A", "C", "F").
  • parse-table-style: Parse table style(columns width, rows height), default is true.
  • parse-alignment: Parse cell content alignment, default is true.
  • parse-stroke: Parse cell stroke, default is true.
  • parse-fill: Parse cell fill, default is true.
  • parse-font: Parse font style, default is true.
  • parse-header: Parse header row, default is false.
  • parse-formatted-cell: Parse formatted cell, default is false. Notice that this will cause great performance loss so don't use it unless you need it.
  • eval-as-markup: Evaluate cell content as typst markup, default is false.

Notice that 0pt height or 0pt width will be parsed as auto. Disable parse-table-style to prevent this behavior and set the width and height manually.

Extra arguments passed to xlsx-parser function will be passed to table. Feel free to customize the output table. For the prepend elements(for example: header, hline) you should pass them as array to prepend-elems parameter.

#xlsx-parser(
  read("test.xlsx", encoding: none),
  parse-header: true,
  parse-stroke: false,
  prepend-elems: (table.hline()),
  stroke: (_, y) => {
    if y == 0 {
      return (bottom: black)
    }
  },
  table.hline(),
)

three-line-table

Work with Spreet

You can also convert Spreet parsed tables to typst tables. Here is an example:

#import "@preview/spreet:0.1.0"
#import "@preview/rexllent:0.4.1": spreet-parser

#spreet-parser(spreet.decode(read("/tests/data/default.ods", encoding: none)))

By passing sheet-index parameter, you can specify the sheet index to parse. The default value is 0. The extra arguments passed to spreet-parser function will be passed to table.

Through this way, you can convert excel/opendocument spreadsheets to typst tables. However, the styles and merge cells will not be parsed due to the limitation of calamine.

Example

  • Excel Table

    Excel

  • Typst Table (with default parameters)

    Typst

  • Typst Table (with parse-table-style: false)

    Typst

  • Typst Table (with parse-alignment: false)

    Typst table with alignment disabled

  • Typst Table (with parse-stroke: false)

    Typst table with stroke disabled

  • Typst Table (with parse-fill: false)

    Typst table with fill disabled

  • Typst Table (with parse-font: false)

    Typst table with font styling disabled

  • With Custom Style

    Typst table with custom styling

Pixel Art

You can also convert pixel art to typst table using ReXLlenT. Here are some examples:

  • Typst Logo

    Typst logo rendered as a table

  • Typst Guy

    Typst Guy rendered as a table

  • Impression, soleil levant

    Monet's Impression, soleil levant rendered as a table

TODOs

ReXLlenT is still in development and PRs are welcome. Here are some TODOs (also limitations):

  • Implement in-cell image parsing.
  • Prevent parsing errors caused by special characters.
  • Parse auto width and height instead of treating 0pt as auto.
  • Handle hidden rows and columns.
  • ...

Credits

License

This package is licensed under the MIT License.

Star History

Star History Chart

Version History

0.4.1
fb879790f808...
0.4.0
97c68127a187...
0.3.4
2deb41c2dad0...
0.3.3
81594e3a8a26...
0.3.2
abfc585d3eee...
0.3.1
7cc6a9280963...
0.3.0
fb1729489472...
0.2.3
f3ff2667d80b...
0.2.2
aa4214799964...
0.2.1
f908124fd5bc...
0.2.0
07a01eafd542...