3 * Module written by Herman Kuiper <herman@ozuzo.net>
7 * Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
8 * Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 //require_once('PEAR.php');
27 // Possible operator types
30 FIXME: change prefixes
32 define("OP_BETWEEN", 0x00);
33 define("OP_NOTBETWEEN", 0x01);
34 define("OP_EQUAL", 0x02);
35 define("OP_NOTEQUAL", 0x03);
36 define("OP_GT", 0x04);
37 define("OP_LT", 0x05);
38 define("OP_GTE", 0x06);
39 define("OP_LTE", 0x07);
42 * Baseclass for generating Excel DV records (validations)
44 * @author Herman Kuiper
45 * @category FileFormats
46 * @package Spreadsheet_Excel_Writer
48 class Spreadsheet_Excel_Writer_Validator
65 * The parser from the workbook. Used to parse validation formulas also
66 * @var Spreadsheet_Excel_Writer_Parser
70 function Spreadsheet_Excel_Writer_Validator(&$parser)
72 $this->_parser
= $parser;
73 $this->_type
= 0x01; // FIXME: add method for setting datatype
75 $this->_fixedList
= false;
76 $this->_blank
= false;
77 $this->_incell
= false;
78 $this->_showprompt
= false;
79 $this->_showerror
= true;
80 $this->_title_prompt
= "\x00";
81 $this->_descr_prompt
= "\x00";
82 $this->_title_error
= "\x00";
83 $this->_descr_error
= "\x00";
84 $this->_operator
= 0x00; // default is equal
85 $this->_formula1
= '';
86 $this->_formula2
= '';
89 function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true)
91 $this->_showprompt
= $showPrompt;
92 $this->_title_prompt
= $promptTitle;
93 $this->_descr_prompt
= $promptDescription;
96 function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true)
98 $this->_showerror
= $showError;
99 $this->_title_error
= $errorTitle;
100 $this->_descr_error
= $errorDescription;
103 function allowBlank()
105 $this->_blank
= true;
108 function onInvalidStop()
110 $this->_style
= 0x00;
113 function onInvalidWarn()
115 $this->_style
= 0x01;
118 function onInvalidInfo()
120 $this->_style
= 0x02;
123 function setFormula1($formula)
125 // Parse the formula using the parser in Parser.php
126 $error = $this->_parser
->parse($formula);
127 if (PEAR
::isError($error)) {
128 return $this->_formula1
;
131 $this->_formula1
= $this->_parser
->toReversePolish();
132 if (PEAR
::isError($this->_formula1
)) {
133 return $this->_formula1
;
138 function setFormula2($formula)
140 // Parse the formula using the parser in Parser.php
141 $error = $this->_parser
->parse($formula);
142 if (PEAR
::isError($error)) {
143 return $this->_formula2
;
146 $this->_formula2
= $this->_parser
->toReversePolish();
147 if (PEAR
::isError($this->_formula2
)) {
148 return $this->_formula2
;
153 function _getOptions()
155 $options = $this->_type
;
156 $options |
= $this->_style
<< 3;
157 if ($this->_fixedList
) {
163 if (!$this->_incell
) {
166 if ($this->_showprompt
) {
169 if ($this->_showerror
) {
172 $options |
= $this->_operator
<< 20;
179 $title_prompt_len = strlen($this->_title_prompt
);
180 $descr_prompt_len = strlen($this->_descr_prompt
);
181 $title_error_len = strlen($this->_title_error
);
182 $descr_error_len = strlen($this->_descr_error
);
184 $formula1_size = strlen($this->_formula1
);
185 $formula2_size = strlen($this->_formula2
);
187 $data = pack("V", $this->_getOptions());
188 $data .= pack("vC", $title_prompt_len, 0x00) . $this->_title_prompt
;
189 $data .= pack("vC", $title_error_len, 0x00) . $this->_title_error
;
190 $data .= pack("vC", $descr_prompt_len, 0x00) . $this->_descr_prompt
;
191 $data .= pack("vC", $descr_error_len, 0x00) . $this->_descr_error
;
193 $data .= pack("vv", $formula1_size, 0x0000) . $this->_formula1
;
194 $data .= pack("vv", $formula2_size, 0x0000) . $this->_formula2
;
200 /*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation
202 function Spreadsheet_Excel_Writer_Validation_list()
204 parent::Spreadsheet_Excel_Writer_Validation();
208 function setList($source, $incell = true)
210 $this->_incell = $incell;
211 $this->_fixedList = true;
213 $source = implode("\x00", $source);
214 $this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source;
217 function setRow($row, $col1, $col2, $incell = true)
219 $this->_incell = $incell;
220 //$this->_formula1 = ...;
223 function setCol($col, $row1, $row2, $incell = true)
225 $this->_incell = $incell;
226 //$this->_formula1 = ...;