7296478731c1bdc37b12cce3f78aef319b694c6b.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel
  23. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /**
  28. * PHPExcel_DocumentProperties
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_DocumentProperties
  35. {
  36. /** constants */
  37. const PROPERTY_TYPE_BOOLEAN = 'b';
  38. const PROPERTY_TYPE_INTEGER = 'i';
  39. const PROPERTY_TYPE_FLOAT = 'f';
  40. const PROPERTY_TYPE_DATE = 'd';
  41. const PROPERTY_TYPE_STRING = 's';
  42. const PROPERTY_TYPE_UNKNOWN = 'u';
  43. /**
  44. * Creator
  45. *
  46. * @var string
  47. */
  48. private $_creator = 'Unknown Creator';
  49. /**
  50. * LastModifiedBy
  51. *
  52. * @var string
  53. */
  54. private $_lastModifiedBy;
  55. /**
  56. * Created
  57. *
  58. * @var datetime
  59. */
  60. private $_created;
  61. /**
  62. * Modified
  63. *
  64. * @var datetime
  65. */
  66. private $_modified;
  67. /**
  68. * Title
  69. *
  70. * @var string
  71. */
  72. private $_title = 'Untitled Spreadsheet';
  73. /**
  74. * Description
  75. *
  76. * @var string
  77. */
  78. private $_description = '';
  79. /**
  80. * Subject
  81. *
  82. * @var string
  83. */
  84. private $_subject = '';
  85. /**
  86. * Keywords
  87. *
  88. * @var string
  89. */
  90. private $_keywords = '';
  91. /**
  92. * Category
  93. *
  94. * @var string
  95. */
  96. private $_category = '';
  97. /**
  98. * Manager
  99. *
  100. * @var string
  101. */
  102. private $_manager = '';
  103. /**
  104. * Company
  105. *
  106. * @var string
  107. */
  108. private $_company = 'Microsoft Corporation';
  109. /**
  110. * Custom Properties
  111. *
  112. * @var string
  113. */
  114. private $_customProperties = array();
  115. /**
  116. * Create a new PHPExcel_DocumentProperties
  117. */
  118. public function __construct()
  119. {
  120. // Initialise values
  121. $this->_lastModifiedBy = $this->_creator;
  122. $this->_created = time();
  123. $this->_modified = time();
  124. }
  125. /**
  126. * Get Creator
  127. *
  128. * @return string
  129. */
  130. public function getCreator() {
  131. return $this->_creator;
  132. }
  133. /**
  134. * Set Creator
  135. *
  136. * @param string $pValue
  137. * @return PHPExcel_DocumentProperties
  138. */
  139. public function setCreator($pValue = '') {
  140. $this->_creator = $pValue;
  141. return $this;
  142. }
  143. /**
  144. * Get Last Modified By
  145. *
  146. * @return string
  147. */
  148. public function getLastModifiedBy() {
  149. return $this->_lastModifiedBy;
  150. }
  151. /**
  152. * Set Last Modified By
  153. *
  154. * @param string $pValue
  155. * @return PHPExcel_DocumentProperties
  156. */
  157. public function setLastModifiedBy($pValue = '') {
  158. $this->_lastModifiedBy = $pValue;
  159. return $this;
  160. }
  161. /**
  162. * Get Created
  163. *
  164. * @return datetime
  165. */
  166. public function getCreated() {
  167. return $this->_created;
  168. }
  169. /**
  170. * Set Created
  171. *
  172. * @param datetime $pValue
  173. * @return PHPExcel_DocumentProperties
  174. */
  175. public function setCreated($pValue = null) {
  176. if ($pValue === NULL) {
  177. $pValue = time();
  178. } elseif (is_string($pValue)) {
  179. if (is_numeric($pValue)) {
  180. $pValue = intval($pValue);
  181. } else {
  182. $pValue = strtotime($pValue);
  183. }
  184. }
  185. $this->_created = $pValue;
  186. return $this;
  187. }
  188. /**
  189. * Get Modified
  190. *
  191. * @return datetime
  192. */
  193. public function getModified() {
  194. return $this->_modified;
  195. }
  196. /**
  197. * Set Modified
  198. *
  199. * @param datetime $pValue
  200. * @return PHPExcel_DocumentProperties
  201. */
  202. public function setModified($pValue = null) {
  203. if ($pValue === NULL) {
  204. $pValue = time();
  205. } elseif (is_string($pValue)) {
  206. if (is_numeric($pValue)) {
  207. $pValue = intval($pValue);
  208. } else {
  209. $pValue = strtotime($pValue);
  210. }
  211. }
  212. $this->_modified = $pValue;
  213. return $this;
  214. }
  215. /**
  216. * Get Title
  217. *
  218. * @return string
  219. */
  220. public function getTitle() {
  221. return $this->_title;
  222. }
  223. /**
  224. * Set Title
  225. *
  226. * @param string $pValue
  227. * @return PHPExcel_DocumentProperties
  228. */
  229. public function setTitle($pValue = '') {
  230. $this->_title = $pValue;
  231. return $this;
  232. }
  233. /**
  234. * Get Description
  235. *
  236. * @return string
  237. */
  238. public function getDescription() {
  239. return $this->_description;
  240. }
  241. /**
  242. * Set Description
  243. *
  244. * @param string $pValue
  245. * @return PHPExcel_DocumentProperties
  246. */
  247. public function setDescription($pValue = '') {
  248. $this->_description = $pValue;
  249. return $this;
  250. }
  251. /**
  252. * Get Subject
  253. *
  254. * @return string
  255. */
  256. public function getSubject() {
  257. return $this->_subject;
  258. }
  259. /**
  260. * Set Subject
  261. *
  262. * @param string $pValue
  263. * @return PHPExcel_DocumentProperties
  264. */
  265. public function setSubject($pValue = '') {
  266. $this->_subject = $pValue;
  267. return $this;
  268. }
  269. /**
  270. * Get Keywords
  271. *
  272. * @return string
  273. */
  274. public function getKeywords() {
  275. return $this->_keywords;
  276. }
  277. /**
  278. * Set Keywords
  279. *
  280. * @param string $pValue
  281. * @return PHPExcel_DocumentProperties
  282. */
  283. public function setKeywords($pValue = '') {
  284. $this->_keywords = $pValue;
  285. return $this;
  286. }
  287. /**
  288. * Get Category
  289. *
  290. * @return string
  291. */
  292. public function getCategory() {
  293. return $this->_category;
  294. }
  295. /**
  296. * Set Category
  297. *
  298. * @param string $pValue
  299. * @return PHPExcel_DocumentProperties
  300. */
  301. public function setCategory($pValue = '') {
  302. $this->_category = $pValue;
  303. return $this;
  304. }
  305. /**
  306. * Get Company
  307. *
  308. * @return string
  309. */
  310. public function getCompany() {
  311. return $this->_company;
  312. }
  313. /**
  314. * Set Company
  315. *
  316. * @param string $pValue
  317. * @return PHPExcel_DocumentProperties
  318. */
  319. public function setCompany($pValue = '') {
  320. $this->_company = $pValue;
  321. return $this;
  322. }
  323. /**
  324. * Get Manager
  325. *
  326. * @return string
  327. */
  328. public function getManager() {
  329. return $this->_manager;
  330. }
  331. /**
  332. * Set Manager
  333. *
  334. * @param string $pValue
  335. * @return PHPExcel_DocumentProperties
  336. */
  337. public function setManager($pValue = '') {
  338. $this->_manager = $pValue;
  339. return $this;
  340. }
  341. /**
  342. * Get a List of Custom Property Names
  343. *
  344. * @return array of string
  345. */
  346. public function getCustomProperties() {
  347. return array_keys($this->_customProperties);
  348. }
  349. /**
  350. * Check if a Custom Property is defined
  351. *
  352. * @param string $propertyName
  353. * @return boolean
  354. */
  355. public function isCustomPropertySet($propertyName) {
  356. return isset($this->_customProperties[$propertyName]);
  357. }
  358. /**
  359. * Get a Custom Property Value
  360. *
  361. * @param string $propertyName
  362. * @return string
  363. */
  364. public function getCustomPropertyValue($propertyName) {
  365. if (isset($this->_customProperties[$propertyName])) {
  366. return $this->_customProperties[$propertyName]['value'];
  367. }
  368. }
  369. /**
  370. * Get a Custom Property Type
  371. *
  372. * @param string $propertyName
  373. * @return string
  374. */
  375. public function getCustomPropertyType($propertyName) {
  376. if (isset($this->_customProperties[$propertyName])) {
  377. return $this->_customProperties[$propertyName]['type'];
  378. }
  379. }
  380. /**
  381. * Set a Custom Property
  382. *
  383. * @param string $propertyName
  384. * @param mixed $propertyValue
  385. * @param string $propertyType
  386. * 'i' : Integer
  387. * 'f' : Floating Point
  388. * 's' : String
  389. * 'd' : Date/Time
  390. * 'b' : Boolean
  391. * @return PHPExcel_DocumentProperties
  392. */
  393. public function setCustomProperty($propertyName,$propertyValue='',$propertyType=NULL) {
  394. if (($propertyType === NULL) || (!in_array($propertyType,array(self::PROPERTY_TYPE_INTEGER,
  395. self::PROPERTY_TYPE_FLOAT,
  396. self::PROPERTY_TYPE_STRING,
  397. self::PROPERTY_TYPE_DATE,
  398. self::PROPERTY_TYPE_BOOLEAN)))) {
  399. if ($propertyValue === NULL) {
  400. $propertyType = self::PROPERTY_TYPE_STRING;
  401. } elseif (is_float($propertyValue)) {
  402. $propertyType = self::PROPERTY_TYPE_FLOAT;
  403. } elseif(is_int($propertyValue)) {
  404. $propertyType = self::PROPERTY_TYPE_INTEGER;
  405. } elseif (is_bool($propertyValue)) {
  406. $propertyType = self::PROPERTY_TYPE_BOOLEAN;
  407. } else {
  408. $propertyType = self::PROPERTY_TYPE_STRING;
  409. }
  410. }
  411. $this->_customProperties[$propertyName] = array('value' => $propertyValue, 'type' => $propertyType);
  412. return $this;
  413. }
  414. /**
  415. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  416. */
  417. public function __clone() {
  418. $vars = get_object_vars($this);
  419. foreach ($vars as $key => $value) {
  420. if (is_object($value)) {
  421. $this->$key = clone $value;
  422. } else {
  423. $this->$key = $value;
  424. }
  425. }
  426. }
  427. public static function convertProperty($propertyValue,$propertyType) {
  428. switch ($propertyType) {
  429. case 'empty' : // Empty
  430. return '';
  431. break;
  432. case 'null' : // Null
  433. return NULL;
  434. break;
  435. case 'i1' : // 1-Byte Signed Integer
  436. case 'i2' : // 2-Byte Signed Integer
  437. case 'i4' : // 4-Byte Signed Integer
  438. case 'i8' : // 8-Byte Signed Integer
  439. case 'int' : // Integer
  440. return (int) $propertyValue;
  441. break;
  442. case 'ui1' : // 1-Byte Unsigned Integer
  443. case 'ui2' : // 2-Byte Unsigned Integer
  444. case 'ui4' : // 4-Byte Unsigned Integer
  445. case 'ui8' : // 8-Byte Unsigned Integer
  446. case 'uint' : // Unsigned Integer
  447. return abs((int) $propertyValue);
  448. break;
  449. case 'r4' : // 4-Byte Real Number
  450. case 'r8' : // 8-Byte Real Number
  451. case 'decimal' : // Decimal
  452. return (float) $propertyValue;
  453. break;
  454. case 'lpstr' : // LPSTR
  455. case 'lpwstr' : // LPWSTR
  456. case 'bstr' : // Basic String
  457. return $propertyValue;
  458. break;
  459. case 'date' : // Date and Time
  460. case 'filetime' : // File Time
  461. return strtotime($propertyValue);
  462. break;
  463. case 'bool' : // Boolean
  464. return ($propertyValue == 'true') ? True : False;
  465. break;
  466. case 'cy' : // Currency
  467. case 'error' : // Error Status Code
  468. case 'vector' : // Vector
  469. case 'array' : // Array
  470. case 'blob' : // Binary Blob
  471. case 'oblob' : // Binary Blob Object
  472. case 'stream' : // Binary Stream
  473. case 'ostream' : // Binary Stream Object
  474. case 'storage' : // Binary Storage
  475. case 'ostorage' : // Binary Storage Object
  476. case 'vstream' : // Binary Versioned Stream
  477. case 'clsid' : // Class ID
  478. case 'cf' : // Clipboard Data
  479. return $propertyValue;
  480. break;
  481. }
  482. return $propertyValue;
  483. }
  484. public static function convertPropertyType($propertyType) {
  485. switch ($propertyType) {
  486. case 'i1' : // 1-Byte Signed Integer
  487. case 'i2' : // 2-Byte Signed Integer
  488. case 'i4' : // 4-Byte Signed Integer
  489. case 'i8' : // 8-Byte Signed Integer
  490. case 'int' : // Integer
  491. case 'ui1' : // 1-Byte Unsigned Integer
  492. case 'ui2' : // 2-Byte Unsigned Integer
  493. case 'ui4' : // 4-Byte Unsigned Integer
  494. case 'ui8' : // 8-Byte Unsigned Integer
  495. case 'uint' : // Unsigned Integer
  496. return self::PROPERTY_TYPE_INTEGER;
  497. break;
  498. case 'r4' : // 4-Byte Real Number
  499. case 'r8' : // 8-Byte Real Number
  500. case 'decimal' : // Decimal
  501. return self::PROPERTY_TYPE_FLOAT;
  502. break;
  503. case 'empty' : // Empty
  504. case 'null' : // Null
  505. case 'lpstr' : // LPSTR
  506. case 'lpwstr' : // LPWSTR
  507. case 'bstr' : // Basic String
  508. return self::PROPERTY_TYPE_STRING;
  509. break;
  510. case 'date' : // Date and Time
  511. case 'filetime' : // File Time
  512. return self::PROPERTY_TYPE_DATE;
  513. break;
  514. case 'bool' : // Boolean
  515. return self::PROPERTY_TYPE_BOOLEAN;
  516. break;
  517. case 'cy' : // Currency
  518. case 'error' : // Error Status Code
  519. case 'vector' : // Vector
  520. case 'array' : // Array
  521. case 'blob' : // Binary Blob
  522. case 'oblob' : // Binary Blob Object
  523. case 'stream' : // Binary Stream
  524. case 'ostream' : // Binary Stream Object
  525. case 'storage' : // Binary Storage
  526. case 'ostorage' : // Binary Storage Object
  527. case 'vstream' : // Binary Versioned Stream
  528. case 'clsid' : // Class ID
  529. case 'cf' : // Clipboard Data
  530. return self::PROPERTY_TYPE_UNKNOWN;
  531. break;
  532. }
  533. return self::PROPERTY_TYPE_UNKNOWN;
  534. }
  535. }