mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 664 forks source link

BUG: (oversight) writeSheetHeader function can't handle duplicate captions #251

Closed AzzaAzza69 closed 1 year ago

AzzaAzza69 commented 4 years ago

As "headings" are cells just like data - they should be able to contain duplicated text!

eg. $aCols=[]; $aCols['column']='@'; $aCols['column']='@'; // durh ; obviously $aCols['column']='@'; // durh ; obviously $aData=['data','data','data']; $o=new XLSXWriter(); $o->writeSheetHeader('sheet', $aCols); $o->writeSheetRow('sheet', $aData); $o->writeToFile('../public/test.xlsx');

Maybe a new function that uses the array without keys, eg. $aCols=[]; $aCols[]=['title'=>'column', 'format'=>'@']; $aCols[]=['title'=>'column', 'format'=>'@']; $aCols[]=['title'=>'column', 'format'=>'@']; $aData=['data','data','data']; $o=new XLSXWriter(); $o->writeSheetHeadings('sheet', $aCols); $o->writeSheetRow('sheet', $aData); $o->writeToFile('../public/test.xlsx');

seattledeveloper commented 4 years ago

FYI, you might also look at Pull Request #250 which also discusses this issue. I like your solution as an array without keys ... and the current function could auto-detect which format of the array is being sent in, for complete backwards compatibility.

AzzaAzza69 commented 4 years ago

I see a future problem in that any more options are going to require more parameters...whereas extra keys can be added to the array as the functionality increases... It is already harder to follow with the column widths defined as a completely separate array to the header captions & types.

mk-j commented 1 year ago

$writer->writeSheetHeader('Sheet1', $header1);
$writer->writeSheetRow('Sheet1', $row1 );
$writer->writeSheetHeader('Sheet1', $header2);
$writer->writeSheetRow('Sheet1', $row2);
``` this works now.
momala454 commented 2 months ago

sorry but I don't understand how writing two times the header will allow to have multiple headers with the same value on a single row ?