2017 © Pedro PelΓ‘ez
 

yii2-extension yii2-export

Yii2 It saves data in xls, csv, word, html, pdf files.

image

phpnt/yii2-export

Yii2 It saves data in xls, csv, word, html, pdf files.

  • Monday, May 8, 2017
  • by phpnt
  • Repository
  • 1 Watchers
  • 11 Stars
  • 1,276 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 2 Open issues
  • 8 Versions
  • 8 % Grown

The README.md

phpNT - Export to file

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

ОписаниС:

БохраняСт Π΄Π°Π½Π½Ρ‹Π΅ Π² xls, csv, word, html, pdf Ρ„Π°ΠΉΠ»Ρ‹. Если, Π² прСдставлСнии, модСль Search использовалась вмСстС с DataProvider для Π²Ρ‹Π²ΠΎΠ΄Π° GridView ΠΈ примСнялся Ρ„ΠΈΠ»ΡŒΡ‚Ρ€, Ρ‚ΠΎ ΠΊ сохраняСмым Π΄Π°Π½Π½Ρ‹ΠΌ Π±ΡƒΠ΄Π΅Ρ‚ Ρ‚Π°ΠΊΠΆΠ΅ ΠΏΡ€ΠΈΠΌΠ΅Π½Π΅Π½ этот Ρ„ΠΈΠ»ΡŒΡ‚Ρ€.

Для CSV Ρ„Π°ΠΉΠ»ΠΎΠ² прСдусмотрСн Π²Ρ‹Π±ΠΎΡ€ ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΎΠΊ 'UTF-8' (ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ) ΠΈ 'Windows-1251'.

Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ для русификации PDF Ρ„Π°ΠΉΠ»ΠΎΠ² находится Π² Ρ„Π°ΠΉΠ»Π΅ README, Π² ΠΏΠ°ΠΏΠΊΠ΅ /dompdf_ru.

DEMO


Π‘ΠΎΡ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Π΅ сСти:


Установка:, (*2)


php composer.phar require "phpnt/yii2-export" "*"

ΠΈΠ»ΠΈ, (*3)

composer require phpnt/yii2-export

ΠΈΠ»ΠΈ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Π² composer.json Ρ„Π°ΠΉΠ», (*4)

"phpnt/yii2-export": "*"

ИспользованиС:

### ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅:

// Π² Ρ„Π°ΠΉΠ»Π΅ настройки прилоТСния (main.php - Advanced ΠΈΠ»ΠΈ web.php - Basic) добавляСтся класс Π² controllerMap
...
'controllerMap' => [
    'export' => 'phpnt\exportFile\controllers\ExportController'
],
'components' => [
    ...
],

### Π’ любой ΠΌΠΎΠ΄Π΅Π»ΠΈ Search:

...
class GeoCitySearch extends GeoCity
{
...
    // ΡƒΠΊΠ°Π·Ρ‹Π²Π°ΡŽΡ‚ΡΡ свойства, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π½ΡƒΠΆΠ½ΠΎ Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚ΡŒ Π² Ρ„Π°ΠΉΠ»Ρ‹
    public function exportFields()
    {
        return [
            'id' => function ($model) {
                /* @var $model User */
                return $model->id;
            },
            'name_ru',
            'region_id' => function ($model) {
                /* @var $model GeoCity */
                if (isset($model->region->name_ru)) {
                    return $model->region->name_ru;
                }
                return false;
            },
            'lat',
            'lon'
        ];
    }
...
}

### ΠšΠΎΠ½Ρ‚Ρ€ΠΎΠ»Π»Π΅Ρ€:

