mk-j / PHP_XLSXWriter

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

Define 2 Header in one Sheed is not possible #326

Closed kueblertgb closed 1 year ago

kueblertgb commented 2 years ago

Hi, i tryed to Create this kind of Excel Sheed

FB | Anzahl 1 | 5 2 | 7


Summe 12

If i try to use the Header Funktion for the first line everything is fine

$header1 = array( 'FB'=>'integer','Anzahl'=>'integer'); $Mappe1 = 'Professoren'; $writer->writeSheetHeader($Mappe1, $header1); Then comes the Data (numers) output At the end of the line i wanted to ad a total (Summe).

$prof_summe = array( 'Summe',$alle_daten_prof_fb_summe[0]['Summe'] ); $writer->writeSheetRow( $Mappe1, $prof_summe);

But this creates an error because 'Summe' is an text Field and it is in the Colum 'FB'. In the head statement i defined the Colum 'FB' as integer.

So try to define a second Head for the $Mappe1 but this creates an other error. There is a solution without the Head statemend but i wanted to us it because of the Filter possibilities.

Dou you have a soulution for me?

ArunShree commented 1 year ago

Creating a header with full length of table (cell merge) above the table header is not possible.This is making the normal table header disappear.Is there any way to work aroung in this issue

ArunShree commented 1 year ago

$header = array(' '=>'string', ' '=>'string'); $styles1 = array('widths'=>[40,40]); $styles2 = array('font'=>'Arial','font-size'=>14); $styles3 = array('font'=>'Arial','font-size'=>10); $writer->writeSheetHeader('Sheet1', $header, $styles1); $writer->writeSheetRow('Sheet1', ['some heading above heading'],$styles2); $writer->markMergedCell('Sheet1', $start_row=0, $start_col=0, $end_row=0, $end_col=2); $writer->writeSheetRow('Sheet1', ['column 1 name','column 2 name'],$styles3);

below this you can put your db render loop or whatever row data you want .The only drawback is , this will leave an empty row at the very top.This is what i did after searching a lot and found noting online. I dont know whether this is a proper way.But it worked for me.

mk-j commented 1 year ago

You should be able to specify multiple calls to writeSheetHeader now on the same sheet (if you use the latest from master). Maybe that will help? $writer->writeSheetHeader($Mappe1, $header1); $writer->writeSheetRow( $Mappe1, $data1); $writer->writeSheetHeader($Mappe1, $header2); $writer->writeSheetRow( $Mappe1, $data2);