I am working on "export to excel" sheet functionality using "PhpOffice\PhpSpreadsheet" library, till export to excel sheet working fine but My Problem here is that I have a total amount column where I have to add Indian currency symbol. I searched for a solution but no luck yet.
My Code:
require_once('../vendor/autoload.php');
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$objPHPSpreadSheet = new Spreadsheet();
$sheet = $objPHPSpreadSheet->getActiveSheet();
$results=getsalesReport($data);
$sheet->setCellValue('A1', 'title1');
$sheet->setCellValue('B1', 'title2');
$sheet->setCellValue('C1', 'title3');
$rowCount = 2;
if(isset($results) && !empty($results)){
foreach ($results as $key => $val) {
$total_amount = '₹'.$val['TotalAmount']; // I added '₹' for INR currency symbol, its working fine in HTML
$sheet->setCellValue('A'.$rowCount, $val['my_val1']);
$sheet->setCellValue('B'.$rowCount, $val['my_val2']);
$sheet->setCellValue('C'.$rowCount, $total_amount);
$rowCount++;
}
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename=sales_report.xlsx');
header('Cache-Control: max-age=0');
$writer = new Xlsx($objPHPSpreadSheet);
$writer->save("php://output");
How to add Indian currency symbol to total_amount cell in Excel sheet? Hope someone helps. Thanks.