...
    // cоздаСтся стандартноС дСйствиС для Π²Ρ‹Π²ΠΎΠ΄Π° Π΄Π°Π½Π½Ρ‹Ρ…
    public function actionExportFile()
    {
        $searchModel = new GeoCitySearch();
        $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);

        return $this->render('export-file', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
...

### ΠŸΡ€Π΅Π΄ΡΡ‚Π°Π²Π»Π΅Π½ΠΈΠ΅ 1:

use phpnt\exportFile\ExportFile;
use yii\grid\GridView;
/* @var $searchModel \common\models\GeoCitySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

// ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹Π΅ настройки
echo ExportFile::widget([
        'model'             => 'common\models\GeoCitySearch',   // ΠΏΡƒΡ‚ΡŒ ΠΊ ΠΌΠΎΠ΄Π΅Π»ΠΈ
        'searchAttributes'  => $searchModel,                    // Ρ„ΠΈΠ»ΡŒΡ‚Ρ€
]) ?>
= GridView::widget([
    'dataProvider'  => $dataProvider,
    'filterModel'   => $searchModel,
    'columns' => [
        ...
    ]
]);
?>

### ΠŸΡ€Π΅Π΄ΡΡ‚Π°Π²Π»Π΅Π½ΠΈΠ΅ 2:

use phpnt\exportFile\ExportFile;
use yii\grid\GridView;
/* @var $searchModel \common\models\GeoCitySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

// ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹Π΅ настройки
echo ExportFile::widget([
    'model'             => 'common\models\search\UserSearch',   // ΠΏΡƒΡ‚ΡŒ ΠΊ ΠΌΠΎΠ΄Π΅Π»ΠΈ
    'title'             => 'Π—Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°',
    'queryParams'       => Yii::$app->request->queryParams,

    'getAll'            => true,                               // всС записи - true, ΡƒΡ‡ΠΈΡ‚Ρ‹Π²Π°Ρ‚ΡŒ ΠΏΠ°Π³ΠΈΠ½Π°Ρ†ΠΈΡŽ - false
    'csvCharset'        => 'Windows-1251',                      // ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ° csv Ρ„Π°ΠΉΠ»Π°: 'UTF-8' (ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ) ΠΈΠ»ΠΈ 'Windows-1251'

    'buttonClass'       => 'btn btn-primary',                   // класс кнопки
    'blockClass'        => 'pull-left',                         // класс Π±Π»ΠΎΠΊΠ° Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ ΠΊΠ½ΠΎΠΏΠΊΠ°
    'blockStyle'        => 'padding: 5px;',                     // ΡΡ‚ΠΈΠ»ΡŒ Π±Π»ΠΎΠΊΠ° Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ ΠΊΠ½ΠΎΠΏΠΊΠ°

    // экспорт Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ Ρ„Π°ΠΉΠ»Ρ‹ (true - Ρ€Π°Π·Ρ€Π΅ΡˆΠΈΡ‚ΡŒ, false - Π·Π°ΠΏΡ€Π΅Ρ‚ΠΈΡ‚ΡŒ)
    'xls'               => true,
    'csv'               => true,
    'word'              => true,
    'html'              => true,
    'pdf'               => true,

    // ΡˆΠ°Π±Π»ΠΎΠ½Ρ‹ ΠΊΠ½ΠΎΠΏΠΎΠΊ
    'xlsButtonName'     => Yii::t('app', 'MS Excel'),
    'csvButtonName'     => Yii::t('app', 'CSV'),
    'wordButtonName'    => Yii::t('app', 'MS Word'),
    'htmlButtonName'    => Yii::t('app', 'HTML'),
    'pdfButtonName'     => Yii::t('app', 'PDF')
]) ?>
= GridView::widget([
    'dataProvider'  => $dataProvider,
    'filterModel'   => $searchModel,
    'columns' => [
        ...
    ]
]);
?>

ДокумСнтация (ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρ‹):

PHPExcel

PHPWord

## dompdf

ВСрсия:

### 0.0.2

ЛицСнзия:

### MIT

The Versions

08/05 2017

dev-master

9999999-dev

Yii2 It saves data in xls, csv, word, html, pdf files.

  Sources   Download

MIT

The Requires

 

csv extension yii2 excel xls html widget export pdf phpexcel word dompdf phpword

08/05 2017

0.0.7

0.0.7.0

Yii2 It saves data in xls, csv, word, html, pdf files.

  Sources   Download

MIT

The Requires

 

csv extension yii2 excel xls html widget export pdf phpexcel word dompdf phpword

24/04 2017

0.0.6

0.0.6.0

Yii2 It saves data in xls, csv, word, html, pdf files.

  Sources   Download

MIT

The Requires

 

csv extension yii2 excel xls html widget export pdf phpexcel word dompdf phpword

17/04 2017

0.0.5

0.0.5.0

Yii2 It saves data in xls, csv, word, html, pdf files.

  Sources   Download

MIT

The Requires

 

csv extension yii2 excel xls html widget export pdf phpexcel word dompdf phpword

16/04 2017

0.0.4

0.0.4.0

Yii2 It saves data in xls, csv, word, html, pdf files.

  Sources   Download

MIT

The Requires

 

csv extension yii2 excel xls html widget export pdf phpexcel word dompdf phpword

16/04 2017

0.0.3

0.0.3.0

Yii2 It saves data in xls, csv, word, html, pdf files.

  Sources   Download

MIT

The Requires

 

csv extension yii2 excel xls html widget export pdf phpexcel word dompdf phpword

06/08 2016

0.0.2

0.0.2.0

Yii2 It saves data in xls, csv, word, html, pdf files.

  Sources   Download

MIT

The Requires

 

csv extension yii2 excel xls html widget export pdf phpexcel word dompdf phpword

09/07 2016

0.0.1

0.0.1.0

Yii2 It saves data in xls, csv, word, html, pdf files.

  Sources   Download

MIT

The Requires

 

csv extension yii2 excel xls html widget export pdf phpexcel word dompdf phpword