ChronicStone/typed-xlsx

titleStyle are not applied and cellStyle fill attribute seems broken

hixus opened this issue · 3 comments

Types have titleStyle attribute but looking the code it's not used anywhere. Also fill seems to always make cell background black.

CleanShot 2024-04-29 at 07 23 48

  const schema = ExcelSchemaBuilder.create<User>()
    .column("ID", { key: "id" })
    .column("NAME", {
      key: "name",
      cellStyle: {
        font: { bold: false, italic: true, color: { rgb: "FF0000" } },
        fill: { bgColor: { rgb: "61eb34" } },
      },
    })
    .column("Email", { key: "email" })
    .build();

  const users: User[] = [
    {
      id: 1,
      name: "JOHN Doe",
      email: "john@foo.com",
    },
  ];

  const excelFile1 = ExcelBuilder.create()
    .sheet("Sheet1")
    .addTable({
      data: users,
      schema,
      titleStyle: {
        font: { bold: false, italic: true },
        fill: { bgColor: { rgb: "FF0000" } },
      },
    })
    .build({ output: "buffer", bordered: false });

Hi @hixus, titleStyle is effectively not being used, but it's meant to style the table-level title, not the column headers. That feature is missing, I'll add it today.

For cell background styling, this is a bit counterintuitive, but you need to use the "fgColor" prop instead of "bgColor".
Typed-xlsx uses xlsx-js-style underneath, a fork of sheetjs with free cell styling support. You can have a look at the styling API there :

https://www.npmjs.com/package/xlsx-js-style

@hixus Released v0.2.13. Columns now have a headerStyle property giving you control column headers styling. titleStyle will be addressed on v0.2.14, I want to finish implement formatting presets first (kinda like transformers but for cell formatting).

I'll let you close the issue if all your questions are answered. If not, feel free to ask anything.

@hixus I just released v0.2.14, which also fix titleStyle not being implemented. titleStyle will apply styles to the table title, if one is configured.