1: <?php
2: /**
3: * LICENSE (BSD)
4: *
5: * Copyright (c) 2013, Gerd Christian Kunze
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions are
10: * met:
11: *
12: * * Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: *
15: * * Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: *
19: * * Neither the name of Gerd Christian Kunze nor the names of the
20: * contributors may be used to endorse or promote products derived from
21: * this software without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34: *
35: * Value
36: * 25.02.2013 16:06
37: */
38: namespace MOC\Module\Office\Document\Excel\Cell;
39: use MOC\Api;
40: use MOC\Generic\Device\Module;
41: use MOC\Module\Drive\File;
42:
43: /**
44: *
45: */
46: class Value implements Module {
47: /**
48: * Get Changelog
49: *
50: * @static
51: * @return \MOC\Core\Changelog
52: */
53: public static function InterfaceChangelog() {
54: return Api::Core()->Changelog()->Create( __CLASS__ );
55: }
56:
57: /**
58: * Get Dependencies
59: *
60: * @static
61: * @return \MOC\Core\Depending
62: */
63: public static function InterfaceDepending() {
64: return Api::Core()->Depending();
65: }
66:
67: /**
68: * Get Singleton/Instance
69: *
70: * @static
71: * @return Value
72: */
73: public static function InterfaceInstance() {
74: return new Value();
75: }
76:
77: /**
78: * @param mixed $Value
79: * @return \MOC\Module\Office\Document\Excel
80: */
81: public function Set( $Value ) {
82: // Prepare UTF8
83: $Value = Api::Core()->Encoding()->MixedToUtf8( $Value );
84: // Reset Cell-Format
85: $this->getNumberFormat()->setFormatCode( \PHPExcel_Style_NumberFormat::FORMAT_GENERAL );
86: $this->getCell()->setValue( $Value );
87: return Api::Module()->Office()->Document()->Excel();
88: }
89:
90: /**
91: * @param mixed $Value
92: * @return \MOC\Module\Office\Document\Excel
93: */
94: public function String( $Value ) {
95: // Prepare UTF8
96: $Value = Api::Core()->Encoding()->MixedToUtf8( $Value );
97: // Set Cell-Format: TEXT
98: $this->getNumberFormat()->setFormatCode( \PHPExcel_Style_NumberFormat::FORMAT_TEXT );
99: $this->getCell()->setValueExplicit( $Value, \PHPExcel_Cell_DataType::TYPE_STRING );
100: return Api::Module()->Office()->Document()->Excel();
101: }
102:
103: /**
104: * @param mixed $Value
105: * @return \MOC\Module\Office\Document\Excel
106: */
107: public function Formula( $Value ) {
108: // Reset Cell-Format
109: $this->getNumberFormat()->setFormatCode( \PHPExcel_Style_NumberFormat::FORMAT_GENERAL );
110: $this->getCell()->setValueExplicit( $Value, \PHPExcel_Cell_DataType::TYPE_FORMULA );
111: return Api::Module()->Office()->Document()->Excel();
112: }
113:
114: /**
115: * @param mixed $Value
116: * @return \MOC\Module\Office\Document\Excel
117: */
118: public function Bool( $Value ) {
119: // Reset Cell-Format
120: $this->getNumberFormat()->setFormatCode( \PHPExcel_Style_NumberFormat::FORMAT_GENERAL );
121: $this->getCell()->setValueExplicit( $Value, \PHPExcel_Cell_DataType::TYPE_BOOL );
122: return Api::Module()->Office()->Document()->Excel();
123: }
124:
125: /**
126: * @return \MOC\Module\Office\Document\Excel
127: */
128: public function Null() {
129: // Reset Cell-Format
130: $this->getNumberFormat()->setFormatCode( \PHPExcel_Style_NumberFormat::FORMAT_GENERAL );
131: $this->getCell()->setValueExplicit( null, \PHPExcel_Cell_DataType::TYPE_NULL );
132: return Api::Module()->Office()->Document()->Excel();
133: }
134:
135: /**
136: * @param File $Image
137: * @param int $Width
138: * @param int $Height
139: * @param int $OffsetX
140: * @param int $OffsetY
141: * @return \MOC\Module\Office\Document\Excel
142: */
143: public function Image( File $Image, $Width = 100, $Height = 0, $OffsetX = 0, $OffsetY = 0 ) {
144: // Reset Cell-Format
145: $this->getNumberFormat()->setFormatCode( \PHPExcel_Style_NumberFormat::FORMAT_GENERAL );
146:
147: $Draw = new \PHPExcel_Worksheet_Drawing();
148: $Draw->setPath( $Image->GetLocation() );
149: $Draw->setResizeProportional( true );
150: if( $Width > 0 ) $Draw->setWidth( $Width );
151: if( $Height > 0 ) $Draw->setHeight( $Height );
152: if( $OffsetX > 0 ) $Draw->setOffsetX( $OffsetX );
153: if( $OffsetY > 0 ) $Draw->setOffsetY( $OffsetY );
154: $Draw->setCoordinates(
155: Api::Module()->Office()->Document()->Excel()
156: ->Cell()->Select()->Current()
157: );
158: $Draw->setWorksheet(
159: Api::Extension()->Excel()->Current()
160: ->getActiveSheet()
161: );
162: return Api::Module()->Office()->Document()->Excel();
163: }
164:
165: /**
166: * @return mixed
167: */
168: public function Get() {
169: return $this->getCell()->getCalculatedValue();
170: }
171:
172: /**
173: * @return \PHPExcel_Style_NumberFormat
174: */
175: private function getNumberFormat() {
176: return Api::Extension()->Excel()->Current()
177: ->getActiveSheet()
178: ->getStyle(
179: Api::Module()->Office()->Document()->Excel()
180: ->Cell()->Select()->Current()
181: )
182: ->getNumberFormat();
183: }
184:
185: /**
186: * @return \PHPExcel_Cell
187: */
188: private function getCell() {
189: return Api::Extension()->Excel()->Current()
190: ->getActiveSheet()
191: ->getCell(
192: Api::Module()->Office()->Document()->Excel()
193: ->Cell()->Select()->Current()
194: );
195: }
196: }
197: