duandan1995 2017-07-28 10:33
浏览 526
已采纳

PHPOffice / PHPExcel PHPExcel_Style_NumberFormat FORMAT_CURRENCY_USD_SIMPLE使用它的正确方法。

I am trying to use FORMAT_CURRENCY_USD_SIMPLE .

I am able to use dates, integer and general succefully. But i am having problem with this.

My Cell content can be like this.

enter image description here

Here you can see, I am using "$75.00" is my cell content. I am putting $ as my cell content as I get this data from my query.

Is CONTENT of CELL value we put in setCellValueByColumnAndRow should be without "$" or with "$". I have tried it with "$".

DOCUMENTS

I have not tried without "$".

So what will be the correct CONTENT and what will be the correct format code.

I have used "FORMAT_CURRENCY_USD_SIMPLE" , "FORMAT_CURRENCY_USD" , '"$"#,##0.00_-' ( directly ) , '$#,##0_-' ( right now ).

My all currencny number will be like $1,356.25. If you follow this structure.

Which format code should i use for content value like this.

My code , It works with date and numbers.

$areaOfExcel = $column_alphabet.$row_start_data.":".$column_alphabet.$excel_current_row_index ;
$this->excel_active_sheet->getStyle( $areaOfExcel )
                ->getNumberFormat()
                ->setFormatCode( $dataTypeFromAdoDb );

My main concern is what should be correct format code or what should be correct content. to use $ sign and format them properly.

  • 写回答

1条回答 默认 最新

  • dqy006150 2017-07-28 10:36
    关注

    The content value in the cell should be a simple floating point number, with no currency code, no thousands separator, etc..... exactly as it should be in MS Excel itself if you want to use a currency format number mask.

    $value = 1234.56; // float value
    
    $objPHPExcel->getActiveSheet()
        ->setCellValue('A1', $value);
    $objPHPExcel->getActiveSheet()
        ->getStyle('A1')
        ->getNumberFormat()
        ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler