Typed-xlsx
Schema Builder

Column Selection

Restricting which columns appear in a given export using include and exclude lists.

The schema itself stays stable. Report variations — which columns appear, which are hidden — are pushed to table-level selection so the same schema definition can serve multiple export shapes.

Include only a subset of columns

import { 
createExcelSchema
,
createWorkbook
} from "@chronicstone/typed-xlsx";
const
schema
=
createExcelSchema
<{
email
: string;
firstName
: string;
lastName
: string }>()
.
column
("firstName", {
accessor
: "firstName" })
.
column
("lastName", {
accessor
: "lastName" })
.
column
("email", {
accessor
: "email" })
.
build
();
const
workbook
=
createWorkbook
();
workbook
.
sheet
("Users").
table
({
rows
: [],
schema
,
select
: {
include
: ["firstName", "email"],
}, });

Exclude a few columns from a wide schema

import { 
createExcelSchema
,
createWorkbook
} from "@chronicstone/typed-xlsx";
const
schema
=
createExcelSchema
<{
email
: string;
firstName
: string;
internalNote
: string }>()
.
column
("firstName", {
accessor
: "firstName" })
.
column
("email", {
accessor
: "email" })
.
column
("internalNote", {
accessor
: "internalNote" })
.
build
();
const
workbook
=
createWorkbook
();
workbook
.
sheet
("Public export").
table
({
rows
: [],
schema
,
select
: {
exclude
: ["internalNote"],
}, });

This pattern makes it easy to define one rich schema and reuse it for several workbook views without cloning column definitions.

Column IDs are statically typed

Both include and exclude only accept IDs that were declared through .column() or .group(). Passing an unknown string is a compile-time error, never a silent runtime no-op.

Hover over SelectableColumns to see the full set of valid IDs for a schema:

import { 
createExcelSchema
} from "@chronicstone/typed-xlsx";
import type {
SchemaColumnId
} from "@chronicstone/typed-xlsx";
const
schema
=
createExcelSchema
<{
email
: string;
firstName
: string;
lastName
: string }>()
.
column
("firstName", {
accessor
: "firstName" })
.
column
("lastName", {
accessor
: "lastName" })
.
column
("email", {
accessor
: "email" })
.
build
();
type
SelectableColumns
=
SchemaColumnId
<typeof
schema
>;

Providing a string outside that set is caught immediately:

import { 
createExcelSchema
,
createWorkbook
} from "@chronicstone/typed-xlsx";
const
schema
=
createExcelSchema
<{
email
: string;
firstName
: string }>()
.
column
("firstName", {
accessor
: "firstName" })
.
column
("email", {
accessor
: "email" })
.
build
();
createWorkbook
()
.
sheet
("Users")
.
table
({
rows
: [],
schema
,
select
: {
include
: ["firstName", "nonExistent"],
Type '"nonExistent"' is not assignable to type 'SchemaSelectableIds<SchemaDefinition<{ email: string; firstName: string; }, "firstName" | "email", never, {}>>'.
}, });
Copyright © 2026 Cyprien Thao. Released under the MIT License.