"Fossies" - the Fresh Open Source Software Archive 
Member "php_writeexcel-0.3.0/example-colors.php" (1 Nov 2005, 3419 Bytes) of package /linux/www/old/php_writeexcel-0.3.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "example-colors.php" see the
Fossies "Dox" file reference documentation.
1 <?php
2
3 # Demonstrates Spreadsheet::WriteExcel's named colors and the Excel
4 # color palette.
5 #
6 # reverse('©'), March 2002, John McNamara, jmcnamara@cpan.org
7
8 # PHP port by Johann Hanne, 2005-11-01
9
10 set_time_limit(10);
11
12 require_once "class.writeexcel_workbook.inc.php";
13 require_once "class.writeexcel_worksheet.inc.php";
14
15 $fname = tempnam("/tmp", "colors.xls");
16 $workbook = &new writeexcel_workbook($fname);
17
18 # Some common formats
19 $center =& $workbook->addformat(array('align' => 'center'));
20 $heading =& $workbook->addformat(array('align' => 'center', 'bold' => 1));
21
22 # Try this to see the default Excel 5 palette
23 # $workbook->set_palette_xl5();
24
25 ######################################################################
26 #
27 # Demonstrate the named colors.
28 #
29
30 $colors = array(
31 'black'=>0x08,
32 'blue'=>0x0C,
33 'brown'=>0x10,
34 'cyan'=>0x0F,
35 'gray'=>0x17,
36 'green'=>0x11,
37 'lime'=>0x0B,
38 'magenta'=>0x0E,
39 'navy'=>0x12,
40 'orange'=>0x35,
41 'purple'=>0x14,
42 'red'=>0x0A,
43 'silver'=>0x16,
44 'white'=>0x09,
45 'yellow'=>0x0D
46 );
47
48 $worksheet1 =& $workbook->addworksheet('Named colors');
49
50 $worksheet1->set_column(0, 3, 15);
51
52 $worksheet1->write(0, 0, "Index", $heading);
53 $worksheet1->write(0, 1, "Index", $heading);
54 $worksheet1->write(0, 2, "Name", $heading);
55 $worksheet1->write(0, 3, "Color", $heading);
56
57 $i = 1;
58
59 foreach ($colors as $color=>$index) {
60 $format =& $workbook->addformat(array(
61 'fg_color' => $color,
62 'pattern' => 1,
63 'border' => 1
64 ));
65
66 $worksheet1->write($i+1, 0, $index, $center);
67 $worksheet1->write($i+1, 1, sprintf("0x%02X", $index), $center);
68 $worksheet1->write($i+1, 2, $color, $center);
69 $worksheet1->write($i+1, 3, '', $format);
70 $i++;
71 }
72
73
74 ######################################################################
75 #
76 # Demonstrate the standard Excel colors in the range 8..63.
77 #
78
79 $worksheet2 =& $workbook->addworksheet('Standard colors');
80
81 $worksheet2->set_column(0, 3, 15);
82
83 $worksheet2->write(0, 0, "Index", $heading);
84 $worksheet2->write(0, 1, "Index", $heading);
85 $worksheet2->write(0, 2, "Color", $heading);
86 $worksheet2->write(0, 3, "Name", $heading);
87
88 for ($i=8;$i<=63;$i++) {
89 $format =& $workbook->addformat(array(
90 'fg_color' => $i,
91 'pattern' => 1,
92 'border' => 1
93 ));
94
95 $worksheet2->write(($i -7), 0, $i, $center);
96 $worksheet2->write(($i -7), 1, sprintf("0x%02X", $i), $center);
97 $worksheet2->write(($i -7), 2, '', $format);
98
99 # Add the color names
100 foreach ($colors as $color=>$index) {
101 if ($i==$index) {
102 $worksheet2->write(($i -7), 3, $color, $center);
103 }
104 }
105 }
106
107 $workbook->close();
108
109 header("Content-Type: application/x-msexcel; name=\"example-colors.xls\"");
110 header("Content-Disposition: inline; filename=\"example-colors.xls\"");
111 $fh=fopen($fname, "rb");
112 fpassthru($fh);
113 unlink($fname);
114
115 ?>