Advertisement
GWibisono

phpexcel.net make excel using php part 2

May 27th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. <?php
  2. if($_POST)
  3. {
  4.     $aData=$_POST['txt'];
  5.     $sType='2007 XLSX';
  6.     error_reporting(E_ALL);
  7.     date_default_timezone_set('Europe/London');
  8.     require_once 'Classes/PHPExcel.php';
  9.     $objPHPExcel = new PHPExcel();
  10.     $objPHPExcel->getProperties()->setCreator("Nasgor")
  11.      ->setLastModifiedBy("Gunawan")
  12.      ->setTitle("Office  Test Document")
  13.      ->setSubject("Office $sType Test Document")
  14.      ->setDescription("Test document for Office $sType, generated using PHP classes.")
  15.      ->setKeywords("office $sType openxml php")
  16.      ->setCategory("Test result file");
  17.      
  18.     foreach($aData as $posY=>$aData2)
  19.     {
  20.         for($i=1;$i<6;$i++){ //count($aData2)
  21.             $pos=chr(64+$i).($posY+1);
  22.             $aData2[$i]?$dt=addslashes($aData2[$i]):$dt='';
  23.             $objPHPExcel->setActiveSheetIndex(0)
  24.                 ->setCellValue($pos,$dt );
  25.         }
  26.     }
  27.      
  28.     $objPHPExcel->getActiveSheet()->setTitle('Testing');
  29.  
  30.     $writeAs='Excel2007';
  31.     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $writeAs);
  32.      
  33.     $objWriter->save('tmp/003data.xlsx');
  34.      
  35.     header('location:?stat=open');
  36.     die();
  37. }
  38. if($_GET['stat']=='open')
  39. {
  40.     header('Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') ;
  41.     $fName='tmp/003data.xlsx';
  42.     header('Content-Disposition: attachment; filename="003.xlsx"');
  43.     $f=file_get_contents($fName);
  44.     echo $f;
  45.      
  46.     die();
  47. }
  48. ?><form method="post"  enctype='multipart/form-data'>  
  49. <table border=1>
  50. <tr><th>&nbsp;</th><th>A</TH><TH>B</TH><TH>C</TH><TH>D</TH><TH>E</TH></TR>
  51. <?php
  52. for($i=0;$i<5;$i++)
  53. {
  54.     $s.='<tr><td>'.++$n."</td>";
  55.     for($j=1;$j<6;$j++)
  56.     {
  57.         $s.="<td><input type=text
  58.        name='txt[$i][$j]' size=6 />";
  59.     }
  60.     $s.="<tr>\\n";
  61. }
  62. echo $s;
  63. ?>
  64.  
  65. </table>
  66. <br><input name=stat type=submit value='input' />
  67. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement