0

我正在使用“PhpOffice\PhpSpreadsheet”库处理“导出到 excel”表功能,直到导出到 excel 表工作正常,但我的问题是我有一个总金额列,我必须在其中添加印度货币符号。我寻找解决方案,但还没有运气。

我的代码:

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");

如何将印度货币符号添加到 Excel 工作表中的 total_amount 单元格?希望有人帮忙。谢谢。

4

0 回答 0