<?php
header( 'Content-Type: text/html; charset=utf-8' );
require_once 'config.php';
require_once 'functions.php';
$price_list = get_price();
//$cat_list = get_category();
//foreach($price_list as $item) {
//print_r($item);
//}
//echo '<pre>';
//echo '<pre>'; print_r($price_list); echo '</pre>';
//echo '<pre>'; print_r($cat_list); echo '</pre>';
//echo '</pre>';
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setOutputEncoding('utf-8');
$objPHPExcel->setActiveSheetIndex(0);
$active_sheet = $objPHPExcel->getActiveSheet();
//Ориентация страницы и размер листа
$active_sheet->getPageSetup()
->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT);
$active_sheet->getPageSetup()
->SetPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_EXTRA_PAPER);
//Поля документа
$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("Прайс-лист");
//Шапка и футер
//$active_sheet->getHeaderFooter()->setOddHeader("&CШапка нашего прайс-листа");
$active_sheet->getHeaderFooter()->setOddFooter('&L&B'.$active_sheet->getTitle().'&RСтраница &P из &N');
//Настройки шрифта
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(10);
//Настройки основных полей
$active_sheet->getColumnDimension('A')->setWidth(16);
$active_sheet->getColumnDimension('B')->setWidth(30);
$active_sheet->getColumnDimension('C')->setWidth(40);
//Настройки основных полей
$style_one = array(
//Шрифт
'font'=>array(
'bold' => true,
'name' => 'Times New Roman',
'size' => 16
),
//Выравнивание
'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->getStyle('A1:C1')->applyFromArray($style_one);
$active_sheet->mergeCells('A1:C1');
$active_sheet->getRowDimension('1')->setRowHeight(40);
$active_sheet->setCellValue('A1','Прайс-лист');
//Стили – вторая строка
$style_two = array(
//шрифт
'font'=>array(
'bold' => true,
'name' => 'Times New Roman',
'size' => 18,
),
//выравнивание
'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' => 'ffff00'
)
),
);
$active_sheet->getStyle('A2:C2')->applyFromArray($style_two);
$active_sheet->mergeCells('A2:C2');
$active_sheet->getRowDimension('1')->setRowHeight(40);
$active_sheet->setCellValue('A2','Рояль Текстиль');
//Стили – вторая строка
$style_tree = array(
//шрифт
'font'=>array(
'bold' => true,
'name' => 'Times New Roman',
'size' => 13,
),
//выравнивание
'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->getStyle('A3:C3')->applyFromArray($style_tree);
$active_sheet->mergeCells('A3:C3');
$active_sheet->getRowDimension('1')->setRowHeight(40);
$active_sheet->setCellValue('A3','г. Иваново +7(920) 342 57 58, E-mail: royal-textil@mail.ru');
$style_header = array(
//шрифт
'font'=>array(
'bold' => true,
),
//выравнивание
'alignment' => array(
'horizontal' => PHPExcel_STYLE_ALIGNMENT::HORIZONTAL_CENTER,
'vertical' => PHPExcel_STYLE_ALIGNMENT::VERTICAL_CENTER,
),
);
//Стили – вторая строка
$style_four = array(
//шрифт
'font'=>array(
'bold' => true,
'name' => 'Times New Roman',
'size' => 13,
),
//выравнивание
'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' => 'ffff00'
)
),
);
$active_sheet->getStyle('A4:C4')->applyFromArray($style_four);
$active_sheet->mergeCells('A4:C4');
$active_sheet->getRowDimension('1')->setRowHeight(40);
$active_sheet->setCellValue('A4','Домашний трикотаж оптом и розницу от производителя');
$active_sheet->getStyle('A5:C5')->applyFromArray($style_header);
//Создаем шапку таблички данных
$active_sheet->setCellValue('A5', 'Изображение');
$active_sheet->setCellValue('B5','Название');
$active_sheet->setCellValue('C5','Описание');
//В цикле проходимся по элементам массива и выводим все в соответствующие ячейки
//Стили для слогана компании – вторая строка
$style_slogan = array(
//выравнивание
'alignment' => array(
'horizontal' => PHPExcel_STYLE_ALIGNMENT::HORIZONTAL_CENTER,
'vertical' => PHPExcel_STYLE_ALIGNMENT::VERTICAL_CENTER,
),
);
$row_start = 6;
$i = 0;
foreach($price_list as $item) {
$row_next = $row_start + $i;
$iDrowing = new PHPExcel_Worksheet_Drawing();
$iDrowing->setPath('../'.$item['file_url_thumb']);
$iDrowing->setCoordinates('A'.$row_next);
$iDrowing->setResizeProportional(false);
$iDrowing->setHeight(150);
$iDrowing->setWidth(100);
$iDrowing->setWorksheet($objPHPExcel->getActiveSheet());
//$desc = sprintf($item['product_desc']);
$desc = $item['product_desc'];
//$desc = str_replace("</p>", ", ", $desc);
$desc = strip_tags($desc);
//$active_sheet->setCellValue('A'.$row_next,$item['file_url_thumb']);
$active_sheet->getRowDimension($row_next)->setRowHeight(120);
$active_sheet->getStyle($row_next)->applyFromArray($style_slogan);
$active_sheet->setCellValue('B'.$row_next,$item['product_name']);
$active_sheet->setCellValue('C'.$row_next,$desc);
$i++;
}
header("Content-Type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=price-list.xls");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
ob_end_flush();
exit();
?>
а ВОТ ОТ function
<?php
function get_price() {
$sql = "SELECT a.virtuemart_category_id, a.virtuemart_product_id, c.product_name, c.product_desc, b.product_ordered, d.virtuemart_media_id, d.ordering, p.file_url_thumb ";
$sql .= "FROM skcf0_virtuemart_product_categories AS a ";
$sql .= "left join skcf0_virtuemart_products AS b ON b.virtuemart_product_id = a.virtuemart_product_id ";
$sql .= "left join skcf0_virtuemart_products_ru_ru AS c ON c.virtuemart_product_id = a.virtuemart_product_id ";
$sql .= "left join skcf0_virtuemart_product_medias AS d ON d.virtuemart_product_id = a.virtuemart_product_id ";
$sql .= "left join skcf0_virtuemart_medias AS p ON p.virtuemart_media_id = d.virtuemart_media_id ";
$sql .= "WHERE d.ordering=1 AND b.published=1 ";
$result = mysql_query($sql);
if(!$result) {
exit(mysql_error());
}
$row = array();
for($i = 0;$i < mysql_num_rows($result);$i++) {
$row[] = mysql_fetch_assoc($result);
}
return $row;
}
function get_category() {
$sql = "SELECT a.virtuemart_category_id, a.category_name ";
$sql .= "FROM skcf0_virtuemart_categories_ru_ru AS a ";
$result = mysql_query($sql);
if(!$result) {
exit(mysql_error());
}
$row = array();
for($i = 0;$i < mysql_num_rows($result);$i++) {
$row[] = mysql_fetch_assoc($result);
}
return $row;
}
?>
А вот от config
<?phpпомогите решить проблему уж давно не могу ответа найти хоть как сделать чтобы ошибки отображались
define("HOST","localhost");
define("USER",'******');
define("PASSWORD",'******');
define("DB",'*****');
$db = mysql_connect(HOST,USER,PASSWORD);
if (!$db) {
exit('WRONG CONNECTION');
}
if(!mysql_select_db('****',$db)) {
exit(DB);
}
mysql_query('SET NAMES utf8');
?>