使用 PHP 将 XSL 文件呈现为 HTML

Render XSL file to HTML using PHP

我需要读取 excel (xls) 文件并将其呈现到 HTML 页面。

我在 PHP 中使用 Symfony 2.6.5 进行开发,我想访问 excel cel 数据,这样我就可以生成 HTML Symfony 控制器(或更好的模板)。

我正在使用 ExcelBundle 并且我已经阅读了文档,但我发现只有设置信息而不是获取信息的方法。

我们最好看的内容是excel?

PS:excel是表格形式的价目表,如下所示:

+––––+––––––+–––––––––––––+–––––––+
| id | name | description | price |
|____|______|_____________|_______|
+––––+––––––+–––––––––––––+–––––––+
| 1  | foo  | foo desc    | 12€   |
+––––+––––––+–––––––––––––+–––––––+
| 2  | bar  | abr desc    | 65€   |
+––––+––––––+–––––––––––––+–––––––+
|... |...   | ...         | ...   |

code source一致,只需在createPHPExcelObject方法中传递文件名即可。 例如:

public function xlsAction()
{
    $filenames = "your-file-name";
    $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject($filenames);

    foreach ($phpExcelObject ->getWorksheetIterator() as $worksheet) {
        echo 'Worksheet - ' , $worksheet->getTitle();
        foreach ($worksheet->getRowIterator() as $row) {
            echo '    Row number - ' , $row->getRowIndex();
            $cellIterator = $row->getCellIterator();
            $cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
            foreach ($cellIterator as $cell) {
                if (!is_null($cell)) {
                    echo '        Cell - ' , $cell->getCoordinate() , ' - ' , $cell->getCalculatedValue();
                }
            }
    }
    }
}

只需将数组传递给您的视图,以便在模板中呈现。

希望对您有所帮助