Advertisement
johncarlson21

php excel

Sep 24th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. $c=1;
  4. while($row = mysql_result($query)) {
  5.  
  6. // put your data into an array that will match the columns
  7. $data = array(
  8. '', // will be an empty because there is no column 0
  9. $row['last'], // will be for column A
  10. $row['first'],// will be for column B
  11. $row['phone']
  12. );
  13. // your also going to have to have something here for letters
  14. $alpha = array(
  15. '', // need an empty
  16. 'A',
  17. 'B',
  18. 'C', // etc..
  19. );
  20.  
  21. // set active sheet
  22. $objPHPExcel->setActiveSheetIndex(0);
  23.  
  24. // now for a loop to put it together
  25. for($i=0; $i<count($data); $i++) {
  26.  
  27. // make sure we aren't looking at the empty one
  28. if ($i > 0) {
  29. $objPHPExcel->setCellValue($alpha[$i].$c, $data[$i]);
  30. // example: $objPHPExcel->setCellValue('A1', 'Carlson');
  31. }// end if
  32.  
  33. }// end for loop
  34.  
  35. // increment counter for the row
  36. $c++;
  37.  
  38. }// end while
  39.  
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement