Yii2-export: exported CSV/XLS contains html from page

Hi. I’m using yii2-export and it’s almost all fine, except that I get some html of the page inside the exported file in Excel/CSV. This does not happen with PDF.

It’s the same problem reported in issue 102, but I don’t understand Kartik’s reply.

What markup should be checked? I found no option to include/exclude portions of page inside the exported file.

My ExportMenu config:

        'toolbar' => [
        ExportMenu::widget([
            'dataProvider' => $dataProvider,
            'columns' => $columns,
            'showColumnSelector' => false,
            'target' => ExportMenu::TARGET_BLANK,
            'pjaxContainerId' => 'kv-pjax-container',
            'fontAwesome'=>true,
            'showConfirmAlert'=>false,
            'exportContainer' => [
                'class' => 'btn-group mr-2'
            ],
            'filename'        => Yii::t('app', 'esportazione_vetture'),
            'exportConfig' => [
                ExportMenu::FORMAT_HTML => false,
                ExportMenu::FORMAT_EXCEL => false,
                ExportMenu::FORMAT_TEXT => false,
                ExportMenu::FORMAT_CSV   => [
                    'label'           => Yii::t('app', 'Salva CSV'),
                ],
                ExportMenu::FORMAT_EXCEL_X => [
                    'label'           => Yii::t('app', 'Salva Excel'),
                ],
                ExportMenu::FORMAT_PDF   => [
                    'label'           => Yii::t('app', 'Salva PDF'),
                    'showPageSummary' => true,
                    'config'          => $pdf_config,
                ],
            ],                
            'dropdownOptions' => [
                'label' => Yii::t('app', 'Esporta'),
                'class' => 'btn btn-secondary',
                /*
                'itemsBefore' => [
                    '<div class="dropdown-header">Esporta su</div>',
                ],
                */
            ],
        ]),
    ],
    'panel'=>[
        'before' => '{summary}',
        'type'    => GridView::TYPE_DEFAULT,
        'heading' => FALSE
    ],
];

Thanks

Hi @maxxer

I’m not very sure because I don’t have any experience with yii2-export. But Kartik’s reply seems to be suggesting that you should check the HTML of your view script. It’s only a guess, but your view script might have a mismatch of tags … an opening tag without the corresponding closing tag, a closing tag without the corresponding opening tag, or overlapped tags, … etc.

1 Like

Hi, thanks for the reply.

I tried removing all the HTML around the GridView but there’s still a small issue: I still get some spaces and a BOM character (0xfeff) in the beginning of the file, which causes the CSV to be lightly corrupted. Same applies for xlsx, unfortunately the latter doesn’t get opened.

Can you show us the relevant view code?

I’ve tried with a barely empty layout and the best result I could obtain is the CSV containing some spaces and the BOM char feff.

                <feff>

There indeed must be an invalid or imperfect HTML tag which makes the extension behave this way, but I was unable to identify it so far.

I’ll investigate a little further, but I might switch to yii2-excelexport which generates the file on the controller and is not influenced by the webpage.

You can use this site to check your html.
https://validator.w3.org/

But IMO it’s best for you to consider using a better editor or IDE that can help you to write a valid html.

thanks for the suggestion. unfortunately the app is behind auth, so I cannot use an external validator.

I’m trying to use Firefox’s HTML validator but returns a lot of messages I have to check manually.

the problem is, as initially supposed by @softark, the HTML markup. I tried to remove everything from the page and export works, but I had to remove everything from the view! What is weird that just a single empty line will break export.

This view file does work:

<?php

use yii\helpers\ArrayHelper;
use yii\bootstrap\ActiveForm;
use kartik\select2\Select2;
use app\models\Profile;
use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $dataProvider \yii\data\ActiveDataProvider */
/* @var $searchModel \app\models\VetturaSearch */
/* @var $venditore \app\models\docux\Venditore */
?>
<?php echo $this->render("/vettura/_list", [
                    'dataProvider' => $dataProvider,
                    'searchModel' => $searchModel,
                    'gridOptions' => [
                        'summary' => FALSE,
                    ],
                    'lightVersion' => TRUE,
                ]); 
                
// Devo impostarlo qui perché altrimenti una delle view incluse lo ridefinisce
$this->title = 'Cruscotto Responsabile';

while this doesn’t:

<?php

use yii\helpers\ArrayHelper;
use yii\bootstrap\ActiveForm;
use kartik\select2\Select2;
use app\models\Profile;
use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $dataProvider \yii\data\ActiveDataProvider */
/* @var $searchModel \app\models\VetturaSearch */
/* @var $venditore \app\models\docux\Venditore */
?>

<?php echo $this->render("/vettura/_list", [
                    'dataProvider' => $dataProvider,
                    'searchModel' => $searchModel,
                    'gridOptions' => [
                        'summary' => FALSE,
                    ],
                    'lightVersion' => TRUE,
                ]); 
                
// Devo impostarlo qui perché altrimenti una delle view incluse lo ridefinisce
$this->title = 'Cruscotto Responsabile';

The only difference between the two blocks is the empty line before <?php echo.

The _list.php view file contains:

<?php
/* some stuff */

echo GridView::widget(array_merge([ // Alcune opzioni potrebbero essere sovrascritte da $gridOptions
    'dataProvider' => $dataProvider,
    'tableOptions' => [
        'class' => $lightVersion ? 'hideHeaderOnMobile' : '',
    ],
    'autoXlFormat'=>true,
    'rowOptions'=>function($model){
            if($model->stato_lavorazione === "D"){
                return ['class' => 'danger'];
            }
    },
    'persistResize' => TRUE,
    'filterModel' => $searchModel,
    'pjax' => TRUE,
    'options' => [
        'id' => 'elenco-vetture'
    ],
    'columns' => $columns,
], $gridOptions, $toolbar));

Would you please check the HTML markups in some stuff?

This is the controller

    public function actionIndexVettura()
    {
        $this->layout = "main-login";
        $searchModel = new VetturaSearch();
        $dataProvider = $searchModel->searchPos(Yii::$app->request->queryParams);
        
        return $this->render('/vettura/index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'searchPosXY'  => TRUE,
        ]);
    }

this is the layout:

<?php
use yii\helpers\Html;
use yii\web\View;
use yii\helpers\ArrayHelper;

/* @var $this \yii\web\View */
/* @var $content string */

if (class_exists('backend\assets\AppAsset')) {
    backend\assets\AppAsset::register($this);
} else {
    app\assets\AppAsset::register($this);
}

dmstr\web\AdminLteAsset::register($this);

?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body class=" hold-transition" style="background-color: #ecf0f5">
<?php $this->beginBody() ?>
    <div class="row">&nbsp;</div>
    <?= $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

this is the index view

<?php

use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $searchModel app\models\VetturaSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $searchPosXY boolean */

if ( !isset( $searchPosXY ) )
    $searchPosXY = TRUE;

$this->title = Yii::t('app', 'Vetture');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="vettura-index">
    <?php echo $this->render("_list", [
        'dataProvider' => $dataProvider,
        'searchModel' => $searchModel,
        'gridOptions' => $searchModel->changeEmptyText ? ["emptyText" => Yii::t("app", "Inserisci un termine di ricerca")] : [],
	    'searchPosXY' => $searchPosXY,
        'otherColumns' => [
            'nomeVenditore',
            'tempoDallaPrimaStampa',
        ]
    ]); ?>
    <p>
        <?= Html::a(Yii::t('app', 'Crea Vettura'), ['/logix/create-vettura'], ['class' => 'btn btn-success']) ?>
    </p>
</div>

this is the _list view:

<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\bootstrap\Button;
use kartik\export\ExportMenu;
use kartik\grid\GridView;
use app\dictionaries\TipoVettura;
use app\dictionaries\TipoStatoLavorazione;

$css_distinte = <<<CSS
.gia-presente {
    color: #999;
    cursor: not-allowed;
}
CSS;

$this->registerCss($css_distinte);

if ( !isset( $searchPosXY ) ) {
    $searchPosXY = FALSE;
}
$toolbar = [];
$footer = "";
if (!isset($visualizzaPosizioneVettura)) $visualizzaPosizioneVettura = FALSE;

if (!isset($gridOptions)) {
    $gridOptions = [];
}
if (!isset($lightVersion)) {
    $lightVersion = FALSE;
}

// Colonne gridview (ed esportazione)
$columns = [
    [
        'attribute' => 'tipo',
        'value' => 'tipoStr',
//        'filter' => TipoVettura::all(),
    ],
];

$colonna_posizione = [
    'attribute' => 'posizione',
    'format' => 'RAW',
    'visible' => !$lightVersion,
    'options' => ['style' => 'width:100px']
];


$colonna_posizione['contentOptions'] = [
        'style' => 'min-width: 160px;',
    ];
$columns[] =  $colonna_posizione;

if ( !\Yii::$app->devicedetect->isMobile() ) {
    $pdf_config = [
        'methods' => [
            'SetHeader' => Yii::t('app', 'Esportazione Vetture'),
            'SetFooter' => $footer,
        ],
        'options' => [
            'header'    => Yii::t('app', 'Esportazione Vetture'),
            'title'     => Yii::t('app', 'Esportazione Vetture'),
            'subject'   => '',
        ]
    ];
    $toolbar = [
        'toolbar' => [
            ExportMenu::widget([
                'dataProvider' => $dataProvider,
                'columns' => $columns,
                'showColumnSelector' => false,
                'target' => ExportMenu::TARGET_BLANK,
                'pjaxContainerId' => 'kv-pjax-container',
                'fontAwesome'=>true,
                'showConfirmAlert'=>false,
                'exportContainer' => [
                    'class' => 'btn-group mr-2'
                ],
                'filename'        => Yii::t('app', 'esportazione_vetture'),
                'exportConfig' => [
                    ExportMenu::FORMAT_HTML => false,
                    ExportMenu::FORMAT_EXCEL => false,
                    ExportMenu::FORMAT_TEXT => false,
                    ExportMenu::FORMAT_CSV   => [
                        'label'           => Yii::t('app', 'Salva CSV'),
                    ],
                    ExportMenu::FORMAT_EXCEL_X => [
                        'label'           => Yii::t('app', 'Salva Excel'),
                    ],
                    ExportMenu::FORMAT_PDF   => [
                        'label'           => Yii::t('app', 'Salva PDF'),
                        'showPageSummary' => true,
                        'config'          => $pdf_config,
                    ],
                ],                
                'dropdownOptions' => [
                    'label' => Yii::t('app', 'Esporta'),
                    'class' => 'btn btn-secondary',
                    /*
                    'itemsBefore' => [
                        '<div class="dropdown-header">Esporta su</div>',
                    ],
                    */
                ],
            ]),
        ],
        'panel'=>[
            'before' => '{summary}',
            'type'    => GridView::TYPE_DEFAULT,
            'heading' => FALSE
        ],
    ];
}

echo GridView::widget(array_merge([ 
    'dataProvider' => $dataProvider,
    'tableOptions' => [
        'class' => $lightVersion ? 'hideHeaderOnMobile' : '',
    ],
    'autoXlFormat'=>true,
    'rowOptions'=>function($model){
            if($model->stato_lavorazione === "D"){
                return ['class' => 'danger'];
            }
    },
    'persistResize' => TRUE,
    'filterModel' => $searchModel,
    'pjax' => TRUE,
    'options' => [
        'id' => 'elenco-vetture'
    ],
    'columns' => $columns,
], $gridOptions, $toolbar));

the resulting html is this:

<!DOCTYPE html>
<html lang="it-IT">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-param" content="_csrf">
    <meta name="csrf-token" content="HNLDBng8tqAYEJKVqI7ovH6lrrAXLsTfJiePDNzT7Hlvt5FkK1Sb4U1A6tHF_qL_F-rt71JN96lFdOV7uLyUMQ==">
    <title>Vetture</title>
    <link href="/work/gestyocar/web/assets/8ad78fe1/css/bootstrap.css" rel="stylesheet">
<link href="/work/gestyocar/web/assets/dd07fbdd/dist/css/bootstrap-dialog.min.css" rel="stylesheet">
<link href="/work/gestyocar/web/assets/9d1f3197/css/kv-grid.min.css" rel="stylesheet">
<link href="/work/gestyocar/web/assets/9d1f3197/css/jquery.resizableColumns.min.css" rel="stylesheet">
<link href="/work/gestyocar/web/css/site.css" rel="stylesheet">
<link href="/work/gestyocar/web/assets/f80f69bc/css/font-awesome.min.css" rel="stylesheet">
<link href="/work/gestyocar/web/assets/41536e50/css/AdminLTE.min.css" rel="stylesheet">
<link href="/work/gestyocar/web/assets/41536e50/css/skins/_all-skins.min.css" rel="stylesheet">
<style>.gia-presente {
    color: #999;
    cursor: not-allowed;
}</style>
<style>.bootstrap-dialog .modal-header.bootstrap-dialog-draggable{cursor:move}</style>
<script src="/work/gestyocar/web/assets/84434d1d/js/dialog.min.js"></script>
<script>var krajeeDialogDefaults_7d44018c = {"alert":{"type":"type-info","title":"Informazione","buttonLabel":"<span class=\"glyphicon glyphicon-ok\"></span> Ok"},"confirm":{"type":"type-warning","title":"Conferma","btnOKClass":"btn-warning","btnOKLabel":"<span class=\"glyphicon glyphicon-ok\"></span> Ok","btnCancelLabel":"<span class=\"glyphicon glyphicon-ban-circle\"></span> Annulla"},"prompt":{"draggable":false,"title":"Informazione","buttons":[{"label":"Annulla","icon":"glyphicon glyphicon-ban-circle"},{"label":"Ok","icon":"glyphicon glyphicon-ok","cssClass":"btn-primary"}],"closable":false},"dialog":{"draggable":true,"title":"Informazione","buttons":[{"label":"Annulla","icon":"glyphicon glyphicon-ban-circle"},{"label":"Ok","icon":"glyphicon glyphicon-ok","cssClass":"btn-primary"}]}};
var krajeeDialog_e48a4427 = {"id":"w1"};
var krajeeDialog=new KrajeeDialog(true,krajeeDialog_e48a4427,krajeeDialogDefaults_7d44018c);
var kvexpmenu_9907d697 = {"target":"_blank","formOptions":{"class":"kv-export-full-form","id":"w0-export-form"},"messages":{"allowPopups":"Disabilita qualsiasi blockers popup nel tuo browser per permettere il download","confirmDownload":"Procedere?","downloadProgress":"Generazione del file da esportare. Attendere...","downloadComplete":"Richiesta sottomessa! Puoi chiudere in sicurezza questa finestra dopo aver scaricato il file"},"exportType":"Xlsx","colSelFlagParam":"column_selector_enabled","colSelEnabled":0,"exportRequestParam":"exportFull_w0","exportTypeParam":"export_type","exportColsParam":"export_columns","exportFormHiddenInputs":[],"showConfirmAlert":false,"dialogLib":"krajeeDialog"};

var krajeeDialog_71cd4f22 = {"id":"w6"};
var krajeeDialog=new KrajeeDialog(true,krajeeDialog_71cd4f22,krajeeDialogDefaults_7d44018c);</script></head>
<body class=" hold-transition" style="background-color: #ecf0f5">
    <div class="row">&nbsp;</div>
    <div class="vettura-index">
    <div id="elenco-vetture-pjax" data-pjax-container="" data-pjax-push-state data-pjax-timeout="1000"><div class="kv-loader-overlay"><div class="kv-loader"></div></div><div id="elenco-vetture" class="is-bs3 hide-resize" data-krajee-grid="kvGridInit_c24939ba" data-krajee-ps="ps_elenco_vetture_container"><div class="panel panel-default">
<div class="kv-panel-before">    <div class="btn-toolbar kv-grid-toolbar toolbar-container pull-right">
<div class="btn-group" role="group">
<div class="btn-group mr-2">
<button id="w2" class="btn btn-secondary btn-default dropdown-toggle" title="Esporta i dati nel formato selezionato" data-toggle="dropdown"><i class="glyphicon glyphicon-export"></i> Esporta <span class="caret"></span></button>

<ul id="w3" class="dropdown-menu"><li title="Valori Separati Da Virgole"><a id="w0-csv" class="export-full-csv" href="#" data-format="Csv" tabindex="-1"><i class="text-primary fa fa-file-code-o"></i> Salva CSV</a></li>
<li title="Portable Document Format"><a id="w0-pdf" class="export-full-pdf" href="#" data-format="Pdf" tabindex="-1"><i class="text-danger fa fa-file-pdf-o"></i> Salva PDF</a></li>
<li title="Microsoft Excel 2007+ (xlsx)"><a id="w0-xlsx" class="export-full-xlsx" href="#" data-format="Xlsx" tabindex="-1"><i class="text-success fa fa-file-excel-o"></i> Salva Excel</a></li></ul>
</div></div></div>
    <div class="pull-right"><div class="summary">Visualizzo <b>1-10</b> di <b>14</b> elementi.</div></div>
    <div class="clearfix"></div></div>
<div id="elenco-vetture-container" class="table-responsive kv-grid-container" data-resizable-columns-id="kv-1-elenco-vetture"><table class="kv-grid-table table table-bordered table-striped kv-table-wrap"><colgroup><col>
<col style="width:100px"></colgroup>
<thead>

<tr><th data-resizable-column-id="kv-col-0" data-col-seq="0"><a href="/work/gestyocar/web/index.php?r=logix%2Findex-vettura&amp;VetturaSearch%5Bidvettura%5D=&amp;VetturaSearch%5Bstato%5D=&amp;VetturaSearch%5Bnumero_telaio%5D=&amp;VetturaSearch%5Bnumero_pratica%5D=&amp;VetturaSearch%5Btipo%5D=&amp;VetturaSearch%5Bnumero_targa%5D=&amp;VetturaSearch%5Bmarca%5D=21&amp;VetturaSearch%5Bmodello%5D=&amp;VetturaSearch%5Bcliente%5D=&amp;VetturaSearch%5Bstato_lavorazione%5D=&amp;VetturaSearch%5Bposizione%5D=&amp;VetturaSearch%5Bdata_arrivo%5D=&amp;VetturaSearch%5Bdata_consegna%5D=&amp;page=1&amp;per-page=10&amp;sort=tipo" data-sort="tipo">Tipo</a></th><th data-resizable-column-id="kv-col-1" data-col-seq="1">Posizione</th></tr><tr id="elenco-vetture-filters" class="filters skip-export"><td><input type="text" class="form-control" name="VetturaSearch[tipo]" value=""></td><td><input type="text" class="form-control" name="VetturaSearch[posizione]" value=""></td></tr>

</thead>
<tbody>
<tr data-key="81749"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
<tr data-key="7519"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
<tr data-key="7533"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
<tr data-key="7566"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
<tr data-key="70805"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
<tr data-key="7573"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
<tr data-key="6809"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
<tr data-key="7079"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
<tr data-key="7080"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
<tr data-key="8616"><td data-col-seq="0" style="mso-number-format: \@;">Usato</td><td style="min-width: 160px; mso-number-format: ;" data-col-seq="1"><span class="not-set">(nessun valore)</span></td></tr>
</tbody></table></div>
<div class="kv-panel-after"></div>
<div class="panel-footer">    <div class="kv-panel-pager">
        <ul class="pagination"><li class="prev disabled"><span>&laquo;</span></li>
<li class="active"><a href="/work/gestyocar/web/index.php?r=logix%2Findex-vettura&amp;VetturaSearch%5Bidvettura%5D=&amp;VetturaSearch%5Bstato%5D=&amp;VetturaSearch%5Bnumero_telaio%5D=&amp;VetturaSearch%5Bnumero_pratica%5D=&amp;VetturaSearch%5Btipo%5D=&amp;VetturaSearch%5Bnumero_targa%5D=&amp;VetturaSearch%5Bmarca%5D=21&amp;VetturaSearch%5Bmodello%5D=&amp;VetturaSearch%5Bcliente%5D=&amp;VetturaSearch%5Bstato_lavorazione%5D=&amp;VetturaSearch%5Bposizione%5D=&amp;VetturaSearch%5Bdata_arrivo%5D=&amp;VetturaSearch%5Bdata_consegna%5D=&amp;page=1&amp;per-page=10" data-page="0">1</a></li>
<li><a href="/work/gestyocar/web/index.php?r=logix%2Findex-vettura&amp;VetturaSearch%5Bidvettura%5D=&amp;VetturaSearch%5Bstato%5D=&amp;VetturaSearch%5Bnumero_telaio%5D=&amp;VetturaSearch%5Bnumero_pratica%5D=&amp;VetturaSearch%5Btipo%5D=&amp;VetturaSearch%5Bnumero_targa%5D=&amp;VetturaSearch%5Bmarca%5D=21&amp;VetturaSearch%5Bmodello%5D=&amp;VetturaSearch%5Bcliente%5D=&amp;VetturaSearch%5Bstato_lavorazione%5D=&amp;VetturaSearch%5Bposizione%5D=&amp;VetturaSearch%5Bdata_arrivo%5D=&amp;VetturaSearch%5Bdata_consegna%5D=&amp;page=2&amp;per-page=10" data-page="1">2</a></li>
<li class="next"><a href="/work/gestyocar/web/index.php?r=logix%2Findex-vettura&amp;VetturaSearch%5Bidvettura%5D=&amp;VetturaSearch%5Bstato%5D=&amp;VetturaSearch%5Bnumero_telaio%5D=&amp;VetturaSearch%5Bnumero_pratica%5D=&amp;VetturaSearch%5Btipo%5D=&amp;VetturaSearch%5Bnumero_targa%5D=&amp;VetturaSearch%5Bmarca%5D=21&amp;VetturaSearch%5Bmodello%5D=&amp;VetturaSearch%5Bcliente%5D=&amp;VetturaSearch%5Bstato_lavorazione%5D=&amp;VetturaSearch%5Bposizione%5D=&amp;VetturaSearch%5Bdata_arrivo%5D=&amp;VetturaSearch%5Bdata_consegna%5D=&amp;page=2&amp;per-page=10" data-page="1">&raquo;</a></li></ul>
    </div>
    
    <div class="clearfix"></div></div></div></div></div>    <p>
        <a class="btn btn-success" href="/work/gestyocar/web/index.php?r=logix%2Fcreate-vettura">Crea Vettura</a>    </p>
</div>
<script src="/work/gestyocar/web/assets/f335e2fa/jquery.js"></script>
<script src="/work/gestyocar/web/assets/ade0a232/yii.js"></script>
<script src="/work/gestyocar/web/assets/8ad78fe1/js/bootstrap.js"></script>
<script src="/work/gestyocar/web/assets/dd07fbdd/dist/js/bootstrap-dialog.min.js"></script>
<script src="/work/gestyocar/web/assets/84434d1d/js/dialog-yii.min.js"></script>
<script src="/work/gestyocar/web/assets/4d667e4b/js/kv-export-data.min.js"></script>
<script src="/work/gestyocar/web/assets/9d1f3197/js/kv-grid-export.min.js"></script>
<script src="/work/gestyocar/web/assets/9d1f3197/js/store.min.js"></script>
<script src="/work/gestyocar/web/assets/9d1f3197/js/jquery.resizableColumns.min.js"></script>
<script src="/work/gestyocar/web/assets/ade0a232/yii.gridView.js"></script>
<script src="/work/gestyocar/web/assets/6a472112/jquery.pjax.js"></script>
<script src="/work/gestyocar/web/js/ajax-modal-popup.js"></script>
<script src="/work/gestyocar/web/js/panel-expand-from-heading.js"></script>
<script src="/work/gestyocar/web/assets/41536e50/js/adminlte.min.js"></script>
<script>jQuery(function ($) {
krajeeYiiConfirm('krajeeDialog');
jQuery('#w0-csv').exportdata({"settings":kvexpmenu_9907d697,"alertMsg":"Il file esportato in CSV sarà generato per il download"});
jQuery('#w0-pdf').exportdata({"settings":kvexpmenu_9907d697,"alertMsg":"Il file esportato in PDF sarà generato per il download"});
jQuery('#w0-xlsx').exportdata({"settings":kvexpmenu_9907d697,"alertMsg":"Il file esportato in EXCEL 2007+ (xlsx) sarà generato per il download"});
jQuery('#kv-pjax-container').on('pjax:complete', function() {
                jQuery('#w0-csv').exportdata({"settings":kvexpmenu_9907d697,"alertMsg":"Il file esportato in CSV sarà generato per il download"});
jQuery('#w0-pdf').exportdata({"settings":kvexpmenu_9907d697,"alertMsg":"Il file esportato in PDF sarà generato per il download"});
jQuery('#w0-xlsx').exportdata({"settings":kvexpmenu_9907d697,"alertMsg":"Il file esportato in EXCEL 2007+ (xlsx) sarà generato per il download"});

            });

jQuery('#w2').dropdown();
jQuery('#w4').dropdown();
var kvGridExp_61fe686e={"gridId":"elenco-vetture","action":"/work/gestyocar/web/index.php?r=gridview%2Fexport%2Fdownload","module":"gridview","encoding":"utf-8","bom":1,"target":"_blank","messages":{"allowPopups":"Disabilita tutti i popup blockers per consentire il download.","confirmDownload":"Procedere?","downloadProgress":"Generazione file di esportazione. Attendere prego...","downloadComplete":"Richiesta inviata! E' possibile chiudere questo popup dopo aver salvato il file scaricato."},"exportConversions":[{"from":"<span class=\"glyphicon glyphicon-ok text-success\"></span>","to":"Attivo"},{"from":"<span class=\"glyphicon glyphicon-remove text-danger\"></span>","to":"Inattivo"}],"showConfirmAlert":true};
var kvGridExp_12735912={"filename":"grid-export","showHeader":true,"showPageSummary":true,"showFooter":true};
var kvGridExp_1ec3c108={"dialogLib":"krajeeDialog","gridOpts":kvGridExp_61fe686e,"genOpts":kvGridExp_12735912,"alertMsg":"Sarà generato il file HTML da esportare.","config":{"cssFile":["https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"]}};
var kvGridExp_2a0fbead={"dialogLib":"krajeeDialog","gridOpts":kvGridExp_61fe686e,"genOpts":kvGridExp_12735912,"alertMsg":"Sarà generato il file CSV da esportare.","config":{"colDelimiter":",","rowDelimiter":"\r\n"}};
var kvGridExp_101dcc50={"dialogLib":"krajeeDialog","gridOpts":kvGridExp_61fe686e,"genOpts":kvGridExp_12735912,"alertMsg":"Sarà generato il file di testo da esportare.","config":{"colDelimiter":"\t","rowDelimiter":"\r\n"}};
var kvGridExp_16d7b055={"dialogLib":"krajeeDialog","gridOpts":kvGridExp_61fe686e,"genOpts":kvGridExp_12735912,"alertMsg":"Sarà generato il file di Excel da esportare.","config":{"worksheet":"ExportWorksheet","cssFile":""}};
var kvGridExp_2729be87={"dialogLib":"krajeeDialog","gridOpts":kvGridExp_61fe686e,"genOpts":kvGridExp_12735912,"alertMsg":"Sarà generato il file PDF da esportare.","config":{"mode":"UTF-8","format":"A4-L","destination":"D","marginTop":20,"marginBottom":20,"cssInline":".kv-wrap{padding:20px}","methods":{"SetHeader":[{"odd":{"L":{"content":"Yii2 Grid Export (PDF)","font-size":8,"color":"#333333"},"C":{"content":"Esportazione griglia","font-size":16,"color":"#333333"},"R":{"content":"Generato: Thu, 10-Jan-2019","font-size":8,"color":"#333333"}},"even":{"L":{"content":"Yii2 Grid Export (PDF)","font-size":8,"color":"#333333"},"C":{"content":"Esportazione griglia","font-size":16,"color":"#333333"},"R":{"content":"Generato: Thu, 10-Jan-2019","font-size":8,"color":"#333333"}}}],"SetFooter":[{"odd":{"L":{"content":"© Krajee Yii2 Extensions","font-size":8,"font-style":"B","color":"#999999"},"R":{"content":"[ {PAGENO} ]","font-size":10,"font-style":"B","font-family":"serif","color":"#333333"},"line":true},"even":{"L":{"content":"© Krajee Yii2 Extensions","font-size":8,"font-style":"B","color":"#999999"},"R":{"content":"[ {PAGENO} ]","font-size":10,"font-style":"B","font-family":"serif","color":"#333333"},"line":true}}]},"options":{"title":"Esportazione griglia","subject":"Esportazione PDF generata dall'estensione kartik-v/yii2-grid","keywords":"krajee, grid, export, yii2-grid, pdf"},"contentBefore":"","contentAfter":""}};
var kvGridExp_6349297d={"dialogLib":"krajeeDialog","gridOpts":kvGridExp_61fe686e,"genOpts":kvGridExp_12735912,"alertMsg":"Sarà generato il file JSON da esportare.","config":{"colHeads":[],"slugColHeads":false,"jsonReplacer":function(k,v){return typeof(v)==='string'?$.trim(v):v},"indentSpace":4}};
var kvGridInit_c24939ba=function(){
jQuery('#elenco-vetture .export-html').gridexport(kvGridExp_1ec3c108);jQuery('#elenco-vetture .export-csv').gridexport(kvGridExp_2a0fbead);jQuery('#elenco-vetture .export-txt').gridexport(kvGridExp_101dcc50);jQuery('#elenco-vetture .export-xls').gridexport(kvGridExp_16d7b055);jQuery('#elenco-vetture .export-pdf').gridexport(kvGridExp_2729be87);jQuery('#elenco-vetture .export-json').gridexport(kvGridExp_6349297d);jQuery('#elenco-vetture-container').resizableColumns('destroy').resizableColumns({"resizeFromBody":false});
};
kvGridInit_c24939ba();
jQuery("#elenco-vetture-pjax").on('pjax:timeout', function(e){e.preventDefault()}).on('pjax:send', function(){$("#elenco-vetture-pjax").addClass('kv-grid-loading')}).off('pjax:complete.23cfe1f1').on('pjax:complete.23cfe1f1', function(){setTimeout(kvGridInit_c24939ba, 2500);$("#elenco-vetture-pjax").removeClass('kv-grid-loading');
});
jQuery('#elenco-vetture').yiiGridView({"filterUrl":"\/work\/gestyocar\/web\/index.php?r=logix%2Findex-vettura\u0026VetturaSearch%5Bidvettura%5D=\u0026VetturaSearch%5Bstato%5D=\u0026VetturaSearch%5Bnumero_telaio%5D=\u0026VetturaSearch%5Bnumero_pratica%5D=\u0026VetturaSearch%5Btipo%5D=\u0026VetturaSearch%5Bnumero_targa%5D=\u0026VetturaSearch%5Bmarca%5D=21\u0026VetturaSearch%5Bmodello%5D=\u0026VetturaSearch%5Bcliente%5D=\u0026VetturaSearch%5Bstato_lavorazione%5D=\u0026VetturaSearch%5Bposizione%5D=\u0026VetturaSearch%5Bdata_arrivo%5D=\u0026VetturaSearch%5Bdata_consegna%5D=\u0026page=1\u0026per-page=10","filterSelector":"#elenco-vetture-filters input, #elenco-vetture-filters select"});
jQuery(document).pjax("#elenco-vetture-pjax a", {"push":true,"replace":false,"timeout":1000,"scrollTo":false,"container":"#elenco-vetture-pjax"});
jQuery(document).on("submit", "#elenco-vetture-pjax form[data-pjax]", function (event) {jQuery.pjax.submit(event, {"push":true,"replace":false,"timeout":1000,"scrollTo":false,"container":"#elenco-vetture-pjax"});});
});</script></body>
</html>

