dtjohnson / xlsx-populate

Excel XLSX parser/generator written in JavaScript with Node.js and browser support, jQuery/d3-style method chaining, encryption, and a focus on keeping existing workbook features and styles in tact.
MIT License
957 stars 183 forks source link

[h]:mm number formatting not applied #279

Closed RW-DiefBell closed 4 years ago

RW-DiefBell commented 4 years ago

I'm attempting to populate an existing spreadsheet where some of the columns are already formatted as being for "[h]:mm" number format, however the actual formatting is not applied. For it to work, you have to open the spreadsheet, open the cell, then exit it again for the formatting to be applied. This obviously isn't workable for spreadsheets with thousands of rows...

I've also tried to set the formatting in my code using style("numberFormat", "[h]:mm");, but this also does not work (and also removes the original styling). Is there something I'm doing wrong or is this a missing feature/bug?

Many thanks

RW-DiefBell commented 4 years ago

I've found that the way to do this is set the value using Date. To get only the hours/minutes component I've used cell.value(new Date(0, 0, 0, 11, 52, 0); for getting 11:52.

Note that this still isn't getting around this issue of it overriding the initial styling.