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.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用