the downloaded csv is this:

<div class="vettura-index">
    "Tipo","Posizione"
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""
"Usato",""

in the index view if I remove the <div class="index-vettura"> line, thus removing all the heading html part and just echoing the gridview, the CSV is correct.

thanks

Hmm … I don’t see anything suspicious in your HTML code …

What about the file encoding of the view scripts? Are they written in UTF-8 without BOM?

Yeah, me neither. I tried different HTML validators they all return only trivial errors, but no missing tags.

file reports lista.php as UTF-8. index.php is reported as ASCII Text. I tried forcing save to UTF-8 using Sublime but nothing changes (not even file description, remains as ASCII). I tried also UTF-8 with BOM and got the same result.

Tried find . -name "*.php" -exec file {} \; | grep BOM but no file has BOM, just one in vendor.

I really don’t know what else to search for.

Yeah, it’s very frustrating. Maybe a bug in the extension? I don’t know. I have no guts to dig into the source code of it.

What about this? I don’t see any element with id="kv-pjax-container" in the HTML output.

You may discuss this in the repo comment at issue # 291 to reach the root cause.

1 Like

See this comment.

As I wrote on the issue after looooong troubles I ended up solving by adding clearBuffer => true to ExportMenu configuration.

Thanks everyone for the help and suggestions

2 Likes

Thank you veeery much! Simply adding this solved the problem.
Notice: It is actually 'clearBuffers' => true

3 Likes