DocumentProperties.php 15 KB

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