我想使用 php 导入和查看 excel 文件,所以我找到了一个库类 php-excel-reader
当我们使用 php 时,我们只是在页面中包含文件include("nameoffile.php");
我不知道如何使用 symfony 做到这一点。我应该在哪里进口?怎么做?`
我想使用 php 导入和查看 excel 文件,所以我找到了一个库类 php-excel-reader
当我们使用 php 时,我们只是在页面中包含文件include("nameoffile.php");
我不知道如何使用 symfony 做到这一点。我应该在哪里进口?怎么做?`
这是针对 PHPExcel 而不是读者的,但原理是相同的。无需实际包含文件。它们可以自动加载。
添加到您的 autoload.php:
$loader->registerPrefixes(array(
'Twig_Extensions_' => $ws.'Symfony/vendor/twig-extensions/lib',
'Twig_' => $ws.'Symfony/vendor/twig/lib',
'Zend_' => $ws.'ZendFramework-1.11.11/library',
'PHPExcel' => $ws.'PHPExcel/Classes' // Change to support the reader
));
之后,您可以执行以下操作:
$reader = new \Spreadsheet_Reader();
请注意,处理非命名空间库需要前导斜杠。
我通过使用服务稍微抽象了一些东西:
/* ==================================================
* Wrap interface to the excel spreasheet processing
*/
namespace Zayso\CoreBundle\Component\Format;
class Excel
{
public function newSpreadSheet()
{
return new \PHPExcel();
}
public function newWriter($ss)
{
return \PHPExcel_IOFactory::createWriter($ss, 'Excel5');
}
public function load($file)
{
return \PHPExcel_IOFactory::load($file);
}
}
您可以创建需要文件的服务。您在官方文档中有一个示例。