3

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?

Sven van den Boogaart
  • 11,833
  • 21
  • 86
  • 169

3 Answers3

4

You can add data-format attribute to<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>
Davron Achilov
  • 536
  • 4
  • 14
0

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 
));
Hamelraj
  • 4,676
  • 4
  • 19
  • 42
0

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] * "-"??_-;_-@_-',
));
D. J.
  • 684
  • 6
  • 25