diff --git a/examples/financial-report.xlsx b/examples/financial-report.xlsx index 37e8cba..76362f3 100644 Binary files a/examples/financial-report.xlsx and b/examples/financial-report.xlsx differ diff --git a/examples/kitchen-sink.xlsx b/examples/kitchen-sink.xlsx index 0aa2f98..ab85fae 100644 Binary files a/examples/kitchen-sink.xlsx and b/examples/kitchen-sink.xlsx differ diff --git a/examples/playground.xlsx b/examples/playground.xlsx index c89ecb7..42a5b3b 100644 Binary files a/examples/playground.xlsx and b/examples/playground.xlsx differ diff --git a/src/index.ts b/src/index.ts index 152192e..4e52d9b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -192,7 +192,7 @@ export class ExcelBuilder { worksheet[headerCellRef] = createCell({ value: column.label, bordered: params?.bordered ?? true, - style: getColumnHeaderStyle({ bordered: params?.bordered ?? true }), + style: getColumnHeaderStyle({ bordered: params?.bordered ?? true, customStyle: column._ref.headerStyle }), }) tableConfig.content.forEach((row, rowIndex) => { diff --git a/src/types.ts b/src/types.ts index bbc301c..7529f75 100644 --- a/src/types.ts +++ b/src/types.ts @@ -84,6 +84,7 @@ export type Column< default?: CellValue format?: string | ((rowData: T, rowIndex: number, subRowIndex: number) => string) cellStyle?: CellStyle | ((rowData: T, rowIndex: number, subRowIndex: number) => CellStyle) + headerStyle?: CellStyle summary?: Array<{ value: (data: T[]) => BaseCellValue format?: string | ((data: T[]) => string) diff --git a/src/utils.ts b/src/utils.ts index 190bdaf..c8f55ff 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -104,15 +104,18 @@ export function buildSheetConfig(sheets: Array) { })) } -export function getColumnHeaderStyle(params: { bordered: boolean }) { - return { - font: { bold: true }, - alignment: { horizontal: 'center', vertical: 'center' }, - fill: { fgColor: { rgb: 'E9E9E9' } }, - border: (params?.bordered ?? true) - ? THICK_BORDER_STYLE - : {}, - } satisfies CellStyle +export function getColumnHeaderStyle(params: { bordered: boolean, customStyle?: CellStyle }) { + return deepmerge( + { + font: { bold: true }, + alignment: { horizontal: 'center', vertical: 'center' }, + fill: { fgColor: { rgb: 'E9E9E9' } }, + border: (params?.bordered ?? true) + ? THICK_BORDER_STYLE + : {}, + }, + params?.customStyle ?? {}, + ) satisfies CellStyle } export function getWorksheetColumnWidths(worksheet: WorkSheet, extraLength: number = 1) { diff --git a/test/play.test.ts b/test/play.test.ts index 9f8c8d4..110badc 100644 --- a/test/play.test.ts +++ b/test/play.test.ts @@ -9,7 +9,11 @@ describe('should generate the play excel file', () => { // Group definition within the schema const schema = ExcelSchemaBuilder.create() .column('id', { key: 'id' }) - .column('name', { key: 'name' }) + .column('name', { + key: 'name', + cellStyle: { fill: { fgColor: { rgb: 'FFFF00' } } }, + headerStyle: { fill: { fgColor: { rgb: '00FF00' } } }, + }) .build() const users: User[] = Array.from({ length: 100000 }, (_, i) => ({