Commit d8aa85f354b9f82004fbf6de9a4878ae1d15dfa9
1 parent
b46a9c6c
add examples for xls and txt parsers
Showing
6 changed files
with
140 additions
and
3 deletions
Show diff stats
examples/UploadFileParsingForm.php
... | ... | @@ -23,6 +23,8 @@ class UploadFileParsingForm extends Model |
23 | 23 | // 1 - csv template file from data/template.csv |
24 | 24 | // 2 - xml template file from data/template.xml |
25 | 25 | // 3 - xlsx template file from data/template.xlsx |
26 | + // 4 - xls template file from data/template.xls | |
27 | + // 5 - txt template file from data/template.txt | |
26 | 28 | public $file_type = 0; |
27 | 29 | |
28 | 30 | |
... | ... | @@ -34,11 +36,11 @@ class UploadFileParsingForm extends Model |
34 | 36 | } |
35 | 37 | JS; |
36 | 38 | return [ |
37 | - ['file_type', 'in', 'range' => range( 0, 3 ) ], | |
39 | + ['file_type', 'in', 'range' => range( 0, 5 ) ], | |
38 | 40 | ['file', 'required', 'when' => function(){ |
39 | 41 | return !$this->file_type; |
40 | 42 | } , 'whenClient' => $client_func], |
41 | - [['file'], 'file', 'extensions' => ['csv', 'xlsx', 'xml'], 'checkExtensionByMimeType' => false ], | |
43 | + [['file'], 'file', 'extensions' => ['csv', 'xlsx', 'xml', 'xls', 'txt'], 'checkExtensionByMimeType' => false ], | |
42 | 44 | ['file_path', 'safe'], |
43 | 45 | |
44 | 46 | ]; | ... | ... |
1 | +Áðåíä Íàèìåíîâàíèå Öåíà çàêóïêè Îñòàòîê | |
2 | +EL ZIP THERPR L Êóðòêà ÷îëîâ³÷à ñèíòåòè÷íà 2610.0000 2 | |
3 | +EL ZIP THERPR XL Êóðòêà 2610.0000 3 | |
4 | +EL ZIP THERPR XXL Êóðòêà 2610.0000 2 | |
5 | +ES REKL045 Ñåêàòîð 433.6900 3 | |
6 | +ES REKL060 Ñåðòèôiêàò ïîäàðóíêîâèé 476.8500 7 | |
7 | +ES REKL067 Ñåðòèôiêàò ïîäàðóíêîâèé 866.7800 1 | |
8 | +ES REKL072 Ñåðòèôiêàò ïîäàðóíêîâèé 1103.2500 4 | |
9 | +ES REKL083 Ñåðòèôiêàò ïîäàðóíêîâèé 1892.2500 5 | |
10 | +ES REKL103 Ñåðòèôiêàò ïîäàðóíêîâèé 3467.6500 2 | |
11 | +ES REKL115 Íiæ ãîñïîäàðñüêèé 790.0500 5 | |
12 | +ES REKL138 Ïîäàðóíêîâèé Ñåðòèô³êàò 2088.0000 2 | |
13 | + | ... | ... |
No preview for this file type
examples/config.php
... | ... | @@ -86,7 +86,7 @@ return [ |
86 | 86 | ], |
87 | 87 | 'template' => |
88 | 88 | ['class' => 'yii\multiparser\XlsxParser', |
89 | - 'path_for_extract_files' => $_SERVER["DOCUMENT_ROOT"] . 'tests/_data/xlsx_tmp', | |
89 | + 'path_for_extract_files' => $_SERVER["DOCUMENT_ROOT"] . '/tests/_data/xlsx_tmp/', | |
90 | 90 | 'keys' => [ |
91 | 91 | 0 => 'Original', |
92 | 92 | 1 => 'Replacement', |
... | ... | @@ -101,5 +101,63 @@ return [ |
101 | 101 | "Count" => 'Количество', |
102 | 102 | ], |
103 | 103 | ], |
104 | + 'xls' => | |
105 | + ['custom' => | |
106 | + ['class' => 'yii\multiparser\XlsParser', | |
107 | + ], | |
108 | + 'template' => | |
109 | + ['class' => 'yii\multiparser\XlsParser', | |
110 | + 'converter_conf' => [ | |
111 | + 'class' => ' yii\multiparser\Converter', | |
112 | + 'configuration' => ["encode" => [], | |
113 | + ] | |
114 | + ],], | |
115 | + | |
116 | + 'basic_column' => [ | |
117 | + Null => 'Пусто', | |
118 | + "BRAND" => 'Бренд', | |
119 | + "ARTICLE" => 'Артикул', | |
120 | + "PRICE" => 'Цена', | |
121 | + "DESCR" => 'Наименование', | |
122 | + "BOX" => 'Колво', | |
123 | + "ADD_BOX" => 'В пути', | |
124 | + "GROUP" => 'Группа RG' | |
125 | + ], | |
126 | + ], | |
127 | + 'txt' => | |
128 | + ['custom' => | |
129 | + ['class' => 'yii\multiparser\CsvParser', | |
130 | + 'delimiter' => "\t", | |
131 | + 'converter_conf' => [ | |
132 | + 'class' => 'yii\multiparser\Converter', | |
133 | + 'configuration' => ["encode" => []], | |
134 | + ] | |
135 | + ], | |
136 | + 'template' => | |
137 | + ['class' => 'yii\multiparser\CsvParser', | |
138 | + 'delimiter' => "\t", | |
139 | + 'keys' => [ | |
140 | + 0 => 'Brand', | |
141 | + 1 => 'Article', | |
142 | + 2 => 'Price', | |
143 | + 4 => 'Count', | |
144 | + ], | |
145 | + 'converter_conf' => [ | |
146 | + 'class' => 'yii\multiparser\Converter', | |
147 | + 'configuration' => ["encode" => 'Brand', | |
148 | + "float" => 'Price', | |
149 | + "integer" => 'Count' | |
150 | + ] | |
151 | + ],], | |
152 | + | |
153 | + 'basic_column' => [ | |
154 | + Null => 'null', | |
155 | + "Description" => 'Название', | |
156 | + "Article" => 'Артикул', | |
157 | + "Price" => 'Цена', | |
158 | + "Brand" => 'Производитель', | |
159 | + "Count" => 'Количество', | |
160 | + ], | |
161 | + ], | |
104 | 162 | ]; |
105 | 163 | ... | ... |
1 | +<?php | |
2 | +use yii\widgets\ActiveForm; | |
3 | +use yii\helpers\Html; | |
4 | +use yii\helpers\ArrayHelper; | |
5 | + | |
6 | +?> | |
7 | +<div class="row"> | |
8 | + <div class="col-lg-5"> | |
9 | + <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data',],'action'=>['parser/read']]); | |
10 | + ?> | |
11 | + <h3>Choose file to parse</h3> | |
12 | + | |
13 | + <?= $form->field($model, 'file')->fileInput() ?> | |
14 | + | |
15 | + <?= $form->field($model, 'file_type')->radioList([0 => 'Custom file', 1 => 'csv template', 2 => 'xml template', 3 => 'xlsx template', 4 => 'xls template', 5 => 'txt template'])->label(false); | |
16 | + ?> | |
17 | + | |
18 | + <div class="form-group"> | |
19 | + <?= Html::submitButton('Read', ['class' => 'btn btn-primary']) ?> | |
20 | + </div> | |
21 | + | |
22 | + <?php ActiveForm::end(); | |
23 | + ?> | |
24 | + </div> | |
25 | +</div> | |
26 | + | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\multiparser\DynamicFormHelper; | |
5 | +use yii\widgets\ActiveForm; | |
6 | + | |
7 | + | |
8 | +/* @var $this yii\web\View */ | |
9 | +/* @var $searchModel backend\models\CatalogSearch */ | |
10 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
11 | + | |
12 | +$this->title = 'Results'; | |
13 | +$this->params['breadcrumbs'][] = $this->title; | |
14 | +?> | |
15 | +<div class="catalog-index"> | |
16 | + | |
17 | + <h1><?= Html::encode($this->title) ?></h1> | |
18 | + <?php | |
19 | + | |
20 | + $form = ActiveForm::begin(['action' => 'write']); | |
21 | + | |
22 | + if (empty( $header_model )) { | |
23 | + // выведем просто массив без колонок выбора | |
24 | + echo \yii\grid\GridView::widget([ | |
25 | + 'dataProvider' => $dataProvider, | |
26 | + // 'layout'=>"{pager}\n{items}", | |
27 | + | |
28 | + ]); | |
29 | + | |
30 | + } else { | |
31 | + echo DynamicFormHelper::CreateGridWithDropDownListHeader($dataProvider, $form, $header_model, $basic_column); | |
32 | + } | |
33 | + ?> | |
34 | + | |
35 | + <?php ActiveForm::end() ?> | |
36 | + <?= Html::a('Return', ['parser/index'], ['class' => 'btn btn-primary', 'name' => 'Return',]) ?> | |
37 | + | |
38 | +</div> | |
0 | 39 | \ No newline at end of file | ... | ... |