错误:在Kartik Yii2导出中无法访问此页面

时间:2016-06-02 07:27:14

标签: excel yii2 export

Kartik Yii2 Export中,导出为ExcelThis Page Cant't Reached Error正在Localhost。{/ p>

如果我exportText or CSV,则导出获取worked但如果我open导出的文件Text or CSV,则Half 报告打印像html代码

非常感谢帮助。

GridCode:

 <?php $gridColumns = [
            ['class' => 'yii\grid\SerialColumn'],
                'membercode',
                'member_name',
                [
                   'attribute' => 'payment_category',
                   'format' => 'raw',
                   'label' => 'Payment Category',
                   'value' => function($model, $key, $index, $grid) {
                        $temp = $model->payment_category;
                        $si = Category::find()->where(['category_id' => $temp])->one();
                        return $si['category_name'];
                    },  
                ],
                'member_gender',
                'member_address:ntext',
                'payment_date',
                'amount',
                'receipt_no',
                'payment_mode',
                'pledge_amount',
                'young_amount',
                'tv_amount',
                'building_amount',
                [
                   'attribute' => 'payment_subcategory',
                   'format' => 'raw',
                   'value' => function($model, $key, $index, $grid) {
                        $exp = explode(',', $model->payment_subcategory);
                        $relation_name = ArrayHelper::map(Subcategory::find()->where(['subcategory_id' => $exp])->all(), 'subcategory_id', 'subcategory_name');
                        $relation = implode(',', $relation_name);
                        return $relation;
                    },
                    'filter' => Html::activeDropDownList($searchModel, 'payment_subcategory', ArrayHelper::map(Subcategory::find()->asArray()->all(), 'id', 'subcategory_name'),['class'=>'form-control','multiple' => true]),
                ],
            ['class' => 'yii\grid\ActionColumn'],
        ]; ?>

    <?= ExportMenu::widget([
            'dataProvider' => $dataProvider,
            'columns' => $gridColumns,
            'columnSelectorOptions'=>[
                'label' => 'Columns',
                'class' => 'btn btn-danger'
            ],
            'fontAwesome' => true,
            'dropdownOptions' => [
                'label' => 'Export All',
                'class' => 'btn btn-primary'
            ]
        ]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => $gridColumns,
        'pager' => [
            'firstPageLabel' => 'First',
            'lastPageLabel' => 'Last',
        ],
    ]); ?>

以上是我的Grid view Code。 帮助将非常感激。

更新:

导出为CSV时出现错误:

Error CSV

导出为EXCEL时的错误广告

error on EXCEL

3 个答案:

答案 0 :(得分:1)

您的gridview中存在一个问题,gridview中的一个字段带有“=”等于符号。请查看PhpOffice/PhpExcel

答案 1 :(得分:0)

尝试使用exportConfig设置

 <?= ExportMenu::widget([
        'dataProvider' => $dataProvider,
        'columns' => $gridColumns,
        'columnSelectorOptions'=>[
            'label' => 'Columns',
            'class' => 'btn btn-danger'
        ],
        'fontAwesome' => true,
        'dropdownOptions' => [
            'label' => 'Export All',
            'class' => 'btn btn-primary'
        ]
        'exportConfig' => [
    ExportMenu::FORMAT_HTML => false,
    ExportMenu::FORMAT_TEXT => false,
],
    ]); ?>

答案 2 :(得分:0)

为GridVew :: Widget尝试此代码:

abc-def-ghi