3
votes

Im using the laravel maatwebsite package to export an excel sheet. One column contains euro currency, so im trying to make a currency column for the data.

my code for the columns:

    $sheet->setColumnFormat(array(
        'G' =>  \PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00,
        'H' =>  "[$EUR ]#,##0.00_-",
        'I' =>  \PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE,
    ));

with no luck, when for example 5 (without any decimals) is inserted in one of these columns the data looks like 5 instead of € 5.00

How is the formating set in the correct way?

3

3 Answers

2
votes

You can add to HTML <td>
Example:

<td data-format="$#,##0_-">Price</td>
<td data-format="0.00">Price</td>
<td data-format="0%">Percentage</td>
<td data-format="dd/mm/yy">Date</td>
<td data-format="h:mm:ss AM/PM">Date/Time</td>
0
votes

Hey im not sure about proper method but this is simple trick :P

foreach($jobs  as $index =>$row){
$data=array($index+1,$row->invoice_no,$row->customer_name,'€'.$row->amount);
$sheet->fromArray(array($data),null,'A6',false,false);
  }

$sheet->appendRow(8, array(
           'TOTAL','€'.$sum 
));
0
votes

With the above answer your value will be converted to a string value in Excel. I've used the code snipped below to set the format on a accounting value.

$sheet->setColumnFormat(array(
    'C2' => '[$€-2] * #,##0.00;-[$€-2] * #,##0.00_-;_-[$€-2] * "-"??_-;_-@_-',
));