Answer the question
In order to leave comments, you need to log in
Yii upload to excel?
How can I connect phpexcel and, when clicked, return a document with the content from the request\array?
that's what I did so far
----------------
I'm trying to install phpexcel vendor
d:\open\openserver>cd D:\open\OpenServer\domains\localhost\mining\protected
D:\open\OpenServer\domains\localhost\mining\protected>composer require "yiisoft/yii:@stable"
D:\open\OpenServer\domains\localhost\mining\protected>composer require "phpoffice/phpexcel:@stable"
D:\open\OpenServer\domains\localhost\mining\protected>composer require laxu/yii-phpexcel
public function writeExcelFile() //\analiz\models\Element.php
{
$manager = Yii::app()->getComponent('yii-phpexcel');
//Create empty instance
$excel = $manager->create();
//Add a header row with a grey background
$headerStyle = array(
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'CCCCCC')
)
);
$excel->addHeaderRow(
array(
'header1',
'header2',
'header3'
),
$headerStyle
);
//Add a few rows of data to the document
//Note that addData doesn't care about the actual keys in the data, only the order of values
$data = array(
array(
'data1',
'data2',
'data3',
),
array(
'id' => 1,
'name' => 'Example',
'moreData' => 'Something'
)
);
$excel->addData($data);
$excel->save();
}
CException
Invalid alias "laxu.yii_phpexcel". Make sure it points to an existing directory or file.
// application components
'components' => array(
'yii-phpexcel' => array(
'class' => '\laxu\yii_phpexcel\ExcelManager',
'savePath' => 'app.files.excel'
),
Answer the question
In order to leave comments, you need to log in
Recently I solved a similar problem =)
I solved it like this:
Install via composer https://github.com/AlexGx/yii2-phpexcel
Then
<?php
namespace backend\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use backend\models\Price;
use alexgx\phpexcel;
class PriceController extends Controller {
...
public function actionUpdate() {
$model = new Price();
$h1StyleArray = [
'font' => [
'color' => ['rgb' => '691e1e'],
'bold' => true,
'name' => 'Times New Roman',
'size' => 20
],
'alignment' => [
'horizontal' => 'center'
]
];
$cl = new \alexgx\phpexcel\PhpExcel();
$xls = $cl->create();
$xls->setActiveSheetIndex(0);
$sheet = $xls->getActiveSheet();
$xls->getActiveSheet()->mergeCells('A1:F1');
$sheet->setCellValue('A1', 'Дизайнерский дом ...');
$sheet->getStyle('A1')->applyFromArray($h1StyleArray);
...
$cl->responseFile($xls, '222.xlsx', 'Excel2007');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question