• [学习]PHP EXCEL 同时导出图片


    http://www.360doc.com/content/15/1216/17/8896401_520869856.shtml

    include '/phpexcel/PHPExcel.php';
        $excel = new PHPExcel();
        $objDrawing = new PHPExcel_Worksheet_Drawing();
        
       
        $excel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $excel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objActSheet = $excel->getActiveSheet();

        $letter = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N');
       
        $tableheader = array('姓名', '性别', '年龄', '班级', '头像');
       
        for($i = 0;$i < count($tableheader);$i++) {
            $excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
        }

       
        $data = array(
            array('小王', '男', '20', 'CS12', 'test.jpg'),
            array('小李', '女', '21', 'CS12', 'test.jpg'),
            array('小周', '男', '22', 'CS12', 'test.jpg'),
            array('小赵', '女', '23', 'CS12', 'test.jpg'),
            array('小张', '男', '24', 'CS12', 'test.jpg')
        );

       
        for ($i = 0;$i < count($data);$i++) {
            $j = $i + 2;
           
            $objActSheet->getColumnDimension("$letter[$i]")->setWidth(20);
           
            $excel->getActiveSheet()->getRowDimension($j)->setRowHeight(100);
           
            for ($row = 0;$row < count($data[$i]);$row++) {
                if ($row == (count($data[$i]) -1 )) {
                   
                    $objDrawing = new PHPExcel_Worksheet_Drawing();
                   
                    $objDrawing->setPath($data[$i][$row]);
                   
                    $objDrawing->setHeight(100);
                   
                    $objDrawing->setCoordinates("$letter[$row]$j");
                   
                    $objDrawing->setOffsetX(80);
                    $objDrawing->setRotation(20);
                    $objDrawing->getShadow()->setVisible(true);
                    $objDrawing->getShadow()->setDirection(50);
                    $objDrawing->setWorksheet($excel->getActiveSheet());
                    continue;
                }
                $excel->getActiveSheet()->setCellValue("$letter[$row]$j","111");
            }
        }

        $write = new PHPExcel_Writer_Excel5($excel);
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");;
        header('Content-Disposition:attachment;filename="测试文件.xls"');
        header("Content-Transfer-Encoding:binary");
        $write->save('php://output');
  • 相关阅读:
    picturebox 图片自适应
    C#中如何生成矢量图
    测试ODBC与OLE
    ODBC具体使用
    C#中的OLEDB连接2
    C#中的ODBC、OLEDB连接
    c#执行并行任务之Parallel与TaskFactory
    C# 4.0 新特性之并行运算(Parallel)
    app的下载中心
    第三方库列表
  • 原文地址:https://www.cnblogs.com/linewman/p/9918812.html
Copyright © 2020-2023  润新知