In my Perl script I use the Spreadsheet::WriteExcel module to create an Excel file. The file contains a table, the size of which is dynamic – i.e., I don’t know how many rows it will have until the table is already created. I would like the last row of the table to have a slightly different format (e.g., its bottom border to be “===”). Unfortunately, I cannot apply this (different) format at the time when the row is being created, since at that time I don’t know yet that it will be the last row.
So, my question is: can I change the format of an already existing cell without changing its contents? If I pass undef as cell value to the $worksheet->write() method it just overwrites the contents of the cell with a blank cell.
The direct answer to your question is that you cannot modify the format of an already written cell in Spreadsheet::WriteExcel. This is a planned feature for Excel::Writer::XLSX but it isn’t in place yet.
So you will need to workaround it in some way such as buffering the table data until you are ready to write it or buffering a row at a time and only writing it when you have a new row.
Or you could turn on compatiblilty_mode() and overwrite the last row with new formatted data. Note, this approach isn’t recommended without compatibility_mode() since Excel will complain about duplicate and or missing data in the file.
Alternatively, setting the row format, as pointed out by @bvr, might work for you.