Memory.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
  8. {
  9. /**
  10. * Dummy method callable from CacheBase, but unused by Memory cache
  11. *
  12. * @return void
  13. */
  14. protected function storeData()
  15. {
  16. }
  17. /**
  18. * Add or Update a cell in cache identified by coordinate address
  19. *
  20. * @param string $pCoord Coordinate address of the cell to update
  21. * @param PHPExcel_Cell $cell Cell to update
  22. * @return PHPExcel_Cell
  23. * @throws PHPExcel_Exception
  24. */
  25. public function addCacheData($pCoord, PHPExcel_Cell $cell)
  26. {
  27. $this->cellCache[$pCoord] = $cell;
  28. // Set current entry to the new/updated entry
  29. $this->currentObjectID = $pCoord;
  30. return $cell;
  31. }
  32. /**
  33. * Get cell at a specific coordinate
  34. *
  35. * @param string $pCoord Coordinate of the cell
  36. * @throws PHPExcel_Exception
  37. * @return PHPExcel_Cell Cell that was found, or null if not found
  38. */
  39. public function getCacheData($pCoord)
  40. {
  41. // Check if the entry that has been requested actually exists
  42. if (!isset($this->cellCache[$pCoord])) {
  43. $this->currentObjectID = null;
  44. // Return null if requested entry doesn't exist in cache
  45. return null;
  46. }
  47. // Set current entry to the requested entry
  48. $this->currentObjectID = $pCoord;
  49. // Return requested entry
  50. return $this->cellCache[$pCoord];
  51. }
  52. /**
  53. * Clone the cell collection
  54. *
  55. * @param PHPExcel_Worksheet $parent The new worksheet
  56. */
  57. public function copyCellCollection(PHPExcel_Worksheet $parent)
  58. {
  59. parent::copyCellCollection($parent);
  60. $newCollection = array();
  61. foreach ($this->cellCache as $k => &$cell) {
  62. $newCollection[$k] = clone $cell;
  63. $newCollection[$k]->attach($this);
  64. }
  65. $this->cellCache = $newCollection;
  66. }
  67. /**
  68. * Clear the cell collection and disconnect from our parent
  69. *
  70. */
  71. public function unsetWorksheetCells()
  72. {
  73. // Because cells are all stored as intact objects in memory, we need to detach each one from the parent
  74. foreach ($this->cellCache as $k => &$cell) {
  75. $cell->detach();
  76. $this->cellCache[$k] = null;
  77. }
  78. unset($cell);
  79. $this->cellCache = array();
  80. // detach ourself from the worksheet, so that it can then delete this object successfully
  81. $this->parent = null;
  82. }
  83. }