public function setSelection(ZipArchive $xlsx)
 {
     $sheets = $this->bookUtil->makeSheetMap($xlsx);
     foreach ($sheets as $sheetName) {
         $this->cellSetter->set($xlsx, $sheetName, $this->firstCell);
     }
     $firstSheet = reset($sheets);
     $this->sheetSetter->set($xlsx, $firstSheet);
 }
 /**
  * @param string $xmlFixtureFile
  * @dataProvider provideData
  */
 public function test($xmlFixtureFile)
 {
     $xml = file_get_contents(__DIR__ . '/../../data/xml/' . $xmlFixtureFile);
     $zip = $this->getMockBuilder(ZipArchive::class)->disableOriginalConstructor()->getMock();
     $zip->expects($this->atLeastOnce())->method('getFromName')->with('xl/worksheet/sheet1.xml')->will($this->returnValue($xml));
     $bookUtil = $this->getMock(BookUtil::class);
     $dummySheetMap = ['テスト' => 'xl/worksheet/sheet1.xml'];
     $bookUtil->expects($this->once())->method('makeSheetFileMap')->with($zip)->will($this->returnValue($dummySheetMap));
     $zip->expects($this->once())->method('addFromString')->with('xl/worksheet/sheet1.xml', $this->callback(function ($xml) {
         return strpos($xml, 'activeCell="A1"') !== false && strpos($xml, 'sqref="A1"');
     }));
     $setter = new CellSelectionSetter($bookUtil);
     $setter->set($zip, 'テスト', 'A1');
 }
 /**
  * @param ZipArchive $xlsx
  * @param ZipArchive|null $template
  */
 public function setSelection(ZipArchive $xlsx, ZipArchive $template = null)
 {
     if (!$template instanceof ZipArchive) {
         throw new \RuntimeException('Invalid template');
     }
     // テンプレートで選択されているシートを取得
     $selectedSheet = $this->sheetReader->read($template);
     // テンプレートの各シートで選択されているセルを取得
     $sheets = $this->bookUtil->makeSheetMap($template);
     $selectedCells = [];
     foreach ($sheets as $sheetId => $sheetName) {
         $selectedCells[$sheetName] = $this->cellReader->read($template, $sheetName);
     }
     // 選択シートを書き込む
     $this->sheetSetter->set($xlsx, $selectedSheet);
     // 各シートの選択セルを書き込む
     foreach ($selectedCells as $sheetName => $cellPosition) {
         $this->cellSetter->set($xlsx, $sheetName, $cellPosition);
     }
 }