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

时间:2022-10-20 20:41:45

In Kartik Yii2 Export, While exporting as Excel am getting This Page Cant't Reached Error in Localhost.

在Kartik Yii2导出中,当导出为Excel时,在Localhost中获得此页面不能达到错误。

if i export as Text or CSV, export get worked but if i open the exported file Text or CSV, Half the report is printing like html code

如果我导出为文本或CSV,那么导出就会工作,但是如果我打开导出的文件文本或CSV,报告就会有一半像html代码一样打印出来

Help will be really appreciated.

非常感谢你的帮助。

GridCode:

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',
        ],
    ]); ?>

Above is my Grid view Code. Help will be really appreciated.

上面是我的网格视图代码。非常感谢你的帮助。

Updated:

更新:

Error geeting while exporting as CSV:

导出为CSV时出错:

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

Error geeting while exporting as EXCEL

当导出为EXCEL时发生错误

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

3 个解决方案

#1


1  

There is an issue in your gridview, one of the field in gridview carries "=" equal to sign. please check it out PhpOffice/PhpExcel

在gridview中有一个问题,gridview中的一个字段携带“=”=。请查看PhpOffice/PhpExcel

#2


0  

Try exportConfig settings this

尝试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,
],
    ]); ?>

#3


0  

Try this code for your GridVew::Widget:

请为您的GridVew::Widget尝试以下代码:

  GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => $gridColumns,
    'exportConfig'=> [
        GridView::CSV=>[
            'label' => 'CSV',
            'icon' => '',
            'iconOptions' => '',
            'showHeader' => false,
            'showPageSummary' => false,
            'showFooter' => false,
            'showCaption' => false,
            'filename' => 'yii',
            'alertMsg' => 'created',
            'options' => ['title' => 'Semicolon -  Separated Values'],
            'mime' => 'application/csv',
            'config' => [
                'colDelimiter' => ";",
                'rowDelimiter' => "\r\n",
            ], 
        ],
    ],
]);

#1


1  

There is an issue in your gridview, one of the field in gridview carries "=" equal to sign. please check it out PhpOffice/PhpExcel

在gridview中有一个问题,gridview中的一个字段携带“=”=。请查看PhpOffice/PhpExcel

#2


0  

Try exportConfig settings this

尝试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,
],
    ]); ?>

#3


0  

Try this code for your GridVew::Widget:

请为您的GridVew::Widget尝试以下代码:

  GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => $gridColumns,
    'exportConfig'=> [
        GridView::CSV=>[
            'label' => 'CSV',
            'icon' => '',
            'iconOptions' => '',
            'showHeader' => false,
            'showPageSummary' => false,
            'showFooter' => false,
            'showCaption' => false,
            'filename' => 'yii',
            'alertMsg' => 'created',
            'options' => ['title' => 'Semicolon -  Separated Values'],
            'mime' => 'application/csv',
            'config' => [
                'colDelimiter' => ";",
                'rowDelimiter' => "\r\n",
            ], 
        ],
    ],
]);