thinkphp - phpExcel为什么导出的表边框只有竖线?
我想大声告诉你
我想大声告诉你 2017-05-16 13:12:29
0
2
720

public function sincewriter($cart,$shopname) {
        $obj = new \PHPExcel();
        $obj->getProperties()->setCreator("JAMES")
            ->setLastModifiedBy("JAMES")
            ->setTitle("zltrans")
            ->setSubject("Dorder")
            ->setDescription("Dorder List")
            ->setKeywords("Dorder")
            ->setCategory("Test result file");

        $obj->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $obj->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objSheet = $obj->getActiveSheet();
        //相关行高
        $n = 'a';
        for ($i = 0; $i < 18; $i++) {
            $obj->getActiveSheet()->getRowDimension($i)->setRowHeight(40);
            $objSheet->getColumnDimension($n++)->setWidth(12);
        }

        $obj->getActiveSheet()->getColumnDimension('B')->setWidth(25);
        $obj->getActiveSheet()->getColumnDimension('F')->setWidth(25);

        //标题
        $obj->getActiveSheet()->mergeCells('A1:H1');

        $obj->getActiveSheet()->getStyle('A1')->getFont()->setSize(14);
        $obj->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);

        $obj->getActiveSheet()->setCellValue("A1", "优菜提货单签收单");


        $obj->getActiveSheet()->mergeCells('A2:D2');
        $obj->getActiveSheet()->setCellValue("A2", "提货站点:" . $shopname);

        $obj->getActiveSheet()->mergeCells('E2:H2');
        $obj->getActiveSheet()->setCellValue("E2", "出货时间:" . date("Y-m-d"));

        $obj->getActiveSheet()->setCellValue("A4", "序号");
        $obj->getActiveSheet()->setCellValue("B4", "订单号");
        $obj->getActiveSheet()->setCellValue("C4", "金额");
        $obj->getActiveSheet()->setCellValue("D4", "提货确定");

        $obj->getActiveSheet()->setCellValue("E4", "序号");
        $obj->getActiveSheet()->setCellValue("F4", "订单号");
        $obj->getActiveSheet()->setCellValue("G4", "金额");
        $obj->getActiveSheet()->setCellValue("H4", "提货确定");

        $len = 5;
        $len2 = 5;

        $count = count($cart);

        foreach ($cart as $key => $vo) {

            if ($key < $count / 2 + 3) {
                $obj->getActiveSheet()->setCellValue("A" . $len, $key + 1);
                $obj->getActiveSheet()->setCellValue("B" . $len, $vo['orderid']);
                $obj->getActiveSheet()->setCellValue("C" . $len, ' ' . $vo['sum']);
                $obj->getActiveSheet()->setCellValue("D" . $len, '');
                $len++;
            } else {
                $obj->getActiveSheet()->setCellValue("E" . $len2, $key + 1);
                $obj->getActiveSheet()->setCellValue("F" . $len2, $vo['orderid']);
                $obj->getActiveSheet()->setCellValue("G" . $len2, ' ' . $vo['sum']);
                $obj->getActiveSheet()->setCellValue("H" . $len2, ' ');
                $len2++;
            }
        }

        $hang = $len;

        $obj->getActiveSheet()->mergeCells('A' . $hang . ':B' . $hang);
        $obj->getActiveSheet()->setCellValue("A" . $hang, '优菜送货员签名送达');
        $obj->getActiveSheet()->mergeCells('C' . $hang . ':D' . $hang);
        $obj->getActiveSheet()->setCellValue("C" . $hang, '');


        $obj->getActiveSheet()->mergeCells('F' . $hang . ':H' . ($hang + 2));

        $hang++;
        $obj->getActiveSheet()->mergeCells('A' . $hang . ':C' . $hang);
        $obj->getActiveSheet()->setCellValue("A" . $hang, '本次物品袋数:');
        $obj->getActiveSheet()->setCellValue('D' . $hang, $count);
        $obj->getActiveSheet()->setCellValue('E' . $hang, '袋');
        $hang++;
        $obj->getActiveSheet()->mergeCells('A' . $hang . ':B' . $hang);
        $obj->getActiveSheet()->setCellValue("A" . $hang, '本次提货点签名签收:');
        $obj->getActiveSheet()->mergeCells('C' . $hang . ':E' . $hang);
        $obj->getActiveSheet()->getStyle('A1:H' . $hang)->getBorders()->getAllBorders()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
        $name = time();
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $name . '.xls"');
        header('Cache-Control: max-age=0');
        $objWriter = \PHPExcel_IOFactory::createWriter($obj, 'Excel5');
        $objWriter->save('php://output');
    }

这一句是边框

 $obj->getActiveSheet()->getStyle('A1:H' . $hang)->getBorders()->getAllBorders()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
我想大声告诉你
我想大声告诉你

répondre à tous(2)
东云奇侠

Il ne semble y avoir aucun problème avec le code. Il peut s'agir d'un problème avec la version Excel de sortie. Vous pouvez utiliser : $objWriter = PHPExcel_IOFactory::createWriter($obj, 'Excel2007');

En plus : c'est mieux. à ajouter : ob_end_clean(); avant la sortie //Effacez le tampon pour éviter les caractères tronqués

Manuel de référence chinois :https://www.kancloud.cn/jingyifeng/phpexcel/363084


滿天的星座

Essayez de le remplacer par ce code :

$styleArray = array(
    'borders' => array(                                                                                                                                         
        'allborders' => array(                                                                                                                                  
            'style' => PHPExcel_Style_Border::BORDER_THIN                                                                                                       
        )
     )                                                                                                                                                       );
$obj->getActiveSheet()->getStyle('A1:H' . $hang)->applyFromArray($styleArray);     
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!