PHPExcel打印数组结果以HTML表格形式显示在视图中 [英] PHPExcel print array result as HTML table in view

查看:47
本文介绍了PHPExcel打印数组结果以HTML表格形式显示在视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPExcel和CodeIgniter制作应用程序.我有用于Excel处理的模型:

I'm using PHPExcel and CodeIgniter to make an application. I have my Model for Excel treatment:

class modelExcel extends CI_Model
{
  protected $excel;

  function __construct() {
    parent::__construct();
    $this->load->library('Excel');
  }

  function readReport() { //Função para retorno dos dados do arquivo Excel
    $this->excel = PHPExcel_IOFactory::load(APPPATH."/exceldata/wf.xlsx");

    //Seleciona a planilha ativa
    $objWorksheet = $this->excel->getActiveSheet()->rangeToArray('D7:J7');

    return $objWorksheet;
  }
}

我的主页控制器,我在其中获取所有数据并发送到视图:

My Main Page Controller where I get all the data and send to a view:

public function index() {
        if($this->session->userdata('logged')) {
            $this->load->model('ModelExcel');
            $data['excel'] = $this->ModelExcel->readReport();
            $sessionData = $this->session->userdata('logged');
            $data['username'] = $sessionData['userName'];
            $this->load->view('template/header', $data);
            $this->load->view('home');
            $this->load->view('template/footer');   
        }

最后是我的View(具有更多代码,但这正是我要打印表格的位置):

And finally my View (have more code, but here's exactly where I want to print the table):

<div class="row"> 
   <div class="col-md-6">
        <?=$excel?>
    </div>
</div>

这样做完全正确,我得到了数组到字符串转换的错误.还有其他方法可以打印excel特定的列和行吗?

Doing exactly as this are, I got an error of array to string conversion. Have some another way to print excel specific columns and rows?

推荐答案

解决了"foreach"问题.这是最终的代码:

Solved with "foreach". Here's the final code:

foreach ($excelData as $dataArray) {
            foreach ($dataArray as $dataValue) {
                echo $dataValue;
            }
        }

这篇关于PHPExcel打印数组结果以HTML表格形式显示在视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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