Created
November 21, 2013 21:12
-
-
Save wilf312/7589706 to your computer and use it in GitHub Desktop.
PHPでExcelファイルを読み込んで配列にするまでのサムシング ref: http://qiita.com/wilf312/items/5d70f597aa48855d4f9b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ファイル名の指定 | |
$readFile = "example.xlsx"; | |
// 連想配列でデータ受け取り | |
$data = readXlsx($readFile); | |
// 出力確認 | |
print '<pre>'; | |
var_dump($data); | |
print '</pre>'; | |
// ファイル名渡したら配列返すラッパー関数 | |
function readXlsx($readFile) | |
{ | |
// ライブラリファイルの読み込み (パス指定し直す) | |
require_once dirname(__FILE__) . '/PHPExcel/IOFactory.php'; | |
// ファイルの存在チェック | |
if (!file_exists($readFile)) { | |
exit($readFile. "が見つかりません。" . EOL); | |
} | |
// xlsxをPHPExcelに食わせる | |
$objPExcel = PHPExcel_IOFactory::load($readFile); | |
// 配列形式で返す | |
return $objPExcel->getActiveSheet()->toArray(null,true,true,true); | |
} | |
// toArrayの説明 | |
/** | |
* Create array from worksheet | |
* | |
* @param mixed $nullValue Value returned in the array entry if a cell doesn't exist | |
* @param boolean $calculateFormulas Should formulas be calculated? | |
* @param boolean $formatData Should formatting be applied to cell values? | |
* @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero | |
* True - Return rows and columns indexed by their actual row and column IDs | |
* @return array | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment