R
R
RedSs2018-12-30 18:55:51
opencart
RedSs, 2018-12-30 18:55:51

Order exel generation when sending email 2.3 opencart?

Hello, there is a code for generating an exel file, how to correctly insert it into /catalog/model/checkout/order.php so that it works (I tried to insert it did not work)
The phpexel library is located in /catalog/model/checkout . The code works if it is run in a separate file directly. It is necessary to send the exel file to the administrator in general

require_once 'Classes/PHPExcel.php';

//$price_list = get_price();

$objPHPExcel = new PHPEXcel();

$objPHPExcel->setActiveSheetIndex(0);

//$objPHPExcel->createSheet();

$active_sheet = $objPHPExcel->getActiveSheet();

$active_sheet->getPageSetup()
            ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
           
$active_sheet->getPageSetup()
            ->SetPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
           
           
$active_sheet->getPageMargins()->setTop(1);
$active_sheet->getPageMargins()->setRight(0.75);
$active_sheet->getPageMargins()->setLeft(0.75);
$active_sheet->getPageMargins()->setBottom(1);

$active_sheet->setTitle("Прайс лист");   


$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(11);   


$active_sheet->getColumnDimension('A')->setWidth(15);
$active_sheet->getColumnDimension('B')->setWidth(20);
$active_sheet->getColumnDimension('C')->setWidth(10);
$active_sheet->getColumnDimension('D')->setWidth(10);

$active_sheet->mergeCells('A1:E1');
$active_sheet->setCellValue('A1','Информация о заказе');

$style_wrap = array(
    'borders'=>array(
        'outline' => array(
            'style'=>PHPExcel_Style_Border::BORDER_THICK
        ),
        'allborders'=>array(
            'style'=>PHPExcel_Style_Border::BORDER_THIN,
            'color' => array(
                'rgb'=>'696969'
            )
        )
   
    )


);

//$active_sheet->getStyle('A1:D'.($i+6))->applyFromArray($style_wrap);


$active_sheet->setCellValue('A2','Номер заказа');
$active_sheet->setCellValue('A3','Дата заказа');
$active_sheet->setCellValue('A4','Способ доставки');
$active_sheet->setCellValue('A5','Предоплата');
$active_sheet->setCellValue('A6','ФИО');
$active_sheet->setCellValue('A7','Телефон');
$active_sheet->setCellValue('A8','Индекс');
$active_sheet->setCellValue('A9','Область');
$active_sheet->setCellValue('A10','Город');
$active_sheet->setCellValue('A11','Адрес');


$active_sheet->mergeCells('B2:E2');
$active_sheet->mergeCells('B3:E3');
$active_sheet->mergeCells('B4:E4');
$active_sheet->mergeCells('B5:E5');
$active_sheet->mergeCells('B6:E6');
$active_sheet->mergeCells('B7:E7');
$active_sheet->mergeCells('B8:E8');
$active_sheet->mergeCells('B9:E9');
$active_sheet->mergeCells('B10:E10');
$active_sheet->mergeCells('B11:E11');


$style_header = array(
    'font'=>array(
        'bold' => true,
        'name' => 'Calibri',
        'size' => 14
    ),
    'alignment' => array(
        'horizontal' => PHPExcel_STYLE_ALIGNMENT::HORIZONTAL_CENTER,
        'vertical' => PHPExcel_STYLE_ALIGNMENT::VERTICAL_CENTER,
    ),
    'fill' => array(
        'type' => PHPExcel_STYLE_FILL::FILL_SOLID,
        'color'=>array(
            'rgb' => 'CFCFCF'
        )
    )


);

$active_sheet->mergeCells('A13:E13');
$active_sheet->setCellValue('A13','Детали заказа');

$active_sheet->getStyle('A1:E1')->applyFromArray($style_header);
$active_sheet->getStyle('A13:E13')->applyFromArray($style_header);



$active_sheet->setCellValue('A14','Артикул');
$active_sheet->setCellValue('B14','Наименование');
$active_sheet->setCellValue('C14','Цена');
$active_sheet->setCellValue('D14','Кол-во');
$active_sheet->setCellValue('E14','Сумма');

$style_slogan = array(
    'fill' => array(
'type' => PHPExcel_STYLE_FILL::FILL_SOLID,

         'color'=>array(
            'rgb' => 'f7fafc'

        )

   
    )


);

$active_sheet->getStyle('A14:E14')->applyFromArray($style_slogan);


$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
//header('Content-Type: application/vnd.ms-excel');
//header('Content-Disposition: attachment;filename="stat.xls"');
//header('Cache-Control: max-age=0');
//$objWriter->save('php://output');
$objWriter->save(str_replace('.php', '.xlsx', "stat.xls"));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question