我用过Yii2-grid和Yii2-dynagrid。当我从网格视图导出图像列但未导出图像列时,它在 Excel 表中显示空白单元格。
这是我的代码。
$model->p_image
是实时服务器图像网址吗https://www.exaple.com/uploads/image.png
<?php
// Gridview Setting array
$setting = [
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showPageSummary' => false,
'floatHeader' => true,
'autoXlFormat' => true,
'pjax' => true,
'hover'=>true,
'pjaxSettings' => ['options' => ['id' => 'kv-pjax-container']],
'panel' => [
'heading' => false,
'footer' => false,
'beforeOptions' => ['style' => 'padding:10px 0px'],
],
'panelBeforeTemplate' => '
<div class="pull-left" style="padding-top: 10px">
{summary}
</div>
<div class="pull-right">
<div class="btn-toolbar kv-grid-toolbar" role="toolbar">
{toolbar}
</div>
</div>
{before}
<div class="clearfix"></div>',
'panelTemplate' => '{panelBefore}{items}{pager}',
'export'=>[
'label' => 'Export Data',
'fontAwesome' => true,
'showConfirmAlert' => false,
'target' => \kartik\grid\GridView::TARGET_BLANK
],
'toolbar' => [
['content'=>'{dynagrid}'],
'{export}',
'{toggleData}',
],
'exportConfig' => [
\kartik\grid\GridView::CSV => ['filename' => $fileTitle.time()],
\kartik\grid\GridView::PDF => [
'filename' => $fileTitle.time(),
'config' => [
'methods' => [
'SetHeader' => [str_replace("_", ' ', $fileTitle)],
'SetFooter' => ['{PAGENO}'],
],
],
],
\kartik\grid\GridView::EXCEL => [
'filename' => $fileTitle.time(),
],
]
] ?>
<?php
$dynagrid = DynaGrid::begin([
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'p_image',
'value' => function($model) {
return $model->p_image;
},
'format' => ['image',['width'=>'45','class'=>'img-circle']],
'filter' => false,
],
'p_asin',
'p_title',
],
'theme' => 'panel-info',
'showPersonalize'=>true,
'allowThemeSetting' => false,
'allowFilterSetting' => false,
'allowSortSetting' => false,
'submitButtonOptions' => ['class' => 'btn btn-success'],
'gridOptions' => $setting, <------ grid setting array
'options' => ['id' => 'dynagrid-product-data'] // a unique identifier is important
]);
DynaGrid::end();
?>