Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to format a columns header definition to be a date format. #2740

Open
danharten-sovtech opened this issue Apr 10, 2024 · 1 comment
Open

Comments

@danharten-sovtech
Copy link

馃悰 Bug Report

Unable to format a columns header definition to be in date format. I can format it to a string that looks like a date, for example yyyy/mm/dd however, the cell type is a string and not a date so I cannot use the exported excel sheet as needed. My use case is creating pivot tables amongst other things based on the date that column is for.

Lib version: latest

Steps To Reproduce

const datedColumns = ['2024/02/02']

  1. Create a workbook
  2. Assign a column [{ header: '2024/02/02', key: '2024/02/02', width: 32 }] with worksheet.columns = columns;
  3. Add a row [{ '2024/02/02': "Dummy Test" }]
    rows.forEach(async (row) => {
      worksheet.addRow(row);
    });
  1. Attempt to format cells to date format
    dateColumns.forEach((column) => {
    // try 1
      worksheet.getRow(1).getCell(column).style = { numFmt: 'yyyy/mm/dd' };
    // try 2
      worksheet.getRow(1).numFmt = 'yyyy/mm/dd';
    // try 3, this formats the data in the rows below the column header to be dates
      worksheet.getColumn(column).numFmt = 'yyyy/mm/dd';
    });

I've also tried defining the format on the column definition like so:

``[{ header: '2024/02/02', key: '2024/02/02', width: 32, style: { numFmt: 'yyyy/dd/mm' } }]`

The expected behaviour:

I expect the resulting cell in my export to be formatted as a date cell, this would make the data in the cell right aligned too.

Possible solution (optional, but very helpful):

enable column header formatting

@danharten-sovtech
Copy link
Author

To add further:

I am able to format the dates in the subsequent rows to be the correct date format and display right aligned. However, not in the column headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant