douyan0732 2015-01-15 09:49
浏览 34

PHPExcel不会将变量带入单元格

I am trying to get variables into a PHPExcel file.

When I open the page without variables it shows me an excellent Excel document. Once I add the variables into the cells, the excel sheet turns white and returns nothing. I know it is possible to call variables into ExcelSheets, I have no clue why it is not working.

Code:

// Add Data in your file
            foreach ($response as $key => $value) {
            $timestamp = substr($value['timestamp'], 6, 10);
            $timestamp = date('d-m-Y H:i:s', $timestamp);     

 //Table
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('B2', 'Beller ')
            ->setCellValue('D2', 'Beller nummer')
            ->setCellValue('F2', 'Datum')
            ->setCellValue('H2', 'ontvanger naam')
            ->setCellValue('J2', 'ontvanger nummer')
            ->setCellValue('L2', 'Billing seconds')
            ->setCellValue('N2', 'Direction')
// array 

            ->setCellValue('B3', $value ['caller_id_name'])
            ->setCellValue('D3', $value ['caller_id_number'])
            ->setCellValue('F3', $timestamp)
            ->setCellValue('H3', $value ['callee_id_name'])
            ->setCellValue('J3', $value ['callee_id_number'])
            ->setCellValue('L3', $value ['billing_seconds'])
            ->setCellValue('N3', $value ['direction']);         

                }

To clarify the situation: when I use the variables it returns an empty excel sheet (white screen).

When I try it without variables it returns me exactly what I want, but I want that this also work with my variable.

// Add Data in your file
            //Werkt niet            foreach ($response as $key => $value) {
            //Werkt niet            $timestamp = substr($value['timestamp'], 6, 10);
            //werkt niet            $timestamp = date('d-m-Y H:i:s', $timestamp);     

 //Table
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('B2', 'Beller ')
            ->setCellValue('D2', 'Beller nummer')
            ->setCellValue('F2', 'Datum')
            ->setCellValue('H2', 'ontvanger naam')
            ->setCellValue('J2', 'ontvanger nummer')
            ->setCellValue('L2', 'Billing seconds')
            ->setCellValue('N2', 'Direction')
// array 

            ->setCellValue('B3', 'hi')
            ->setCellValue('D3', 'hi')
            ->setCellValue('F3', 'hi')
            ->setCellValue('H3', 'hi')
            ->setCellValue('J3', 'ontvanger nummer')
            ->setCellValue('L3', 'Billing seconds')
            ->setCellValue('N3', 'Direction');          

            //Werkt niet            }
  • 写回答

1条回答 默认 最新

  • dshakcsq64956 2015-01-29 11:02
    关注

    I had almost the same issue. (I tried to put data from MySQL table into Excell sheet, but it could not worked) so I found that the setCellValue accepts only UTF-8 strings. And Tthat is solved my problem. So I suggest you to use the utf8_encode function like:

    ->setCellValue('B3', utf8_encode( $value ['caller_id_name'] ) )
    

    P.

    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?