Column Selection
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 "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("users", {
rows: [],
schema,
select: {
include: ["firstName", "email"],
},
});
Exclude a few columns from a wide schema
import { createExcelSchema, createWorkbook } from "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("public-export", {
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.
Selections can target plain column IDs, structural group IDs from .group(), and dynamic-scope IDs from .dynamic(). See Column Groups and Dynamic Columns.
Column IDs are statically typed
Both include and exclude only accept IDs that were declared through .column(), .group(), or .dynamic(). 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 "typed-xlsx";
import type { SchemaColumnId } from "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 "typed-xlsx";
const schema = createExcelSchema<{ email: string; firstName: string }>()
.column("firstName", { accessor: "firstName" })
.column("email", { accessor: "email" })
.build();
createWorkbook()
.sheet("Users")
.table("users-invalid-selection", {
rows: [],
schema,
select: {
include: ["firstName", "nonExistent"],
},
});