teamoping 2016-09-12 10:03:06 13606次浏览 9条评论 18 6 0

1.网上下载一个PHPExcel.php 百度很多
2.
控制器 controller

set_time_limit(0);
require dirname(dirname(__FILE__)) . '../../common/comp/excel/PHPExcel.php'; //更改为你的phpexcel文件地址     
$filePath =>Yii::$app->request->post('path')
// Create new PHPExcel object
$objReader =new \PHPExcel_Reader_Excel5();
//$objReader =new \PHPExcel_Reader_Excel2007();
$objWriteHtml=new \PHPExcel_Writer_HTML($objReader->load($filePath));
echo $objWriteHtml->save("php://output");

view 页面我只简单写

<?php
use yii\web\View;
use yii\helpers\Html;
$this->registerJsFile(Yii::$app->request->baseUrl . '/resources/js/jquery.min.js', ['position' => View::POS_HEAD]);
$this->registerJS("
    //预览
    $('.data_table').on('click', '.preview_icon', function(){
        $('#fileIframe').attr('src',$(this).attr('url'));
        $('.quotation_iframe_bg,.quotation_iframe').show();
    });
    $('.quotation_iframe_bg,.iframe_close').click(function(){
        $('.quotation_iframe_bg,.quotation_iframe').hide();
    });
");
?>

//预览 链接

<a class="preview_icon" href="javascript:;" url="<?= Yii::$app->urlManager->createUrl(['/goods/xls', 'path' => $model['path']]) ?>">预览</a>

<!-- 弹框 使用iframe 显示excel内容-->
<div class="comm_popup_bg quotation_iframe_bg"></div>
<div class="quotation_iframe">
    <span class="iframe_close"></span>
    <iframe id="fileIframe" width="100%" height="100%" src="" frameborder="0"></iframe>
</div>
觉得很赞
您需要登录后才可以评论。登录 | 立即注册