Advertisement
academo

Untitled

Apr 25th, 2011
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. App::import("Vendor", "writeexcel_workbook", array("file"=>"excel/class.writeexcel_workbook.inc.php"));
  3. class ExcelHelper extends AppHelper {
  4.  
  5.     public function generate(){
  6.         $fname = tempnam("/tmp", "simple.xls");
  7.         $workbook = &new writeexcel_workbook($fname);
  8.         $worksheet = &$workbook->addworksheet();
  9.  
  10.         # The general syntax is write($row, $column, $token). Note that row and
  11.         # column are zero indexed
  12.         #
  13.  
  14.         # Write some text
  15.         $worksheet->write(0, 0,  "Hi Excel!");
  16.  
  17.         # Write some numbers
  18.         $worksheet->write(2, 0,  3);          # Writes 3
  19.         $worksheet->write(3, 0,  3.00000);    # Writes 3
  20.         $worksheet->write(4, 0,  3.00001);    # Writes 3.00001
  21.         $worksheet->write(5, 0,  3.14159);    # TeX revision no.?
  22.  
  23.         # Write two formulas
  24.         $worksheet->write(7, 0,  '=A3 + A6');
  25.         $worksheet->write(8, 0,  '=IF(A5>3,"Yes", "No")');
  26.  
  27.         # Write a hyperlink
  28.         $worksheet->write(10, 0, 'http://www.php.net/');
  29.  
  30.         $workbook->close();
  31.  
  32.         header("Content-Type: application/x-msexcel; name=\"example-simple.xls\"");
  33.         header("Content-Disposition: inline; filename=\"example-simple.xls\"");
  34.         $fh=fopen($fname, "rb");
  35.         fpassthru($fh);
  36.         unlink($fname);
  37.  
  38.     }
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement