You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1254 lines
40 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php /** @noinspection MultiAssignmentUsageInspection */
  2. namespace Shuchkin;
  3. use SimpleXMLElement;
  4. /**
  5. * SimpleXLSX php class
  6. * MS Excel 2007+ workbooks reader
  7. *
  8. * Copyright (c) 2012 - 2022 SimpleXLSX
  9. *
  10. * @category SimpleXLSX
  11. * @package SimpleXLSX
  12. * @copyright Copyright (c) 2012 - 2022 SimpleXLSX (https://github.com/shuchkin/simplexlsx/)
  13. * @license MIT
  14. */
  15. /** Examples
  16. *
  17. * use Shuchkin\SimpleXLSX;
  18. *
  19. * Example 1:
  20. * if ( $xlsx = SimpleXLSX::parse('book.xlsx') ) {
  21. * foreach ($xlsx->rows() as $r) {
  22. * print_r( $r );
  23. * }
  24. * } else {
  25. * echo SimpleXLSX::parseError();
  26. * }
  27. *
  28. * Example 2: html table
  29. * if ( $xlsx = SimpleXLSX::parse('book.xlsx') ) {
  30. * echo $xlsx->toHTML();
  31. * } else {
  32. * echo SimpleXLSX::parseError();
  33. * }
  34. *
  35. * Example 3: rowsEx
  36. * $xlsx = SimpleXLSX::parse('book.xlsx');
  37. * foreach ( $xlsx->rowsEx() as $r ) {
  38. * print_r( $r );
  39. * }
  40. *
  41. * Example 4: select worksheet
  42. * $xlsx = SimpleXLSX::parse('book.xlsx');
  43. * foreach( $xlsx->rows(1) as $r ) { // second worksheet
  44. * print_t( $r );
  45. * }
  46. *
  47. * Example 5: IDs and worksheet names
  48. * $xlsx = SimpleXLSX::parse('book.xlsx');
  49. * print_r( $xlsx->sheetNames() ); // array( 0 => 'Sheet 1', 1 => 'Catalog' );
  50. *
  51. * Example 6: get sheet name by index
  52. * $xlsx = SimpleXLSX::parse('book.xlsx');
  53. * echo 'Sheet Name 2 = '.$xlsx->sheetName(1);
  54. *
  55. * Example 7: getCell (very slow)
  56. * echo $xlsx->getCell(1,'D12'); // reads D12 cell from second sheet
  57. *
  58. * Example 8: read data
  59. * if ( $xlsx = SimpleXLSX::parseData( file_get_contents('http://www.example.com/example.xlsx') ) ) {
  60. * $dim = $xlsx->dimension(1);
  61. * $num_cols = $dim[0];
  62. * $num_rows = $dim[1];
  63. * echo $xlsx->sheetName(1).':'.$num_cols.'x'.$num_rows;
  64. * } else {
  65. * echo SimpleXLSX::parseError();
  66. * }
  67. *
  68. * Example 9: old style
  69. * $xlsx = new SimpleXLSX('book.xlsx');
  70. * if ( $xlsx->success() ) {
  71. * print_r( $xlsx->rows() );
  72. * } else {
  73. * echo 'xlsx error: '.$xlsx->error();
  74. * }
  75. */
  76. class SimpleXLSX
  77. {
  78. // Don't remove this string! Created by Sergey Shuchkin sergey.shuchkin@gmail.com
  79. public static $CF = [ // Cell formats
  80. 0 => 'General',
  81. 1 => '0',
  82. 2 => '0.00',
  83. 3 => '#,##0',
  84. 4 => '#,##0.00',
  85. 9 => '0%',
  86. 10 => '0.00%',
  87. 11 => '0.00E+00',
  88. 12 => '# ?/?',
  89. 13 => '# ??/??',
  90. 14 => 'mm-dd-yy',
  91. 15 => 'd-mmm-yy',
  92. 16 => 'd-mmm',
  93. 17 => 'mmm-yy',
  94. 18 => 'h:mm AM/PM',
  95. 19 => 'h:mm:ss AM/PM',
  96. 20 => 'h:mm',
  97. 21 => 'h:mm:ss',
  98. 22 => 'm/d/yy h:mm',
  99. 37 => '#,##0 ;(#,##0)',
  100. 38 => '#,##0 ;[Red](#,##0)',
  101. 39 => '#,##0.00;(#,##0.00)',
  102. 40 => '#,##0.00;[Red](#,##0.00)',
  103. 44 => '_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)',
  104. 45 => 'mm:ss',
  105. 46 => '[h]:mm:ss',
  106. 47 => 'mmss.0',
  107. 48 => '##0.0E+0',
  108. 49 => '@',
  109. 27 => '[$-404]e/m/d',
  110. 30 => 'm/d/yy',
  111. 36 => '[$-404]e/m/d',
  112. 50 => '[$-404]e/m/d',
  113. 57 => '[$-404]e/m/d',
  114. 59 => 't0',
  115. 60 => 't0.00',
  116. 61 => 't#,##0',
  117. 62 => 't#,##0.00',
  118. 67 => 't0%',
  119. 68 => 't0.00%',
  120. 69 => 't# ?/?',
  121. 70 => 't# ??/??',
  122. ];
  123. public $nf = []; // number formats
  124. public $cellFormats = []; // cellXfs
  125. public $datetimeFormat = 'Y-m-d H:i:s';
  126. public $debug;
  127. public $activeSheet = 0;
  128. public $rowsExReader;
  129. /* @var SimpleXMLElement[] $sheets */
  130. protected $sheets;
  131. protected $sheetFiles = [];
  132. protected $sheetMetaData = [];
  133. // scheme
  134. public $styles;
  135. protected $hyperlinks;
  136. /* @var array[] $package */
  137. protected $package;
  138. protected $sharedstrings;
  139. protected $date1904 = 0;
  140. /*
  141. private $date_formats = array(
  142. 0xe => "d/m/Y",
  143. 0xf => "d-M-Y",
  144. 0x10 => "d-M",
  145. 0x11 => "M-Y",
  146. 0x12 => "h:i a",
  147. 0x13 => "h:i:s a",
  148. 0x14 => "H:i",
  149. 0x15 => "H:i:s",
  150. 0x16 => "d/m/Y H:i",
  151. 0x2d => "i:s",
  152. 0x2e => "H:i:s",
  153. 0x2f => "i:s.S"
  154. );
  155. private $number_formats = array(
  156. 0x1 => "%1.0f", // "0"
  157. 0x2 => "%1.2f", // "0.00",
  158. 0x3 => "%1.0f", //"#,##0",
  159. 0x4 => "%1.2f", //"#,##0.00",
  160. 0x5 => "%1.0f", //"$#,##0;($#,##0)",
  161. 0x6 => '$%1.0f', //"$#,##0;($#,##0)",
  162. 0x7 => '$%1.2f', //"$#,##0.00;($#,##0.00)",
  163. 0x8 => '$%1.2f', //"$#,##0.00;($#,##0.00)",
  164. 0x9 => '%1.0f%%', //"0%"
  165. 0xa => '%1.2f%%', //"0.00%"
  166. 0xb => '%1.2f', //"0.00E00",
  167. 0x25 => '%1.0f', //"#,##0;(#,##0)",
  168. 0x26 => '%1.0f', //"#,##0;(#,##0)",
  169. 0x27 => '%1.2f', //"#,##0.00;(#,##0.00)",
  170. 0x28 => '%1.2f', //"#,##0.00;(#,##0.00)",
  171. 0x29 => '%1.0f', //"#,##0;(#,##0)",
  172. 0x2a => '$%1.0f', //"$#,##0;($#,##0)",
  173. 0x2b => '%1.2f', //"#,##0.00;(#,##0.00)",
  174. 0x2c => '$%1.2f', //"$#,##0.00;($#,##0.00)",
  175. 0x30 => '%1.0f'); //"##0.0E0";
  176. // }}}
  177. */
  178. protected $errno = 0;
  179. protected $error = false;
  180. /**
  181. * @var false|SimpleXMLElement
  182. */
  183. public $theme;
  184. public function __construct($filename = null, $is_data = null, $debug = null)
  185. {
  186. if ($debug !== null) {
  187. $this->debug = $debug;
  188. }
  189. $this->package = [
  190. 'filename' => '',
  191. 'mtime' => 0,
  192. 'size' => 0,
  193. 'comment' => '',
  194. 'entries' => []
  195. ];
  196. if ($filename && $this->_unzip($filename, $is_data)) {
  197. $this->_parse();
  198. }
  199. }
  200. protected function _unzip($filename, $is_data = false)
  201. {
  202. if ($is_data) {
  203. $this->package['filename'] = 'default.xlsx';
  204. $this->package['mtime'] = time();
  205. $this->package['size'] = $this->_strlen($filename);
  206. $vZ = $filename;
  207. } else {
  208. if (!is_readable($filename)) {
  209. $this->error(1, 'File not found ' . $filename);
  210. return false;
  211. }
  212. // Package information
  213. $this->package['filename'] = $filename;
  214. $this->package['mtime'] = filemtime($filename);
  215. $this->package['size'] = filesize($filename);
  216. // Read file
  217. $vZ = file_get_contents($filename);
  218. }
  219. // Cut end of central directory
  220. /* $aE = explode("\x50\x4b\x05\x06", $vZ);
  221. if (count($aE) == 1) {
  222. $this->error('Unknown format');
  223. return false;
  224. }
  225. */
  226. // Explode to each part
  227. $aE = explode("\x50\x4b\x03\x04", $vZ);
  228. array_shift($aE);
  229. $aEL = count($aE);
  230. if ($aEL === 0) {
  231. $this->error(2, 'Unknown archive format');
  232. return false;
  233. }
  234. // Search central directory end record
  235. $last = $aE[$aEL - 1];
  236. $last = explode("\x50\x4b\x05\x06", $last);
  237. if (count($last) !== 2) {
  238. $this->error(2, 'Unknown archive format');
  239. return false;
  240. }
  241. // Search central directory
  242. $last = explode("\x50\x4b\x01\x02", $last[0]);
  243. if (count($last) < 2) {
  244. $this->error(2, 'Unknown archive format');
  245. return false;
  246. }
  247. $aE[$aEL - 1] = $last[0];
  248. // Loop through the entries
  249. foreach ($aE as $vZ) {
  250. $aI = [];
  251. $aI['E'] = 0;
  252. $aI['EM'] = '';
  253. // Retrieving local file header information
  254. // $aP = unpack('v1VN/v1GPF/v1CM/v1FT/v1FD/V1CRC/V1CS/V1UCS/v1FNL', $vZ);
  255. $aP = unpack('v1VN/v1GPF/v1CM/v1FT/v1FD/V1CRC/V1CS/V1UCS/v1FNL/v1EFL', $vZ);
  256. // Check if data is encrypted
  257. // $bE = ($aP['GPF'] && 0x0001) ? TRUE : FALSE;
  258. // $bE = false;
  259. $nF = $aP['FNL'];
  260. $mF = $aP['EFL'];
  261. // Special case : value block after the compressed data
  262. if ($aP['GPF'] & 0x0008) {
  263. $aP1 = unpack('V1CRC/V1CS/V1UCS', $this->_substr($vZ, -12));
  264. $aP['CRC'] = $aP1['CRC'];
  265. $aP['CS'] = $aP1['CS'];
  266. $aP['UCS'] = $aP1['UCS'];
  267. // 2013-08-10
  268. $vZ = $this->_substr($vZ, 0, -12);
  269. if ($this->_substr($vZ, -4) === "\x50\x4b\x07\x08") {
  270. $vZ = $this->_substr($vZ, 0, -4);
  271. }
  272. }
  273. // Getting stored filename
  274. $aI['N'] = $this->_substr($vZ, 26, $nF);
  275. $aI['N'] = str_replace('\\', '/', $aI['N']);
  276. if ($this->_substr($aI['N'], -1) === '/') {
  277. // is a directory entry - will be skipped
  278. continue;
  279. }
  280. // Truncate full filename in path and filename
  281. $aI['P'] = dirname($aI['N']);
  282. $aI['P'] = ($aI['P'] === '.') ? '' : $aI['P'];
  283. $aI['N'] = basename($aI['N']);
  284. $vZ = $this->_substr($vZ, 26 + $nF + $mF);
  285. if ($this->_strlen($vZ) !== (int)$aP['CS']) { // check only if availabled
  286. $aI['E'] = 1;
  287. $aI['EM'] = 'Compressed size is not equal with the value in header information.';
  288. }
  289. // } elseif ( $bE ) {
  290. // $aI['E'] = 5;
  291. // $aI['EM'] = 'File is encrypted, which is not supported from this class.';
  292. /* } else {
  293. switch ($aP['CM']) {
  294. case 0: // Stored
  295. // Here is nothing to do, the file ist flat.
  296. break;
  297. case 8: // Deflated
  298. $vZ = gzinflate($vZ);
  299. break;
  300. case 12: // BZIP2
  301. if (extension_loaded('bz2')) {
  302. $vZ = bzdecompress($vZ);
  303. } else {
  304. $aI['E'] = 7;
  305. $aI['EM'] = 'PHP BZIP2 extension not available.';
  306. }
  307. break;
  308. default:
  309. $aI['E'] = 6;
  310. $aI['EM'] = "De-/Compression method {$aP['CM']} is not supported.";
  311. }
  312. if (!$aI['E']) {
  313. if ($vZ === false) {
  314. $aI['E'] = 2;
  315. $aI['EM'] = 'Decompression of data failed.';
  316. } elseif ($this->_strlen($vZ) !== (int)$aP['UCS']) {
  317. $aI['E'] = 3;
  318. $aI['EM'] = 'Uncompressed size is not equal with the value in header information.';
  319. } elseif (crc32($vZ) !== $aP['CRC']) {
  320. $aI['E'] = 4;
  321. $aI['EM'] = 'CRC32 checksum is not equal with the value in header information.';
  322. }
  323. }
  324. }
  325. */
  326. // DOS to UNIX timestamp
  327. $aI['T'] = mktime(
  328. ($aP['FT'] & 0xf800) >> 11,
  329. ($aP['FT'] & 0x07e0) >> 5,
  330. ($aP['FT'] & 0x001f) << 1,
  331. ($aP['FD'] & 0x01e0) >> 5,
  332. $aP['FD'] & 0x001f,
  333. (($aP['FD'] & 0xfe00) >> 9) + 1980
  334. );
  335. $this->package['entries'][] = [
  336. 'data' => $vZ,
  337. 'ucs' => (int)$aP['UCS'], // ucompresses size
  338. 'cm' => $aP['CM'], // compressed method
  339. 'cs' => isset($aP['CS']) ? (int) $aP['CS'] : 0, // compresses size
  340. 'crc' => $aP['CRC'],
  341. 'error' => $aI['E'],
  342. 'error_msg' => $aI['EM'],
  343. 'name' => $aI['N'],
  344. 'path' => $aI['P'],
  345. 'time' => $aI['T']
  346. ];
  347. } // end for each entries
  348. return true;
  349. }
  350. protected function _strlen($str)
  351. {
  352. return (ini_get('mbstring.func_overload') & 2) ? mb_strlen($str, '8bit') : strlen($str);
  353. }
  354. public function error($num = null, $str = null)
  355. {
  356. if ($num) {
  357. $this->errno = $num;
  358. $this->error = $str;
  359. if ($this->debug) {
  360. trigger_error(__CLASS__ . ': ' . $this->error, E_USER_WARNING);
  361. }
  362. }
  363. return $this->error;
  364. }
  365. protected function _substr($str, $start, $length = null)
  366. {
  367. return (ini_get('mbstring.func_overload') & 2) ? mb_substr($str, $start, ($length === null) ? mb_strlen($str, '8bit') : $length, '8bit') : substr($str, $start, ($length === null) ? strlen($str) : $length);
  368. }
  369. protected function _parse()
  370. {
  371. // Document data holders
  372. $this->sharedstrings = [];
  373. $this->sheets = [];
  374. // $this->styles = array();
  375. // $m1 = 0; // memory_get_peak_usage( true );
  376. // Read relations and search for officeDocument
  377. if ($relations = $this->getEntryXML('_rels/.rels')) {
  378. foreach ($relations->Relationship as $rel) {
  379. $rel_type = basename(trim((string)$rel['Type'])); // officeDocument
  380. $rel_target = $this->_getTarget('', (string)$rel['Target']); // /xl/workbook.xml or xl/workbook.xml
  381. if ($rel_type === 'officeDocument' && $workbook = $this->getEntryXML($rel_target)) {
  382. $index_rId = []; // [0 => rId1]
  383. $index = 0;
  384. foreach ($workbook->sheets->sheet as $s) {
  385. $a = [];
  386. foreach ($s->attributes() as $k => $v) {
  387. $a[(string)$k] = (string)$v;
  388. }
  389. $this->sheetMetaData[$index] = $a;
  390. $index_rId[$index] = (string)$s['id'];
  391. $index++;
  392. }
  393. if ((int)$workbook->workbookPr['date1904'] === 1) {
  394. $this->date1904 = 1;
  395. }
  396. if ($workbookRelations = $this->getEntryXML(dirname($rel_target) . '/_rels/workbook.xml.rels')) {
  397. // Loop relations for workbook and extract sheets...
  398. foreach ($workbookRelations->Relationship as $workbookRelation) {
  399. $wrel_type = basename(trim((string)$workbookRelation['Type'])); // worksheet
  400. $wrel_path = $this->_getTarget(dirname($rel_target), (string)$workbookRelation['Target']);
  401. if (!$this->entryExists($wrel_path)) {
  402. continue;
  403. }
  404. if ($wrel_type === 'worksheet') { // Sheets
  405. if ($sheet = $this->getEntryXML($wrel_path)) {
  406. $index = array_search((string)$workbookRelation['Id'], $index_rId, true);
  407. $this->sheets[$index] = $sheet;
  408. $this->sheetFiles[$index] = $wrel_path;
  409. }
  410. } elseif ($wrel_type === 'sharedStrings') {
  411. if ($sharedStrings = $this->getEntryXML($wrel_path)) {
  412. foreach ($sharedStrings->si as $val) {
  413. if (isset($val->t)) {
  414. $this->sharedstrings[] = (string)$val->t;
  415. } elseif (isset($val->r)) {
  416. $this->sharedstrings[] = $this->_parseRichText($val);
  417. }
  418. }
  419. }
  420. } elseif ($wrel_type === 'styles') {
  421. $this->styles = $this->getEntryXML($wrel_path);
  422. // number formats
  423. $this->nf = [];
  424. if (isset($this->styles->numFmts->numFmt)) {
  425. foreach ($this->styles->numFmts->numFmt as $v) {
  426. $this->nf[(int)$v['numFmtId']] = (string)$v['formatCode'];
  427. }
  428. }
  429. $this->cellFormats = [];
  430. if (isset($this->styles->cellXfs->xf)) {
  431. foreach ($this->styles->cellXfs->xf as $v) {
  432. $x = [
  433. 'format' => null
  434. ];
  435. foreach ($v->attributes() as $k1 => $v1) {
  436. $x[ $k1 ] = (int) $v1;
  437. }
  438. if (isset($x['numFmtId'])) {
  439. if (isset($this->nf[$x['numFmtId']])) {
  440. $x['format'] = $this->nf[$x['numFmtId']];
  441. } elseif (isset(self::$CF[$x['numFmtId']])) {
  442. $x['format'] = self::$CF[$x['numFmtId']];
  443. }
  444. }
  445. $this->cellFormats[] = $x;
  446. }
  447. }
  448. } elseif ($wrel_type === 'theme') {
  449. $this->theme = $this->getEntryXML($wrel_path);
  450. }
  451. }
  452. break;
  453. }
  454. // reptile hack :: find active sheet from workbook.xml
  455. foreach ($workbook->bookViews->workbookView as $s) {
  456. if (!empty($s['activeTab'])) {
  457. $this->activeSheet = (int)$s['activeTab'];
  458. }
  459. }
  460. }
  461. }
  462. }
  463. // $m2 = memory_get_peak_usage(true);
  464. // echo __FUNCTION__.' M='.round( ($m2-$m1) / 1048576, 2).'MB'.PHP_EOL;
  465. if (count($this->sheets)) {
  466. // Sort sheets
  467. ksort($this->sheets);
  468. return true;
  469. }
  470. return false;
  471. }
  472. public function getEntryXML($name)
  473. {
  474. if ($entry_xml = $this->getEntryData($name)) {
  475. $this->deleteEntry($name); // economy memory
  476. // dirty remove namespace prefixes and empty rows
  477. $entry_xml = preg_replace('/xmlns[^=]*="[^"]*"/i', '', $entry_xml); // remove namespaces
  478. $entry_xml .= ' '; // force run garbage collector
  479. $entry_xml = preg_replace('/[a-zA-Z0-9]+:([a-zA-Z0-9]+="[^"]+")/', '$1', $entry_xml); // remove namespaced attrs
  480. $entry_xml .= ' ';
  481. $entry_xml = preg_replace('/<[a-zA-Z0-9]+:([^>]+)>/', '<$1>', $entry_xml); // fix namespaced openned tags
  482. $entry_xml .= ' ';
  483. $entry_xml = preg_replace('/<\/[a-zA-Z0-9]+:([^>]+)>/', '</$1>', $entry_xml); // fix namespaced closed tags
  484. $entry_xml .= ' ';
  485. if (strpos($name, '/sheet')) { // dirty skip empty rows
  486. // remove <row...> <c /><c /></row>
  487. $entry_xml = preg_replace('/<row[^>]+>\s*(<c[^\/]+\/>\s*)+<\/row>/', '', $entry_xml, -1, $cnt);
  488. $entry_xml .= ' ';
  489. // remove <row />
  490. $entry_xml = preg_replace('/<row[^\/>]*\/>/', '', $entry_xml, -1, $cnt2);
  491. $entry_xml .= ' ';
  492. // remove <row...></row>
  493. $entry_xml = preg_replace('/<row[^>]*><\/row>/', '', $entry_xml, -1, $cnt3);
  494. $entry_xml .= ' ';
  495. if ($cnt || $cnt2 || $cnt3) {
  496. $entry_xml = preg_replace('/<dimension[^\/]+\/>/', '', $entry_xml);
  497. $entry_xml .= ' ';
  498. }
  499. // file_put_contents( basename( $name ), $entry_xml ); // @to do comment!!!
  500. }
  501. $entry_xml = trim($entry_xml);
  502. // $m1 = memory_get_usage();
  503. // XML External Entity (XXE) Prevention, libxml_disable_entity_loader deprecated in PHP 8
  504. if (LIBXML_VERSION < 20900 && function_exists('libxml_disable_entity_loader')) {
  505. $_old = libxml_disable_entity_loader();
  506. }
  507. $_old_uie = libxml_use_internal_errors(true);
  508. $entry_xmlobj = simplexml_load_string($entry_xml, 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE);
  509. libxml_use_internal_errors($_old_uie);
  510. if (LIBXML_VERSION < 20900 && function_exists('libxml_disable_entity_loader')) {
  511. /** @noinspection PhpUndefinedVariableInspection */
  512. libxml_disable_entity_loader($_old);
  513. }
  514. // $m2 = memory_get_usage();
  515. // echo round( ($m2-$m1) / (1024 * 1024), 2).' MB'.PHP_EOL;
  516. if ($entry_xmlobj) {
  517. return $entry_xmlobj;
  518. }
  519. $e = libxml_get_last_error();
  520. if ($e) {
  521. $this->error(3, 'XML-entry ' . $name . ' parser error ' . $e->message . ' line ' . $e->line);
  522. }
  523. } else {
  524. $this->error(4, 'XML-entry not found ' . $name);
  525. }
  526. return false;
  527. }
  528. // sheets numeration: 1,2,3....
  529. public function getEntryData($name)
  530. {
  531. $name = ltrim(str_replace('\\', '/', $name), '/');
  532. $dir = $this->_strtoupper(dirname($name));
  533. $name = $this->_strtoupper(basename($name));
  534. foreach ($this->package['entries'] as &$entry) {
  535. if ($this->_strtoupper($entry['path']) === $dir && $this->_strtoupper($entry['name']) === $name) {
  536. if ($entry['error']) {
  537. return false;
  538. }
  539. switch ($entry['cm']) {
  540. case -1:
  541. case 0: // Stored
  542. // Here is nothing to do, the file ist flat.
  543. break;
  544. case 8: // Deflated
  545. $entry['data'] = gzinflate($entry['data']);
  546. break;
  547. case 12: // BZIP2
  548. if (extension_loaded('bz2')) {
  549. $entry['data'] = bzdecompress($entry['data']);
  550. } else {
  551. $entry['error'] = 7;
  552. $entry['error_message'] = 'PHP BZIP2 extension not available.';
  553. }
  554. break;
  555. default:
  556. $entry['error'] = 6;
  557. $entry['error_msg'] = 'De-/Compression method '.$entry['cm'].' is not supported.';
  558. }
  559. if (!$entry['error'] && $entry['cm'] > -1) {
  560. $entry['cm'] = -1;
  561. if ($entry['data'] === false) {
  562. $entry['error'] = 2;
  563. $entry['error_msg'] = 'Decompression of data failed.';
  564. } elseif ($this->_strlen($entry['data']) !== (int)$entry['ucs']) {
  565. $entry['error'] = 3;
  566. $entry['error_msg'] = 'Uncompressed size is not equal with the value in header information.';
  567. } elseif (crc32($entry['data']) !== $entry['crc']) {
  568. $entry['error'] = 4;
  569. $entry['error_msg'] = 'CRC32 checksum is not equal with the value in header information.';
  570. }
  571. }
  572. return $entry['data'];
  573. }
  574. }
  575. unset($entry);
  576. $this->error(5, 'Entry not found ' . ($dir ? $dir . '/' : '') . $name);
  577. return false;
  578. }
  579. public function deleteEntry($name)
  580. {
  581. $name = ltrim(str_replace('\\', '/', $name), '/');
  582. $dir = $this->_strtoupper(dirname($name));
  583. $name = $this->_strtoupper(basename($name));
  584. foreach ($this->package['entries'] as $k => $entry) {
  585. if ($this->_strtoupper($entry['path']) === $dir && $this->_strtoupper($entry['name']) === $name) {
  586. unset($this->package['entries'][$k]);
  587. return true;
  588. }
  589. }
  590. return false;
  591. }
  592. protected function _strtoupper($str)
  593. {
  594. return (ini_get('mbstring.func_overload') & 2) ? mb_strtoupper($str, '8bit') : strtoupper($str);
  595. }
  596. protected function _getTarget($base, $target)
  597. {
  598. $target = trim($target);
  599. if (strpos($target, '/') === 0) {
  600. return $this->_substr($target, 1);
  601. }
  602. $target = ($base ? $base . '/' : '') . $target;
  603. // a/b/../c -> a/c
  604. $parts = explode('/', $target);
  605. $abs = [];
  606. foreach ($parts as $p) {
  607. if ('.' === $p) {
  608. continue;
  609. }
  610. if ('..' === $p) {
  611. array_pop($abs);
  612. } else {
  613. $abs[] = $p;
  614. }
  615. }
  616. return implode('/', $abs);
  617. }
  618. /*
  619. * @param string $name Filename in archive
  620. * @return SimpleXMLElement|bool
  621. */
  622. public function entryExists($name)
  623. {
  624. // 0.6.6
  625. $dir = $this->_strtoupper(dirname($name));
  626. $name = $this->_strtoupper(basename($name));
  627. foreach ($this->package['entries'] as $entry) {
  628. if ($this->_strtoupper($entry['path']) === $dir && $this->_strtoupper($entry['name']) === $name) {
  629. return true;
  630. }
  631. }
  632. return false;
  633. }
  634. protected function _parseRichText($is = null)
  635. {
  636. $value = [];
  637. if (isset($is->t)) {
  638. $value[] = (string)$is->t;
  639. } elseif (isset($is->r)) {
  640. foreach ($is->r as $run) {
  641. $value[] = (string)$run->t;
  642. }
  643. }
  644. return implode('', $value);
  645. }
  646. public static function parseFile($filename, $debug = false)
  647. {
  648. return self::parse($filename, false, $debug);
  649. }
  650. public static function parse($filename, $is_data = false, $debug = false)
  651. {
  652. $xlsx = new self();
  653. $xlsx->debug = $debug;
  654. if ($xlsx->_unzip($filename, $is_data)) {
  655. $xlsx->_parse();
  656. }
  657. if ($xlsx->success()) {
  658. return $xlsx;
  659. }
  660. self::parseError($xlsx->error());
  661. self::parseErrno($xlsx->errno());
  662. return false;
  663. }
  664. public function success()
  665. {
  666. return !$this->error;
  667. }
  668. // https://github.com/shuchkin/simplexlsx#gets-extend-cell-info-by--rowsex
  669. public static function parseError($set = false)
  670. {
  671. static $error = false;
  672. return $set ? $error = $set : $error;
  673. }
  674. public static function parseErrno($set = false)
  675. {
  676. static $errno = false;
  677. return $set ? $errno = $set : $errno;
  678. }
  679. public function errno()
  680. {
  681. return $this->errno;
  682. }
  683. public static function parseData($data, $debug = false)
  684. {
  685. return self::parse($data, true, $debug);
  686. }
  687. public function worksheet($worksheetIndex = 0)
  688. {
  689. if (isset($this->sheets[$worksheetIndex])) {
  690. $ws = $this->sheets[$worksheetIndex];
  691. if (!isset($this->hyperlinks[$worksheetIndex]) && isset($ws->hyperlinks)) {
  692. $this->hyperlinks[$worksheetIndex] = [];
  693. $sheet_rels = str_replace('worksheets', 'worksheets/_rels', $this->sheetFiles[$worksheetIndex]) . '.rels';
  694. $link_ids = [];
  695. if ($rels = $this->getEntryXML($sheet_rels)) {
  696. // hyperlink
  697. // $rel_base = dirname( $sheet_rels );
  698. foreach ($rels->Relationship as $rel) {
  699. $rel_type = basename(trim((string)$rel['Type']));
  700. if ($rel_type === 'hyperlink') {
  701. $rel_id = (string)$rel['Id'];
  702. $rel_target = (string)$rel['Target'];
  703. $link_ids[$rel_id] = $rel_target;
  704. }
  705. }
  706. }
  707. foreach ($ws->hyperlinks->hyperlink as $hyperlink) {
  708. $ref = (string)$hyperlink['ref'];
  709. if ($this->_strpos($ref, ':') > 0) { // A1:A8 -> A1
  710. $ref = explode(':', $ref);
  711. $ref = $ref[0];
  712. }
  713. // $this->hyperlinks[ $worksheetIndex ][ $ref ] = (string) $hyperlink['display'];
  714. $loc = (string)$hyperlink['location'];
  715. $id = (string)$hyperlink['id'];
  716. if ($id) {
  717. $href = $link_ids[$id] . ($loc ? '#' . $loc : '');
  718. } else {
  719. $href = $loc;
  720. }
  721. $this->hyperlinks[$worksheetIndex][$ref] = $href;
  722. }
  723. }
  724. return $ws;
  725. }
  726. $this->error(6, 'Worksheet not found ' . $worksheetIndex);
  727. return false;
  728. }
  729. protected function _strpos($haystack, $needle, $offset = 0)
  730. {
  731. return (ini_get('mbstring.func_overload') & 2) ? mb_strpos($haystack, $needle, $offset, '8bit') : strpos($haystack, $needle, $offset);
  732. }
  733. /**
  734. * returns [numCols,numRows] of worksheet
  735. *
  736. * @param int $worksheetIndex
  737. *
  738. * @return array
  739. */
  740. public function dimension($worksheetIndex = 0)
  741. {
  742. if (($ws = $this->worksheet($worksheetIndex)) === false) {
  743. return [0, 0];
  744. }
  745. /* @var SimpleXMLElement $ws */
  746. $ref = (string)$ws->dimension['ref'];
  747. if ($this->_strpos($ref, ':') !== false) {
  748. $d = explode(':', $ref);
  749. $idx = $this->getIndex($d[1]);
  750. return [$idx[0] + 1, $idx[1] + 1];
  751. }
  752. /*
  753. if ( $ref !== '' ) { // 0.6.8
  754. $index = $this->getIndex( $ref );
  755. return [ $index[0] + 1, $index[1] + 1 ];
  756. }
  757. */
  758. // slow method
  759. $maxC = $maxR = 0;
  760. $iR = -1;
  761. foreach ($ws->sheetData->row as $row) {
  762. $iR++;
  763. $iC = -1;
  764. foreach ($row->c as $c) {
  765. $iC++;
  766. $idx = $this->getIndex((string)$c['r']);
  767. $x = $idx[0];
  768. $y = $idx[1];
  769. if ($x > -1) {
  770. if ($x > $maxC) {
  771. $maxC = $x;
  772. }
  773. if ($y > $maxR) {
  774. $maxR = $y;
  775. }
  776. } else {
  777. if ($iC > $maxC) {
  778. $maxC = $iC;
  779. }
  780. if ($iR > $maxR) {
  781. $maxR = $iR;
  782. }
  783. }
  784. }
  785. }
  786. return [$maxC + 1, $maxR + 1];
  787. }
  788. public function getIndex($cell = 'A1')
  789. {
  790. if (preg_match('/([A-Z]+)(\d+)/', $cell, $m)) {
  791. $col = $m[1];
  792. $row = $m[2];
  793. $colLen = $this->_strlen($col);
  794. $index = 0;
  795. for ($i = $colLen - 1; $i >= 0; $i--) {
  796. $index += (ord($col[$i]) - 64) * pow(26, $colLen - $i - 1);
  797. }
  798. return [$index - 1, $row - 1];
  799. }
  800. // $this->error( 'Invalid cell index ' . $cell );
  801. return [-1, -1];
  802. }
  803. public function value($cell)
  804. {
  805. // Determine data type
  806. $dataType = (string)$cell['t'];
  807. if ($dataType === '' || $dataType === 'n') { // number
  808. $s = (int)$cell['s'];
  809. if ($s > 0 && isset($this->cellFormats[$s])) {
  810. if (array_key_exists('format', $this->cellFormats[$s])) {
  811. $format = $this->cellFormats[$s]['format'];
  812. if (preg_match('/[mM]/', preg_replace('/\"[^"]+\"/', '', $format))) { // [mm]onth,AM|PM
  813. $dataType = 'D';
  814. }
  815. } else {
  816. $dataType = 'n';
  817. }
  818. }
  819. }
  820. $value = '';
  821. switch ($dataType) {
  822. case 's':
  823. // Value is a shared string
  824. if ((string)$cell->v !== '') {
  825. $value = $this->sharedstrings[(int)$cell->v];
  826. }
  827. break;
  828. case 'str': // formula?
  829. if ((string)$cell->v !== '') {
  830. $value = (string)$cell->v;
  831. }
  832. break;
  833. case 'b':
  834. // Value is boolean
  835. $value = (string)$cell->v;
  836. if ($value === '0') {
  837. $value = false;
  838. } elseif ($value === '1') {
  839. $value = true;
  840. } else {
  841. $value = (bool)$cell->v;
  842. }
  843. break;
  844. case 'inlineStr':
  845. // Value is rich text inline
  846. $value = $this->_parseRichText($cell->is);
  847. break;
  848. case 'e':
  849. // Value is an error message
  850. if ((string)$cell->v !== '') {
  851. $value = (string)$cell->v;
  852. }
  853. break;
  854. case 'D':
  855. // Date as float
  856. if (!empty($cell->v)) {
  857. $value = $this->datetimeFormat ? gmdate($this->datetimeFormat, $this->unixstamp((float)$cell->v)) : (float)$cell->v;
  858. }
  859. break;
  860. case 'd':
  861. // Date as ISO YYYY-MM-DD
  862. if ((string)$cell->v !== '') {
  863. $value = (string)$cell->v;
  864. }
  865. break;
  866. default:
  867. // Value is a string
  868. $value = (string)$cell->v;
  869. // Check for numeric values
  870. if (is_numeric($value)) {
  871. /** @noinspection TypeUnsafeComparisonInspection */
  872. if ($value == (int)$value) {
  873. $value = (int)$value;
  874. } /** @noinspection TypeUnsafeComparisonInspection */ elseif ($value == (float)$value) {
  875. $value = (float)$value;
  876. }
  877. }
  878. }
  879. return $value;
  880. }
  881. public function unixstamp($excelDateTime)
  882. {
  883. $d = floor($excelDateTime); // days since 1900 or 1904
  884. $t = $excelDateTime - $d;
  885. if ($this->date1904) {
  886. $d += 1462;
  887. }
  888. $t = (abs($d) > 0) ? ($d - 25569) * 86400 + round($t * 86400) : round($t * 86400);
  889. return (int)$t;
  890. }
  891. public function href($worksheetIndex, $cell)
  892. {
  893. $ref = (string)$cell['r'];
  894. return isset($this->hyperlinks[$worksheetIndex][$ref]) ? $this->hyperlinks[$worksheetIndex][$ref] : '';
  895. }
  896. public function toHTML($worksheetIndex = 0)
  897. {
  898. $s = '<table class=excel>';
  899. foreach ($this->readRows($worksheetIndex) as $r) {
  900. $s .= '<tr>';
  901. foreach ($r as $c) {
  902. $s .= '<td nowrap>' . ($c === '' ? '&nbsp' : htmlspecialchars($c, ENT_QUOTES)) . '</td>';
  903. }
  904. $s .= "</tr>\r\n";
  905. }
  906. $s .= '</table>';
  907. return $s;
  908. }
  909. public function toHTMLEx($worksheetIndex = 0)
  910. {
  911. $s = '<table class=excel>';
  912. $y = 0;
  913. foreach ($this->readRowsEx($worksheetIndex) as $r) {
  914. $s .= '<tr>';
  915. $x = 0;
  916. foreach ($r as $c) {
  917. $tag = 'td';
  918. $css = $c['css'];
  919. if ($y === 0) {
  920. $tag = 'th';
  921. $css .= $c['width'] ? 'width: '.round($c['width'] * 0.47, 2).'em;' : '';
  922. }
  923. if ($x === 0 && $c['height']) {
  924. $css .= 'height: '.round($c['height'] * 1.3333).'px;';
  925. }
  926. $s .= '<'.$tag.' style="'.$css.'" nowrap>' . ($c['value'] === '' ? '&nbsp' : htmlspecialchars($c['value'], ENT_QUOTES)) . '</'.$tag.'>';
  927. $x++;
  928. }
  929. $s .= "</tr>\r\n";
  930. $y++;
  931. }
  932. $s .= '</table>';
  933. return $s;
  934. }
  935. public function rows($worksheetIndex = 0, $limit = 0)
  936. {
  937. return iterator_to_array($this->readRows($worksheetIndex, $limit), false);
  938. }
  939. // thx Gonzo
  940. /**
  941. * @param $worksheetIndex
  942. * @param $limit
  943. * @return \Generator
  944. */
  945. public function readRows($worksheetIndex = 0, $limit = 0)
  946. {
  947. if (($ws = $this->worksheet($worksheetIndex)) === false) {
  948. return;
  949. }
  950. $dim = $this->dimension($worksheetIndex);
  951. $numCols = $dim[0];
  952. $numRows = $dim[1];
  953. $emptyRow = [];
  954. for ($i = 0; $i < $numCols; $i++) {
  955. $emptyRow[] = '';
  956. }
  957. $curR = 0;
  958. $_limit = $limit;
  959. /* @var SimpleXMLElement $ws */
  960. foreach ($ws->sheetData->row as $row) {
  961. $r = $emptyRow;
  962. $curC = 0;
  963. foreach ($row->c as $c) {
  964. // detect skipped cols
  965. $idx = $this->getIndex((string)$c['r']);
  966. $x = $idx[0];
  967. $y = $idx[1];
  968. if ($x > -1) {
  969. $curC = $x;
  970. while ($curR < $y) {
  971. yield $emptyRow;
  972. $curR++;
  973. $_limit--;
  974. if ($_limit === 0) {
  975. return;
  976. }
  977. }
  978. }
  979. $r[$curC] = $this->value($c);
  980. $curC++;
  981. }
  982. yield $r;
  983. $curR++;
  984. $_limit--;
  985. if ($_limit === 0) {
  986. return;
  987. }
  988. }
  989. while ($curR < $numRows) {
  990. yield $emptyRow;
  991. $curR++;
  992. $_limit--;
  993. if ($_limit === 0) {
  994. return;
  995. }
  996. }
  997. }
  998. public function rowsEx($worksheetIndex = 0, $limit = 0)
  999. {
  1000. return iterator_to_array($this->readRowsEx($worksheetIndex, $limit), false);
  1001. }
  1002. // https://github.com/shuchkin/simplexlsx#gets-extend-cell-info-by--rowsex
  1003. /**
  1004. * @param $worksheetIndex
  1005. * @param $limit
  1006. * @return \Generator|null
  1007. */
  1008. public function readRowsEx($worksheetIndex = 0, $limit = 0)
  1009. {
  1010. if (!$this->rowsExReader) {
  1011. require_once __DIR__ . '/SimpleXLSXEx.php';
  1012. $this->rowsExReader = new SimpleXLSXEx($this);
  1013. }
  1014. return $this->rowsExReader->readRowsEx($worksheetIndex, $limit);
  1015. }
  1016. /**
  1017. * Returns cell value
  1018. * VERY SLOW! Use ->rows() or ->rowsEx()
  1019. *
  1020. * @param int $worksheetIndex
  1021. * @param string|array $cell ref or coords, D12 or [3,12]
  1022. *
  1023. * @return mixed Returns NULL if not found
  1024. */
  1025. public function getCell($worksheetIndex = 0, $cell = 'A1')
  1026. {
  1027. if (($ws = $this->worksheet($worksheetIndex)) === false) {
  1028. return false;
  1029. }
  1030. if (is_array($cell)) {
  1031. $cell = $this->_num2name($cell[0]) . $cell[1];// [3,21] -> D21
  1032. }
  1033. if (is_string($cell)) {
  1034. $result = $ws->sheetData->xpath("row/c[@r='" . $cell . "']");
  1035. if (count($result)) {
  1036. return $this->value($result[0]);
  1037. }
  1038. }
  1039. return null;
  1040. }
  1041. protected function _num2name($num)
  1042. {
  1043. $numeric = ($num - 1) % 26;
  1044. $letter = chr(65 + $numeric);
  1045. $num2 = (int)(($num - 1) / 26);
  1046. if ($num2 > 0) {
  1047. return $this->_num2name($num2) . $letter;
  1048. }
  1049. return $letter;
  1050. }
  1051. public function getSheets()
  1052. {
  1053. return $this->sheets;
  1054. }
  1055. public function sheetsCount()
  1056. {
  1057. return count($this->sheets);
  1058. }
  1059. public function sheetName($worksheetIndex)
  1060. {
  1061. $sn = $this->sheetNames();
  1062. if (isset($sn[$worksheetIndex])) {
  1063. return $sn[$worksheetIndex];
  1064. }
  1065. return false;
  1066. }
  1067. public function sheetNames()
  1068. {
  1069. $a = [];
  1070. foreach ($this->sheetMetaData as $k => $v) {
  1071. $a[$k] = $v['name'];
  1072. }
  1073. return $a;
  1074. }
  1075. public function sheetMeta($worksheetIndex = null)
  1076. {
  1077. if ($worksheetIndex === null) {
  1078. return $this->sheetMetaData;
  1079. }
  1080. return isset($this->sheetMetaData[$worksheetIndex]) ? $this->sheetMetaData[$worksheetIndex] : false;
  1081. }
  1082. public function isHiddenSheet($worksheetIndex)
  1083. {
  1084. return isset($this->sheetMetaData[$worksheetIndex]['state']) && $this->sheetMetaData[$worksheetIndex]['state'] === 'hidden';
  1085. }
  1086. public function getStyles()
  1087. {
  1088. return $this->styles;
  1089. }
  1090. public function getPackage()
  1091. {
  1092. return $this->package;
  1093. }
  1094. public function setDateTimeFormat($value)
  1095. {
  1096. $this->datetimeFormat = is_string($value) ? $value : false;
  1097. }
  1098. }