dongya1228 2014-04-03 06:16
浏览 65
已采纳

phpexcel导出到图像优秀

I have a table in my Database containing the data of many items with the name of its image.

From that table I want to display each item data with its image. This is the code I use to display it in PHP:

<table>
<thead>
  <tr>
    <th style="border-width:medium;" rowspan="2">CODE</th>
    <th style="border:medium;" rowspan="2">CLR</th>
    <th style="border-width:medium;" rowspan="2">IMAGE</th>
    <th style="border-width:medium;" rowspan="2">DESCRIPTION</th>
    <th style="border-width:medium;" rowspan="2">QTY.</th>
    <th style="border-width:medium;" rowspan="2">PRICE</th>
  </tr>
</thead>
<tbody>
<?php foreach($list as $data){?>
  <tr>
    <td><?=$data->code_caption?></td>
    <td style="text-align:center"><?=$data->color?></td>
    <td style="width:135px; height:135px; text-align:center;">
    <img src="<?=base_url().'media/img/gallery/items/'.$data->image?>TH.jpg" style="margin:5px; text-align:center; vertical-align:middle;" />
    </td>
    <td><?=$data->desc?></td>
    <td style="text-align:center"><?=$data->qty?></td>
    <td style="text-align:right"><?=$data->price?></td>
  </tr>
<?php }?>
</tbody>
</table>

I want to export the data to an Excel formatted file so it looks like what I display on my PHP page.

Can it be done?

I have tried to use the Excel header but the image becomes a link, it's not the complete image being embedded.

And I also saw the PHPexcel library, but I cannot find a way to write the loop with the image.

Any solution for my problem will be very helpful.

  • 写回答

1条回答 默认 最新

  • doushan6161 2014-05-17 06:21
    关注

    Thanks for Helping me I have found the answer for my own question.

        <?php
    
        $rowNumber = 12;
        foreach($list as $data){
    $this->excel->getActiveSheet()->setCellValue('A'.$rowNumber, $data->code_caption)
    ->setCellValue('B'.$rowNumber, $data->color);
    
    if(file_exists('./media/img/gallery/items/'.$data->image.'TH.jpg'))
    {
        $objDrawing = new PHPExcel_Worksheet_Drawing();
        $objDrawing->setPath('./media/img/gallery/items/'.$data->image.'TH.jpg');
        $objDrawing->setCoordinates('C'.$rowNumber);
        $objDrawing->setWorksheet($this->excel->getActiveSheet());
        $this->excel->getActiveSheet()->getRowDimension($rowNumber)->setRowHeight(120);
    }
    else
    {
        $this->excel->getActiveSheet()->setCellValue('C'.$rowNumber, '');
    }
    
    $this->excel->getActiveSheet()->setCellValue('D'.$rowNumber, $data->desc);
    $this->excel->getActiveSheet()->setCellValue('E'.$rowNumber, $data->$d_met);
    $this->excel->getActiveSheet()->setCellValue('F'.$rowNumber, $data->$w_met);
    $this->excel->getActiveSheet()->setCellValue('G'.$rowNumber, $data->$h_met);
    $this->excel->getActiveSheet()->setCellValue('H'.$rowNumber, $data->qty);
    $this->excel->getActiveSheet()->setCellValue('I'.$rowNumber,$data->$cur_dat);           
    $this->excel->getActiveSheet()->setCellValue('J'.$rowNumber,$data->$total_price);
    $rowNumber++;
        }?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题