[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/includes/php_writeexcel/ -> example-stocks.php (source)

   1  <?php
   2  
   3  set_time_limit(10);
   4  
   5  require_once  "class.writeexcel_workbook.inc.php";
   6  require_once  "class.writeexcel_worksheet.inc.php";
   7  
   8  $fname = tempnam("/tmp", "merge2.xls");
   9  $workbook = &new writeexcel_workbook($fname);
  10  $worksheet =& $workbook->addworksheet();
  11  
  12  # Set the column width for columns 1, 2, 3 and 4
  13  $worksheet->set_column(0, 3, 15);
  14  
  15  # Create a format for the column headings
  16  $header =& $workbook->addformat();
  17  $header->set_bold();
  18  $header->set_size(12);
  19  $header->set_color('blue');
  20  
  21  # Create a format for the stock price
  22  $f_price =& $workbook->addformat();
  23  $f_price->set_align('left');
  24  $f_price->set_num_format('$0.00');
  25  
  26  # Create a format for the stock volume
  27  $f_volume =& $workbook->addformat();
  28  $f_volume->set_align('left');
  29  $f_volume->set_num_format('#,##0');
  30  
  31  # Create a format for the price change. This is an example of a conditional
  32  # format. The number is formatted as a percentage. If it is positive it is
  33  # formatted in green, if it is negative it is formatted in red and if it is
  34  # zero it is formatted as the default font colour (in this case black).
  35  # Note: the [Green] format produces an unappealing lime green. Try
  36  # [Color 10] instead for a dark green.
  37  #
  38  $f_change =& $workbook->addformat();
  39  $f_change->set_align('left');
  40  $f_change->set_num_format('[Green]0.0%;[Red]-0.0%;0.0%');
  41  
  42  # Write out the data
  43  $worksheet->write(0, 0, 'Company', $header);
  44  $worksheet->write(0, 1, 'Price',   $header);
  45  $worksheet->write(0, 2, 'Volume',  $header);
  46  $worksheet->write(0, 3, 'Change',  $header);
  47  
  48  $worksheet->write(1, 0, 'Damage Inc.'     );
  49  $worksheet->write(1, 1, 30.25,     $f_price);  # $30.25
  50  $worksheet->write(1, 2, 1234567,   $f_volume); # 1,234,567
  51  $worksheet->write(1, 3, 0.085,     $f_change); # 8.5% in green
  52  
  53  $worksheet->write(2, 0, 'Dump Corp.'      );
  54  $worksheet->write(2, 1, 1.56,      $f_price);  # $1.56
  55  $worksheet->write(2, 2, 7564,      $f_volume); # 7,564
  56  $worksheet->write(2, 3, -0.015,    $f_change); # -1.5% in red
  57  
  58  $worksheet->write(3, 0, 'Rev Ltd.'        );
  59  $worksheet->write(3, 1, 0.13,      $f_price);  # $0.13
  60  $worksheet->write(3, 2, 321,       $f_volume); # 321
  61  $worksheet->write(3, 3, 0,         $f_change); # 0 in the font color (black)
  62  
  63  $workbook->close();
  64  
  65  header("Content-Type: application/x-msexcel");
  66  $fh=fopen($fname, "rb");
  67  fpassthru($fh);
  68  unlink($fname);
  69  
  70  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics