#検索キーワード
phpexcel cell values all
#参考URL
PHPExcel search cell by value
#サンプルコード
php
1<?php
2
3ini_set('display_errors', true);
4error_reporting(E_ALL);
5
6$searchValue = 'く';
7
8require __DIR__ . '/vendor/autoload.php';
9
10$excelfile = __DIR__ . '/sample.xlsx';
11$objReader = PHPExcel_IOFactory::createReader('Excel2007');
12$book = $objReader->load($excelfile);
13
14foreach ($book->getWorksheetIterator() as $worksheet) {
15 $ws = $worksheet->getTitle();
16 foreach ($worksheet->getRowIterator() as $row) {
17 $cellIterator = $row->getCellIterator();
18 $cellIterator->setIterateOnlyExistingCells(true);
19 foreach ($cellIterator as $cell) {
20 if ($cell->getValue() == $searchValue) {
21 $foundInCells[] = $ws . '!' . $cell->getCoordinate();
22 }
23 }
24 }
25}
26
27echo sprintf("検索ワード: %s\n", $searchValue);
28echo sprintf("ヒットしたシート!セル: %s\n", implode(', ', $foundInCells));
29
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/23 15:57
退会済みユーザー
2017/03/23 17:27
2017/03/24 09:38