Guest User

Untitled

a guest
Dec 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. include 'setup.php';
  2. _connectsurvey(); //Database
  3. require_once 'PHPExcel.php';
  4.  
  5. $objPHPExcel = new PHPExcel();
  6.  
  7. $query = "SELECT * FROM questionanswer";
  8.  
  9. $result = mysql_query($query) or die(mysql_error());
  10.  
  11. $objPHPExcel = new PHPExcel();
  12.  
  13. $rowCount = 1;
  14.  
  15. while($row = mysql_fetch_array($result)){
  16. $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $row['gender']);
  17.  
  18. $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $row['city']);
  19. $rowCount++;
  20. pr($objPHPExcel);
  21. }
  22.  
  23. header('Content-Type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet');
  24. header('Content-Disposition: attachment;filename="survey.xls"');
  25. header('Cache-Control: max-age=0');
  26.  
  27. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  28. $objWriter->save('php://output');
  29.  
  30. header('Content-Disposition: attachment;filename="survey.xlsx"');
  31.  
  32. require('../phpexcel/PHPExcel.php');
  33.  
  34. require('../phpexcel/PHPExcel/Writer/Excel5.php');
  35.  
  36. $filename = 'userReport'; //your file name
  37.  
  38. $objPHPExcel = new PHPExcel();
  39. /*********************Add column headings START**********************/
  40. $objPHPExcel->setActiveSheetIndex(0)
  41. ->setCellValue('A1', 'username')
  42. ->setCellValue('B1', 'city_name');
  43.  
  44. /*********************Add data entries START**********************/
  45. //get_result_array_from_class**You can replace your sql code with this line.
  46.  
  47. $result = $get_report_clas->get_user_report();
  48.  
  49. //set variable for count table fields.
  50. $num_row = 1;
  51. foreach ($result as $value) {
  52. $user_name = $value['username'];
  53. $c_code = $value['city_name'];
  54. $num_row++;
  55. $objPHPExcel->setActiveSheetIndex(0)
  56. ->setCellValue('A'.$num_row, $user_name )
  57. ->setCellValue('B'.$num_row, $c_code );
  58. }
  59.  
  60. /*********************Autoresize column width depending upon contents START**********************/
  61. foreach(range('A','B') as $columnID) {
  62. $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
  63. }
  64. $objPHPExcel->getActiveSheet()->getStyle('A1:B1')->getFont()->setBold(true);
  65.  
  66.  
  67.  
  68. //Make heading font bold
  69. /*********************Add color to heading START**********************/
  70. $objPHPExcel->getActiveSheet()
  71. ->getStyle('A1:B1')
  72. ->getFill()
  73. ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  74. ->getStartColor()
  75. ->setARGB('99ff99');
  76.  
  77. $objPHPExcel->getActiveSheet()->setTitle('userReport'); //give title to sheet
  78. $objPHPExcel->setActiveSheetIndex(0);
  79. header('Content-Type: application/vnd.ms-excel');
  80. header("Content-Disposition: attachment;Filename=$filename.xls");
  81. header('Cache-Control: max-age=0');
  82. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  83. $objWriter->save('php://output');
Add Comment
Please, Sign In to add comment