Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include 'setup.php';
- _connectsurvey(); //Database
- require_once 'PHPExcel.php';
- $objPHPExcel = new PHPExcel();
- $query = "SELECT * FROM questionanswer";
- $result = mysql_query($query) or die(mysql_error());
- $objPHPExcel = new PHPExcel();
- $rowCount = 1;
- while($row = mysql_fetch_array($result)){
- $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $row['gender']);
- $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $row['city']);
- $rowCount++;
- pr($objPHPExcel);
- }
- header('Content-Type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet');
- header('Content-Disposition: attachment;filename="survey.xls"');
- header('Cache-Control: max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
- $objWriter->save('php://output');
- header('Content-Disposition: attachment;filename="survey.xlsx"');
- require('../phpexcel/PHPExcel.php');
- require('../phpexcel/PHPExcel/Writer/Excel5.php');
- $filename = 'userReport'; //your file name
- $objPHPExcel = new PHPExcel();
- /*********************Add column headings START**********************/
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', 'username')
- ->setCellValue('B1', 'city_name');
- /*********************Add data entries START**********************/
- //get_result_array_from_class**You can replace your sql code with this line.
- $result = $get_report_clas->get_user_report();
- //set variable for count table fields.
- $num_row = 1;
- foreach ($result as $value) {
- $user_name = $value['username'];
- $c_code = $value['city_name'];
- $num_row++;
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A'.$num_row, $user_name )
- ->setCellValue('B'.$num_row, $c_code );
- }
- /*********************Autoresize column width depending upon contents START**********************/
- foreach(range('A','B') as $columnID) {
- $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
- }
- $objPHPExcel->getActiveSheet()->getStyle('A1:B1')->getFont()->setBold(true);
- //Make heading font bold
- /*********************Add color to heading START**********************/
- $objPHPExcel->getActiveSheet()
- ->getStyle('A1:B1')
- ->getFill()
- ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
- ->getStartColor()
- ->setARGB('99ff99');
- $objPHPExcel->getActiveSheet()->setTitle('userReport'); //give title to sheet
- $objPHPExcel->setActiveSheetIndex(0);
- header('Content-Type: application/vnd.ms-excel');
- header("Content-Disposition: attachment;Filename=$filename.xls");
- header('Cache-Control: max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
Add Comment
Please, Sign In to add comment