在phpexcel

时间:2017-06-09 15:12:07

标签: php phpexcel

如何在html中从phpexcel视图表中添加rowspan / colspan?

我有这张桌子。

A2 cell merged with A1

我想使用PHPexcel View在html中查看excel 但我得到的就是,

Not merge

第一列未与第二列合并。

有谁知道如何在html中的phpexcel视图中添加rowspan?

我的代码就像这样

 $tmpfname = "./sampleData/member.xls";

    $excelObj = $excelReader->load($tmpfname);
    $worksheet = $excelObj->getActiveSheet();
    $worksheet->mergeCells('A1:A3');
    $cell = $worksheet->getCell('A1');
    $lastRow = $worksheet->getHighestRow();


    echo '<table border="1"  >';
    for ($row = 1; $row <= $lastRow; $row++) {

         echo "<tr><td>";
         echo $worksheet->getCell('A'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('B'.$row)->getValue();
         echo "</td><td>";
          echo $worksheet->getCell('C'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('D'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('E'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('F'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('G'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('J'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('K'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('L'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('M'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('N'.$row)->getValue();
         echo "</td><td>";
         echo $worksheet->getCell('O'.$row)->getValue();
         echo "</td><tr>";
    }
    echo "</table>";    

1 个答案:

答案 0 :(得分:1)

可能您可以使用createWriter从phpExcelObject创建HTML表。

$objWriter = $this->get('phpexcel')->createWriter($phpExcelObject, 'HTML');
ob_start();
$objWriter->save('php://output');
$excelOutput = ob_get_clean();

echo $excelOutput;