Skip to main content
Topic: customize excel output file (Read 1705 times) previous topic - next topic

customize excel output file

hi,
is there a way to customize the excel output file like column size, bold header etc. ?
and where can that be done ?
tx, brienen

Re: customize excel output file

Reply #1
@brienen‍ please use an excel editor to edit the exported excel file, if you still want to edit it from code I can point you to where you can find the code that handles that. You can find it in /helpers/Functions.php on line 55 to 69.

Re: customize excel output file

Reply #2
Tx Willvin,
Sorry, but I was looking for the xls output and not the csv output.
Anyway I found it where to change , in the libs dir the file XLSXWriter.php contains the settings for the xls output:

In the writeSheetHeader function

line 223:
      $col_widths = isset($col_options['widths']) ? (array)$col_options['widths'] : array();
change to an array with the different column widths :
      $col_widths = isset($col_options['widths']) ? (array)$col_options['widths'] : array(10,20,25,25,25,11,25,25,25,11,25,9,50,10);

line 225:
      $freeze_rows = isset($col_options['freeze_rows']) ? intval($col_options['freeze_rows']) : true;
change the first row to frozen : true

line 236, add one line with the style settings for the header :
            $style = array( 'font'=>'Tahoma','font-size'=>10,'font-style'=>'bold','fill'=>'#eee','halign'=>'center','border'=>'left,right,top,bottom');

The docs of this class are very well explained and supported here :

https://github.com/mk-j/PHP_XLSXWriter/blob/master/xlsxwriter.class.php


Re: customize excel output file

Reply #3
I added some lines in the  XLSXWriter.php file , when you have more than one excel output file and ofcourse the columns have diferent sizes, so used the switch case, to switch depending on the $sheet_name variable.
Below the changes in the writeSheetHeader function :

   switch ($sheet_name) {

      case 'Tareas':
         $col_widths = isset($col_options['widths']) ? (array)$col_options['widths'] : array(10,20,25,25,25,11,25,25,25,11,25,9,50,10);
      break;

      case 'Ingresos':
         $col_widths = isset($col_options['widths']) ? (array)$col_options['widths'] : array(15,10,13,17,12,11,25,22,15,50);
      break;

      case 'Salidas':
         $col_widths = isset($col_options['widths']) ? (array)$col_options['widths'] : array(14,10,13,13,25,25,12,28,22,11,13,13,50);
      break;
   }