Skip to content

Commit

Permalink
feat: implement table title custom styling
Browse files Browse the repository at this point in the history
  • Loading branch information
ChronicStone committed Apr 29, 2024
1 parent a0e579b commit 0bfe49a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,12 @@ export class ExcelBuilder<UsedSheetKeys extends string = never> {

const hasTitle = !!tableConfig.title
if (hasTitle) {
const titleStyle = typeof tableConfig.titleStyle === 'function' ? tableConfig.titleStyle(tableConfig.content) : tableConfig.titleStyle ?? {}
tableConfig.columns.forEach((_, colIndex) => {
const titleCellRef = utils.encode_cell({ c: COL_OFFSET + colIndex, r: ROW_OFFSET })
worksheet[titleCellRef] = createCell({
value: colIndex === 0 ? tableConfig.title : '',
style: getColumnHeaderStyle({ bordered: params?.bordered ?? true }),
style: getColumnHeaderStyle({ bordered: params?.bordered ?? true, customStyle: titleStyle }),
extraStyle: {
alignment: { horizontal: 'left' },
fill: { fgColor: { rgb: 'b4c4de' } },
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function buildSheetConfig(sheets: Array<SheetConfig>) {

return {
title: table.title,
titleStyle: table.titleStyle,
content: table.data,
columns,
enableSummary: table.summary ?? true,
Expand Down

0 comments on commit 0bfe49a

Please sign in to comment.