PDA

View Full Version : ایجاد اکسل در php



olampiad
سه شنبه 05 آبان 1394, 12:04 عصر
سلام و خسته نباشید به دوستان عزیز
من میخوام خروجی اکسل از دیتابیسم بگیرم.
یعنی میخوام از هر جدولم خروجی اکسل داشته باشم.
به جداولم ی نگا بندازید (تصاویر رو زمیمه کردم)
مثلا به جان name نام قرار میدم در تیتر ها.
تو اینترنت خیلی جست و جو کردم و روش های مختلفی بود.
بهترین روشی که ارائه کرده بون استفاده از phpexcel بود.
من این کتابخونه رو دانلود کردم ولی نمیتونم باهاش کارکنم.
تو اینترنت نمونه کد های زیادی بود:

خواستم ببینم آیا شما دوستان کد آماده ای برای کار با این کتابخونه دارید.
من میخوام خیلی ساده و بدون پیچیدگی دیتابیسم رو به اکسل تبدیل کنم.


الآن به این کد ی نگ بندازید.
این کد ی اکسل ساده میسازه:
همونطور که میبیند اینجا جدول رو از چپ به راست ساخته.
چیکار کنم جدول رو از راست به چپ بسازه.
خیلی خیلی خیلی ممنون



<?phprequire_once 'lib/PHPExcel.php';$objPHPExcel = new PHPExcel(); // Create new PHPExcel object
$objPHPExcel = new PHPExcel(); // Create new PHPExcel object$objPHPExcel->getProperties()->setCreator("Sigit prasetya n") ->setLastModifiedBy("Sigit prasetya n") ->setTitle("Creating file excel with php Test Document") ->setSubject("Creating file excel with php Test Document") ->setDescription("How to Create Excel file from PHP with PHPExcel 1.8.0 Classes by seegatesite.com.") ->setKeywords("phpexcel") ->setCategory("Test result file");// create style$default_border = array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb'=>'1006A3'));$style_header = array( 'borders' => array( 'bottom' => $default_border, 'left' => $default_border, 'top' => $default_border, 'right' => $default_border, ), 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb'=>'E1E0F7'), ), 'font' => array( 'bold' => true, 'size' => 16, ));$style_content = array( 'borders' => array( 'bottom' => $default_border, 'left' => $default_border, 'top' => $default_border, 'right' => $default_border, ), 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb'=>'eeeeee'), ), 'font' => array( 'size' => 12, ));// Create Header$objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', 'NO') ->setCellValue('B1', 'PRODUCT CODE') ->setCellValue('C1', 'TITLE');$objPHPExcel->getActiveSheet()->getStyle('A1:C1')->applyFromArray( $style_header ); // give style to header // Create Data$dataku=array( array('C001','Iphone 6'), array('C002','Samsung Galaxy S4'), array('C003','Nokia Lumia'), array('C004','Blackberry Curve'));$firststyle='A2';for($i=0;$i<count($dataku);$i++){ $urut=$i+2; $num='A'.$urut; $code='B'.$urut; $title='C'.$urut; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($num, $i+1) ->setCellValue($code, $dataku[$i][0]) ->setCellValue($title, $dataku[$i][1]); $laststyle=$title;}$objPHPExcel->getActiveSheet()->getStyle($firststyle.':'.$laststyle)->applyFromArray( $style_content ); // give style to header // Rename worksheet$objPHPExcel->getActiveSheet()->setTitle('Product');// Set active sheet index to the first sheet, so Excel opens this as the first sheet$objPHPExcel->setActiveSheetIndex(0);// Redirect output to a client’s web browser (Excel5)header('Content-Type: application/vnd.ms-excel');header('Content-Disposition: attachment;filename="listproduct.xls"'); // file name of excelheader('Cache-Control: max-age=0');// If you're serving to IE 9, then the following may be neededheader('Cache-Control: max-age=1');// If you're serving to IE over SSL, then the following may be neededheader ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the pastheader ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modifiedheader ('Cache-Control: cache, must-revalidate'); // HTTP/1.1header ('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');$objWriter->save('php://output');
?>

olampiad
سه شنبه 05 آبان 1394, 12:10 عصر
اینم کد ها
http://s3.picofile.com/file/8219424118/index.php.html
ممنون