如何使用symfony2读取Excel文件? [英] How can I read Excel files with symfony2?

查看:113
本文介绍了如何使用symfony2读取Excel文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用PhpExcel库安装了Excelbundle.我想阅读我发现此功能的Excel文件.

I installed Excelbundle with PhpExcel library. I want to read excel files I found this function.

如何使用?有什么建议吗?

How can I use it? Any suggestion?

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();
                    }
                }
        }
    }
}

推荐答案

我的建议是阅读文档"并开始对其进行黑客攻击.根据我的经验,与excel合作非常复杂且耗时,因此不要指望其他人在线解决您的问题.

My suggestion is "Read the documentation" and start hacking at it. Working with excel is, in my experience, quite complex and time consuming so don't expect other people to solve your problem online.

似乎您在谈论此捆绑包: https://github.com/liuggio/ExcelBundle

It seems like you're talking about this bundle: https://github.com/liuggio/ExcelBundle

它具有出色的文档,甚至有完整的示例(请参阅伪控制器").

It has great documentation, even full examples (see "Fake Controller").

这篇关于如何使用symfony2读取Excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