I'm working with PHP_XLSXWriter for one of my projects and running into a problem I don't seem to be able to resolve; mixed formats.
I need to produce an Excel file from my database tables, together with a header row that's all text. The data after the header row is of the format 'integer','number','text'. I already have a perfectly working script that pulls information out of database, then writes it into an XLSX file before sending the file to the user's browser. At the top of this file is the following:
$header = array("string","string","string");
$writer->writeSheetHeader($sheet_name, $header, $col_options = ['widths'=>[20,20,50], 'suppress_row'=>true] );
This all works flawlessly and my file opens in Excel. However, all my data is in the Excel 'text' format; the header row and the data rows. That's obviously because I'm declaring the three columns to be formatted as 'string', but if I change that line to:
$header = array("integer","#0.00","string");
$writer->writeSheetHeader($sheet_name, $header, $col_options = ['widths'=>[20,20,50], 'suppress_row'=>true] );
Then the final Excel alerts the user to a problem in the file as it's being opened and offers to repair the file. That works, and the header is all text and the data all the correct format, but it's messy and unprofessional from the user's perspective.
It's clear that this problem arises because the header row does not contain integers or numbers and I'm trying to force the formatting of the entire columns, but how to get around this? I've spent a long time search the help files and online forums but can't find anything that clearly tells me how to mix my formats in PHP_XLSXWriter.
Has anyone else managed to solve this problem and, if so, how?