| Server IP : 104.21.80.248 / Your IP : 172.71.28.155 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Inetpub/www/news/elearning/admin/Import_Excel2007/ |
Upload File : |
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Asia/Bangkok');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** Include PHPExcel */
require_once 'PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("PHPExcel Test Document")
->setSubject("PHPExcel Test Document")
->setDescription("Test document for PHPExcel, generated using PHP classes.")
->setKeywords("office PHPExcel php")
->setCategory("Test result file");
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'ข้อที่')
->setCellValue('B1', 'คำถาม')
->setCellValue('C1', 'ตัวเลือกที่1-ก')
->setCellValue('D1', 'ตัวเลือกที่2-ข')
->setCellValue('E1', 'ตัวเลือกที่3-ค')
->setCellValue('F1', 'ตัวเลือกที่4-ง')
->setCellValue('G1', 'คำตอบ');
// Miscellaneous glyphs, UTF-8
require '../../configs/host.php';
$idsubject=$_GET["idsubject"];
mysql_query( "SET NAMES utf8");
$ql="SELECT
`exp_subjects`.`sb_name`,
`exp_questions_bank`.`qb_subject_id`,
`exp_questions_bank`.`qb_question`,
`exp_questions_bank`.`qb_option1`,
`exp_questions_bank`.`qb_option2`,
`exp_questions_bank`.`qb_option3`,
`exp_questions_bank`.`qb_option4`,
`exp_questions_bank`.`qb_answer`,
`exp_questions_bank`.`sort_order`
FROM
`exp_subjects`
INNER JOIN `exp_questions_bank` ON `exp_subjects`.`sb_id` =
`exp_questions_bank`.`qb_subject_id`
WHERE
`exp_questions_bank`.`qb_subject_id` = $idsubject ";
$qr=mysql_query($ql);
$row_num=mysql_num_rows($qr);
$i = 2;
while($rs = mysql_fetch_array($qr))
{
$objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $rs['sort_order']);
$objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $rs['qb_question']);
$objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $rs['qb_option1']);
$objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $rs['qb_option2']);
$objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $rs['qb_option3']);
$objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $rs['qb_option4']);
$objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $rs['qb_answer']);
$i++;
}
mysql_close($cn);
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
$callStartTime = microtime(true);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
/*
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Export.xlsx"');
header('Cache-Control: max-age=0');
*/
$today=date('dmY');
$file = "$today.xlsx";
header('Content-disposition: attachment; filename='.$file);
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_end_clean();
ob_start();
flush();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
// Save Excel 95 file
$callStartTime = microtime(true);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;