{"id":3529,"date":"2018-03-22T14:06:39","date_gmt":"2018-03-22T05:06:39","guid":{"rendered":"http:\/\/www.otwo.jp\/blog\/?p=3529"},"modified":"2019-06-19T16:54:03","modified_gmt":"2019-06-19T07:54:03","slug":"phpexcel","status":"publish","type":"post","link":"https:\/\/www.otwo.jp\/blog\/phpexcel\/","title":{"rendered":"PHPExcel\u3067\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210\u304b\u3089\u5024\u306e\u53d6\u5f97"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel_main.jpg\" alt=\"\" width=\"700\" height=\"400\" class=\"alignnone size-full wp-image-3587\" srcset=\"https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel_main.jpg 700w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel_main-150x86.jpg 150w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel_main-300x171.jpg 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>\u3053\u3093\u306b\u3061\u306fWEB\u306e\u4f50\u91ce\u3067\u3059\u3001\u3082\u3046\u3059\u3050\u685c\u306e\u5b63\u7bc0\u3067\u3059\u306d\u3002<br \/>\n\u79c1\u306f\u6700\u8fd1\u3001\u76ee\u304c\u75d2\u304f\u3066\u3001\u9f3b\u304c\u8a70\u3063\u3066\u3001\u304f\u3057\u3083\u307f\u304c\u3088\u304f\u51fa\u307e\u3059\u3002<\/p>\n<p>\u82b1\u898b\u306e\u5b63\u7bc0\u306a\u306e\u306b\u3001\u82b1\u7c89\u75c7\u3067\u8f9b\u3044\u3067\u3059\u3002<br \/>\n\u305d\u3093\u306a\u6642\u306b\u306f\u3053\u308c\u3092\u898b\u3066\u82b1\u898b\u6c17\u5206\u3092\u5473\u308f\u3044\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<div class=\"externalLink\" style=\"margin: 10px 0;\"><a href=\"https:\/\/www.otwo.jp\/blog\/canvas_sakura\/\" target=\"_blank\" rel=\"noopener noreferrer\">Canvas\u3067\u685c\u3092\u964d\u3089\u305b\u3066\u307f\u307e\u3057\u305f<\/a><\/div>\n<p>\u3055\u3066\u3055\u3066\u3001\u79c1\u304c\u6240\u5c5e\u3057\u3066\u3044\u308bWEB\u30c1\u30fc\u30e0\u3082\u82b1\u7c89\u75c7\u306b\u8ca0\u3051\u305a\u3001\u8272\u3005\u306a\u6848\u4ef6\u3092\u9032\u3081\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001WEB\u30b5\u30a4\u30c8\u5236\u4f5c\u306e\u307b\u304b\u306b\u3082\u30b7\u30b9\u30c6\u30e0\u958b\u767a\u306a\u3069\u3092\u884c\u3063\u3066\u304a\u308a\u307e\u3059\uff01<\/p>\n<p>\u4e3b\u306b\u306fPHP\u3092\u4f7f\u3063\u305fWEB\u30b7\u30b9\u30c6\u30e0\u306e\u5236\u4f5c\u3092\u884c\u3063\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u305d\u3053\u3067\u4f7f\u3046\u4e8b\u304c\u591a\u3044PHPExcel\u306b\u3064\u3044\u3066\u66f8\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u57fa\u672c\u64cd\u4f5c\u3068\u306a\u308b\u3001\u65b0\u898f\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u30fb\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d\u306e\u90e8\u5206\u3092\u30b5\u30f3\u30d7\u30eb\u3068\u5408\u308f\u305b\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3059\u3050\u8a66\u3057\u3066\u3082\u3089\u3048\u308b\u69d8\u306b\u30b3\u30d4\u30da\u3067\u4f7f\u3048\u308b\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u8f09\u305b\u3066\u304a\u304d\u307e\u3059\u306e\u3067\u3001\u8208\u5473\u304c\u3042\u308b\u65b9\u306f\u6700\u5f8c\u307e\u3067\u3054\u89a7\u304f\u3060\u3055\u3044\uff01<\/p>\n<div class=\"pageContents\">\n<p class=\"title\">\u3082\u304f\u3058<\/p>\n<ol>\n<li><a href=\"#step1\">PHPExcel\u3068\u306f<\/a><\/li>\n<li><a href=\"#step2\">\u30e1\u30ea\u30c3\u30c8\u30fb\u30c7\u30e1\u30ea\u30c3\u30c8<\/a><\/li>\n<li><a href=\"#step3\">\u4eca\u56de\u306e\u5b9f\u88c5\u5185\u5bb9<\/a><\/li>\n<li><a href=\"#step4\">PHPExcel\u306e\u6e96\u5099<\/a><\/li>\n<li><a href=\"#step5\">\u65b0\u898f\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210<\/a><\/li>\n<li><a href=\"#step6\">\u65e2\u5b58\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f<\/a><\/li>\n<li><a href=\"#step7\">\u6700\u5f8c\u306b<\/a><\/li>\n<\/ol>\n<\/div>\n<h1 id=\"step1\">PHPExcel\u3068\u306f\uff1f<\/h1>\n<p>PHP\u3067\u30a8\u30af\u30bb\u30eb\u306e\u65b0\u898f\u30d5\u30a1\u30a4\u30eb\u3092\u751f\u6210\u3057\u305f\u308a\u3001\u65e2\u5b58\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d\u304c\u53ef\u80fd\u306a\u7121\u511f\u306ePHP\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<br \/>\n\u4e00\u822c\u5411\u3051\u30b5\u30a4\u30c8\u3088\u308a\u3082\u3001\u793e\u5185\u30b7\u30b9\u30c6\u30e0\u306a\u3069\u306e\u30a8\u30af\u30bb\u30eb\u306e\u5229\u7528\u304c\u4fdd\u8a3c\u3055\u308c\u305f\u74b0\u5883\u4e0b\u3067\u306e\u30b7\u30b9\u30c6\u30e0\u3067\u4f7f\u3046\u4e8b\u304c\u591a\u3044\u3067\u3059\u3002<\/p>\n<h1 id=\"step2\">\u30e1\u30ea\u30c3\u30c8\u30fb\u30c7\u30e1\u30ea\u30c3\u30c8<\/h1>\n<p>PHP\u3067\u30a8\u30af\u30bb\u30eb\u64cd\u4f5c\u3092\u884c\u3046\u969b\u306e\u4ee3\u540d\u8a5e\u3068\u3082\u8a00\u3048\u308bPHPExcel\u306e\u3001\u30e1\u30ea\u30c3\u30c8\u30fb\u30c7\u30e1\u30ea\u30c3\u30c8\u3092\u7c21\u5358\u306b\u66f8\u3044\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30e1\u30ea\u30c3\u30c8<\/h2>\n<p>\u30fb\u7121\u6599\u3067\u5229\u7528\u3067\u304d\u308b<br \/>\n\u30fb\u8a2d\u7f6e\u304c\u7c21\u5358<br \/>\n\u30fb\u3060\u3044\u305f\u3044\u306e\u4e8b\u304c\u3067\u304d\u308b<\/p>\n<h2>\u30c7\u30e1\u30ea\u30c3\u30c8<\/h2>\n<p>\u30fb\u30e1\u30e2\u30ea\u306e\u4f7f\u7528\u91cf\u304c\u591a\u3044<\/p>\n<p>\u4eca\u307e\u3067\u4f7f\u3063\u3066\u307f\u305f\u611f\u899a\u3068\u3057\u3066\u306f\u4ee5\u4e0a\u306e\u4e8b\u3092\u5f37\u304f\u611f\u3058\u307e\u3059\u3002<br \/>\n\u30c7\u30e1\u30ea\u30c3\u30c8\u304c\uff11\u3064\u3068\u304b\u306a\u308a\u512a\u79c0\u306a\u69d8\u306b\u3082\u611f\u3058\u307e\u3059\u304c\u3001\u3053\u306e\u30c7\u30e1\u30ea\u30c3\u30c8\u304c\u610f\u5916\u3068\u6df1\u523b\u306a\u554f\u984c\u3067\u3001\u8272\u3005\u306a\u4e8b\u304c\u3067\u304d\u308b\u53cd\u9762\u3001\u7d30\u304b\u3044\u64cd\u4f5c\u3092\u884c\u3046\u3068\u51fa\u529b\u307e\u3067\u306b\u81a8\u5927\u306a\u6642\u9593\u3092\u8981\u3057\u305f\u308a\u3001\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3059\u308b\u53ef\u80fd\u6027\u3082\u3042\u308b\u306e\u3067\u3001\u8a70\u3081\u8fbc\u307f\u904e\u304e\u305f\u4f7f\u3044\u65b9\u306b\u306f\u3054\u6ce8\u610f\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1 id=\"step3\">\u4eca\u56de\u306e\u5b9f\u88c5\u5185\u5bb9<\/h1>\n<p>\u4eca\u56de\u306f\u5192\u982d\u3067\u3082\u8a71\u305f\u69d8\u306b\u3001PHPExcel\u3092\u4f7f\u3063\u3066<br \/>\n\u30fb\u65b0\u898f\u306e\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210\u3068\u5024\u306e\u8a2d\u5b9a<br \/>\n\u30fb\u30b5\u30fc\u30d0\u30fc\u4e0a\u306b\u3042\u308b\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb\u5185\u306e\u5024\u306e\u8aad\u307f\u8fbc\u307f<br \/>\n\u3053\u308c\u3089\uff12\u3064\u3092\u5b9f\u88c5\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1 id=\"step4\">PHPExcel\u306e\u6e96\u5099<\/h1>\n<p>\u307e\u305a\u306f\u3001\u4e0b\u8a18\u306e\u30b5\u30a4\u30c8\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u4e00\u5f0f\u3092ZIP\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002<\/p>\n<div class=\"externalLink\" style=\"margin: 10px 0;\"><a href=\"https:\/\/github.com\/PHPOffice\/PHPExcel\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/PHPOffice\/PHPExcel<\/a><\/div>\n<p>\u89e3\u51cd\u3059\u308b\u3068\u3001\u4e0b\u306e\u69d8\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u300cClasses\u300d\u30d5\u30a9\u30eb\u30c0\u306e\u307f\u4f5c\u696d\u30d5\u30a9\u30eb\u30c0\u3078\u30b3\u30d4\u30fc\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n<img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel.png\" alt=\"\" width=\"600\" height=\"256\" class=\"alignnone size-full wp-image-3555\" srcset=\"https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel.png 600w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel-150x64.png 150w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel-300x128.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u306e\u4f5c\u696d\u30d5\u30a9\u30eb\u30c0\u306f\u3053\u306e\u69d8\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python\r; notranslate\">\u30fb\u4f5c\u696d\u30d5\u30a9\u30eb\u30c0\r\n \u2517index.php\r\n \u2517Classes\u3000\u2190\u3000\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5f8c\u3001ZIP\u3092\u89e3\u51cd\u3059\u308b\u3068\u3042\u308b\u30d5\u30a9\u30eb\u30c0\r\n \u2517create\u3000\u2190\u3000\u4f5c\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u4fdd\u7ba1\u5148\u30d5\u30a9\u30eb\u30c0(\u7a7a\u3067OK)\r\n<\/pre>\n<p>index.php\u306e\u5185\u5bb9\u3068\u3057\u3066\u306f\u3053\u3061\u3089\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python\r; notranslate\">&lt;?php\r\n\/\/ PHPExcel\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8aad\u307f\u8fbc\u307f\r\ninclude_once ( dirname(__FILE__) . '\/Classes\/PHPExcel.php');\r\ninclude_once ( dirname(__FILE__) . '\/Classes\/PHPExcel\/IOFactory.php');\r\n\r\nif($_POST[\"create\"]){\r\n  \/\/ \u65b0\u898f\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210\u306e\u51e6\u7406\r\n}\r\nif($_POST[\"read\"]){\r\n  \/\/ \u65e2\u5b58\u30d5\u30a1\u30a4\u30eb\u8aad\u8fbc\u306e\u51e6\u7406\r\n}\r\n?&gt;\r\n\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n  &lt;meta charset=\"UTF-8\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n  &lt;form name=\"form\" action=\".\/\" method=\"post\"&gt;\r\n    &lt;input type=\"submit\" name=\"create\" value=\"\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210\"&gt;\r\n    &lt;input type=\"submit\" name=\"read\" value=\"\u30d5\u30a1\u30a4\u30eb\u8aad\u8fbc\"&gt;\r\n  &lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u3053\u308c\u3060\u3051\u3067\u30a8\u30af\u30bb\u30eb\u64cd\u4f5c\u4ee5\u5916\u306e\u6e96\u5099\u306f\u5b8c\u4e86\u3067\u3059\u3001\u3082\u306e\u51c4\u304f\u7c21\u5358\u3067\u3059\u3002<\/p>\n<h1 id=\"step5\">\u65b0\u898f\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210<\/h1>\n<p>\u3053\u3053\u304b\u3089\u304c\u30a8\u30af\u30bb\u30eb\u64cd\u4f5c\u306e\u51e6\u7406\u306b\u5165\u308a\u307e\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306f\u65b0\u898f\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3001\u5024\u3092\u30bb\u30c3\u30c8\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u307e\u3067\u884c\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u4e0b\u8a18\u306e\u5185\u5bb9\u3092\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<table class=\"type01\" style=\"width: 100%;table-layout:fixed;\">\n<tbody>\n<tr>\n<th style=\"width: 34%\">\u540d\u524d<\/th>\n<th style=\"width: 33%\">\u5e74\u9f62<\/th>\n<th style=\"width: 33%\">\u6c0f\u540d<\/th>\n<\/tr>\n<tr>\n<td>\u5c71\u7530<\/td>\n<td>20<\/td>\n<td>\u7537\u6027<\/td>\n<\/tr>\n<tr>\n<td>\u4f50\u85e4<\/td>\n<td>25<\/td>\n<td>\u5973\u6027<\/td>\n<\/tr>\n<tr>\n<td>\u7530\u4e2d<\/td>\n<td>32<\/td>\n<td>\u7537\u6027<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u30b3\u30fc\u30c9\u306f\u3053\u3061\u3089\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u307e\u3067\u3092\u8a18\u8ff0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python\r; notranslate\">\/\/ \u4f5c\u6210\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u4fdd\u5b58\u5148\u30d1\u30b9\r\n$path = \".\/create\/\";\r\n$file = \"sample.xlsx\";\r\n\/\/ \u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u6642\u306e\u30d5\u30a1\u30a4\u30eb\u540d\r\n$dl_file = \"\u30b5\u30f3\u30d7\u30eb.xlsx\";\r\n\r\n\/\/ PHPExcel\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u4f5c\u6210\r\n$obj = new PHPExcel();\r\n\r\n\/\/ \u30b7\u30fc\u30c8\u3092\u9078\u629e(0\u304c1\u3064\u76ee\u306e\u30b7\u30fc\u30c8\u3067\u3059)\r\n$obj->setActiveSheetIndex(0);\r\n\/\/ \u64cd\u4f5c\u3059\u308b\u30b7\u30fc\u30c8\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\r\n$sheet = $obj->getActiveSheet();\r\n\/\/ \u30b7\u30fc\u30c8\u540d\u3092\u8a2d\u5b9a\r\n$sheet->setTitle(\"\u30b7\u30fc\u30c8\u540d\");\r\n\r\n\/\/ \u5185\u5bb9\u3092\u8a2d\u5b9a\r\n$sheet->setCellValue(\"A1\", \"\u5c71\u7530\");\r\n$sheet->setCellValue(\"A2\", \"\u4f50\u85e4\");\r\n$sheet->setCellValue(\"A3\", \"\u7530\u4e2d\");\r\n\r\n$sheet->setCellValue(\"B1\", \"20\");\r\n$sheet->setCellValue(\"B2\", \"25\");\r\n$sheet->setCellValue(\"B3\", \"32\");\r\n\r\n$sheet->setCellValue(\"C1\", \"\u7537\u6027\");\r\n$sheet->setCellValue(\"C2\", \"\u5973\u6027\");\r\n$sheet->setCellValue(\"C3\", \"\u7537\u6027\");\r\n\r\n\/\/ \u30d5\u30a1\u30a4\u30eb\u306e\u4fdd\u5b58\r\n$writer = PHPExcel_IOFactory::createWriter($obj, 'Excel2007');\r\n$writer->save($path.$file);\r\n\r\n\/\/ \u30e1\u30e2\u30ea\u306e\u89e3\u653e\r\n$obj->disconnectWorksheets();\r\nunset($obj);\r\n\r\n\/\/ \u30d5\u30a1\u30a4\u30eb\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\r\nheader('Content-Type: application\/force-download');\r\nheader('Content-Length: '.filesize($path.$file));\r\nheader('Content-Disposition: attachment; filename=\"'.mb_convert_encoding($dl_file, 'SJIS-win', 'UTF-8').'\"');\r\nreadfile($path.$file);\r\nexit();\r\n<\/pre>\n<p>\u51fa\u529b\u7d50\u679c<br \/>\n<img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel2.png\" alt=\"\" width=\"346\" height=\"139\" class=\"alignnone size-full wp-image-3560\" srcset=\"https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel2.png 346w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel2-150x60.png 150w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2018\/03\/phpexcel2-300x121.png 300w\" sizes=\"(max-width: 346px) 100vw, 346px\" \/><\/p>\n<p>\u8981\u6240\u306b\u30b3\u30e1\u30f3\u30c8\u3092\u66f8\u3044\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u305e\u308c\u306e\u547d\u4ee4\u304c\u4f55\u3092\u3057\u3066\u3044\u308b\u304b\u306f\u308f\u304b\u3063\u3066\u3044\u305f\u3060\u3051\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u30011\u70b9\u3060\u3051\uff01<br \/>\n35,36\u884c\u76ee\u306e<span style=\"color:#f00;\">\u30e1\u30e2\u30ea\u306e\u89e3\u653e<\/span>\u306f\u5fc5\u305a\u884c\u3044\u307e\u3057\u3087\u3046\uff01<br \/>\n\u3053\u306e\u30e1\u30e2\u30ea\u306e\u89e3\u653e\u3092\u5fd8\u308c\u3066\u3057\u307e\u3046\u3068\u30e1\u30e2\u30ea\u3092\u5927\u304d\u304f\u53d6\u3089\u308c\u305f\u72b6\u614b\u306b\u306a\u308b\u305f\u3081\u3001\u305d\u306e\u4ed6\u306e\u51e6\u7406\u306b\u5f71\u97ff\u3057\u304b\u306d\u307e\u305b\u3093\uff01<br \/>\n\u7d30\u304b\u3044\u51e6\u7406\u3092\u7d44\u3080\u524d\u306b\u6700\u521d\u304b\u3089\u66f8\u3044\u3066\u304a\u304f\u3053\u3068\u3092\u30aa\u30b9\u30b9\u30e1\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30bb\u30eb\u306b\u5024\u3092\u30bb\u30c3\u30c8\u3059\u308b\u5225\u306e\u65b9\u6cd5<\/h2>\n<p>\u4e0a\u306e\u30b3\u30fc\u30c9\u3067\u306f&#8221;A1&#8243;\u3084&#8221;B2&#8243;\u306e\u69d8\u306a\u30bb\u30eb\u6307\u5b9a\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u51fa\u529b\u3059\u308b\u5024\u3092\u914d\u5217\u3067\u7ba1\u7406\u3057\u3066\u3044\u3066\u30eb\u30fc\u30d7\u3092\u4f7f\u3063\u305f\u51fa\u529b\u3092\u8003\u3048\u305f\u6642\u306b\u5c11\u3057\u4e0d\u4fbf\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h3>setCellValueByColumnAndRow\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u305d\u3053\u3067\u3001setCellValueByColumnAndRow\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u51fa\u529b\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python\r; notranslate\">\/\/ \u914d\u5217\u306e\u4f5c\u6210\r\n$ary[0][\"name\"] = \"\u5c71\u7530\";\r\n$ary[0][\"age\"] = \"20\";\r\n$ary[0][\"gender\"] = \"\u7537\u6027\";\r\n$ary[1][\"name\"] = \"\u4f50\u85e4\";\r\n$ary[1][\"age\"] = \"25\";\r\n$ary[1][\"gender\"] = \"\u5973\u6027\";\r\n$ary[2][\"name\"] = \"\u7530\u4e2d\";\r\n$ary[2][\"age\"] = \"32\";\r\n$ary[2][\"gender\"] = \"\u7537\u6027\";\r\n\r\n\/\/ \u30bb\u30eb\u306b\u5024\u3092\u30bb\u30c3\u30c8\r\n$i = 0;\r\nforeach ($ary as $data => $val) {\r\n  $i++;\r\n  $sheet->setCellValueByColumnAndRow(0, $i, $val[\"name\"]);\r\n  $sheet->setCellValueByColumnAndRow(1, $i, $val[\"age\"]);\r\n  $sheet->setCellValueByColumnAndRow(2, $i, $val[\"gender\"]);\r\n}\r\n<\/pre>\n<p>setCellValueByColumnAndRow(\u5217\u756a\u53f7,\u884c\u756a\u53f7,\u5024);<br \/>\n\u3068\u8a00\u3046\u69d8\u306b\u5f15\u6570\u3092\u6e21\u3059\u3068\u8a72\u5f53\u7b87\u6240\u306b\u5024\u3092\u30bb\u30c3\u30c8\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u3001\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u4f7f\u3044\u5206\u3051\u3066\u304f\u3060\u3055\u3044\uff01<br \/>\n\u3053\u306e\u30b3\u30fc\u30c9\u306b\u5dee\u3057\u66ff\u3048\u305f\u30b5\u30f3\u30d7\u30eb\u3067\u3082\u51fa\u529b\u7d50\u679c\u306f\u540c\u3058\u3082\u306e\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067\u8a18\u8ff0\u3059\u308c\u3070\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb\u306e\u65b0\u898f\u4f5c\u6210\u5b8c\u4e86\u3067\u3059\uff01<\/p>\n<h1 id=\"step6\">\u65e2\u5b58\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f<\/h1>\n<p>\u6b21\u306b\u65e2\u5b58\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u304b\u3089\u5024\u3092\u53d6\u5f97\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u53d6\u5f97\u3060\u3051\u306a\u3089\u3082\u306e\u3059\u3054\u304f\u7c21\u5358\u3067\u3001\u4e0b\u306e\u30b3\u30fc\u30c9\u3060\u3051\u3067\u8aad\u307f\u8fbc\u3081\u307e\u3059\uff01<br \/>\n\u3061\u306a\u307f\u306b\u8aad\u307f\u8fbc\u307f\u30d5\u30a1\u30a4\u30eb\u306f\u4e0a\u3067\u4f5c\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python\r; notranslate\">\/\/ \u8aad\u8fbc\u3059\u308b\u30d5\u30a1\u30a4\u30eb\r\n$readFile = \".\/create\/sample.xlsx\";\r\n\r\n\/\/ \u6307\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\r\n$objPExcel = PHPExcel_IOFactory::load($readFile);\r\n\/\/ \u8aad\u307f\u8fbc\u3093\u3060\u30a8\u30af\u30bb\u30eb\u306e\u53c2\u7167\u30b7\u30fc\u30c8\u3092\u6307\u5b9a\r\n$sheet = $objPExcel->getActiveSheet(0);\r\n\/\/ \u914d\u5217\u3067\u4fdd\u6301\u3059\u308b\r\n$ary = $sheet->toArray(null,true,true,true);\r\n\r\n\/\/ \u7d50\u679c\u3092\u51fa\u529b\u3057\u3066\u307f\u308b\r\necho \"&lt;pre&gt;\";\r\nprint_r($ary);\r\necho \"&lt;\/pre&gt;\";\r\n<\/pre>\n<p>\u7d50\u679c\u304c\u3053\u3061\u3089<\/p>\n<pre class=\"brush: python\r; notranslate\">Array(\r\n\u3000[1] => Array(\r\n\u3000\u3000[A] => \u5c71\u7530\r\n\u3000\u3000[B] => 20\r\n\u3000\u3000[C] => \u7537\u6027\r\n\u3000)\r\n\r\n\u3000[2] => Array(\r\n\u3000\u3000[A] => \u4f50\u85e4\r\n\u3000\u3000[B] => 25\r\n\u3000\u3000[C] => \u5973\u6027\r\n\u3000)\r\n\r\n\u3000[3] => Array(\r\n\u3000\u3000[A] => \u7530\u4e2d\r\n\u3000\u3000[B] => 32\r\n\u3000\u3000[C] => \u7537\u6027\r\n\u3000)\r\n)\r\n<\/pre>\n<p>\u884c\u30fb\u5217\u306e\u4e8c\u6b21\u5143\u914d\u5217\u3067\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002<br \/>\n\u3053\u3053\u307e\u3067\u51fa\u6765\u3066\u3044\u308c\u3070\u3001\u3042\u3068\u306f\u597d\u304d\u306b\u3067\u304d\u307e\u3059\u306d\uff01<\/p>\n<h2>\u30bb\u30eb\u3092\u6307\u5b9a\u3057\u3066\u5024\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u5148\u307b\u3069\u306e\u65b9\u6cd5\u306f\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u5168\u3066\u306e\u5024\u3092\u914d\u5217\u306b\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u6307\u5b9a\u3057\u305f\u30bb\u30eb\u306e\u5024\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>getCellByColumnAndRow\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>getCellByColumnAndRow(\u5217[int],\u884c[int])\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3048\u3070\u6307\u5b9a\u30bb\u30eb\u306e\u5024\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<br \/>\n\u3053\u306e\u65b9\u6cd5\u306e\u30e1\u30ea\u30c3\u30c8\u3068\u3057\u3066\u306f<br \/>\n\u30fb\u5fc5\u8981\u306a\u30bb\u30eb\u306e\u5024\u3060\u3051\u3092\u53d6\u5f97\u3067\u304d\u308b<br \/>\n\u30fb\u53d6\u5f97\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u5024\u306e\u52a0\u5de5\u304c\u51fa\u6765\u308b<br \/>\n\u30fb\u597d\u304d\u306a\u5f62\u3067\u914d\u5217\u304c\u4f5c\u308c\u308b<br \/>\n\u3068\u8a00\u3046\u3068\u3053\u308d\u304b\u3068\u601d\u3044\u307e\u3059\u3001\u3061\u306a\u307f\u306b\u79c1\u306f\u3053\u3061\u3089\u306e\u65b9\u6cd5\u3092\u3088\u304f\u4f7f\u3044\u307e\u3059\u3002<br \/>\n\u7279\u306b\u30a8\u30af\u30bb\u30eb\u306f\u30bb\u30eb\u6bce\u306b\u5f62\u5f0f\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u3066\u3001\u610f\u56f3\u3057\u3066\u3044\u306a\u3044\u5f62\u3067\u53d6\u5f97\u3059\u308b\u4e8b\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u305d\u306e\u969b\u306b\u306f\u5f62\u5f0f\u3092\u623b\u3059\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3001\u3053\u3061\u3089\u306e\u65b9\u304c\u90fd\u5408\u3088\u304f\u51e6\u7406\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python\r; notranslate\">for($i=1;$i<=$sheet->getHighestRow();$i++){\r\n  $idx = $i-1;\r\n  \/\/ \u540d\u524d\u306e\u53d6\u5f97\r\n  $ary[$idx][\"name\"] = $sheet->getCellByColumnAndRow(0, $i)->getValue();\r\n  \/\/ \u5e74\u9f62\u306e\u53d6\u5f97\r\n  $ary[$idx][\"age\"] = $sheet->getCellByColumnAndRow(1, $i)->getValue();\r\n  \/\/ \u6027\u5225\u306e\u53d6\u5f97\r\n  $ary[$idx][\"gender\"] = $sheet->getCellByColumnAndRow(2, $i)->getValue();\r\n}\r\n\r\n\/\/ \u7d50\u679c\u3092\u51fa\u529b\u3057\u3066\u307f\u308b\r\necho \"&lt;pre&gt;\";\r\nprint_r($ary);\r\necho \"&lt;\/pre&gt;\";\r\n<\/pre>\n<p>\u7d50\u679c\u306f\u3053\u3061\u3089<\/p>\n<pre class=\"brush: python\r; notranslate\">Array(\r\n\u3000[0] => Array(\r\n\u3000\u3000[name] => \u5c71\u7530\r\n\u3000\u3000[age] => 20\r\n\u3000\u3000[gender] => \u7537\u6027\r\n\u3000)\r\n\r\n\u3000[1] => Array(\r\n\u3000\u3000[name] => \u4f50\u85e4\r\n\u3000\u3000[age] => 25\r\n\u3000\u3000[gender] => \u5973\u6027\r\n\u3000)\r\n\r\n\u3000[2] => Array(\r\n\u3000\u3000[name] => \u7530\u4e2d\r\n\u3000\u3000[age] => 32\r\n\u3000\u3000[gender] => \u7537\u6027\r\n\u3000)\r\n)\r\n<\/pre>\n<p>\u3053\u306e\u69d8\u306b\u914d\u5217\u304c\u4f5c\u308b\u4e8b\u304c\u3067\u304d\u307e\u3057\u305f\u3002<br \/>\n\u3069\u3061\u3089\u306e\u65b9\u6cd5\u3067\u3082\u826f\u3044\u3068\u601d\u3046\u306e\u3067\u4f5c\u696d\u3057\u3084\u3059\u3044\u65b9\u3067\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n<h1 id=\"step7\">\u6700\u5f8c\u306b<\/h1>\n<p>\u4eca\u56de\u306fPHPExcel\u306e\u57fa\u672c\u90e8\u5206\u3060\u3051\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<br \/>\n\u4ed6\u306b\u3082\u7dda\u3092\u5f15\u3044\u305f\u308a\u3001\u8272\u3092\u5857\u3063\u305f\u308a\u3001\u30b5\u30a4\u30ba\u3092\u5909\u3048\u305f\u308a\u306a\u3069\u8272\u3005\u306a\u4e8b\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001\u305d\u3053\u306f\u307e\u305f\u6a5f\u4f1a\u304c\u3042\u308c\u3070\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u30b7\u30b9\u30c6\u30e0\u6848\u4ef6\u4ee5\u5916\u306b\u3082\u30c7\u30fc\u30bf\u306e\u30b3\u30f3\u30d0\u30fc\u30c8\u3067\u4f7f\u3063\u305f\u308a\u3068\u6d3b\u8e8d\u3057\u3066\u304d\u305fPHPExcel\u3067\u3059\u306e\u3067\u3001\u3054\u5b58\u77e5\u306a\u304b\u3063\u305f\u65b9\u306f\u305c\u3072\u3053\u306e\u6a5f\u4f1a\u306b\u4f7f\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n<p>\u5168\u4f53\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u8f09\u305b\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python\r; notranslate\">&lt;?php\r\n\/\/ PHPExcel\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8aad\u307f\u8fbc\u307f\r\ninclude_once ( dirname(__FILE__) . '\/Classes\/PHPExcel.php');\r\ninclude_once ( dirname(__FILE__) . '\/Classes\/PHPExcel\/IOFactory.php');\r\n\r\nif($_POST[\"create\"]){\r\n  \/\/ \u65b0\u898f\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210\u306e\u51e6\u7406\r\n  create_file();\r\n}\r\nif($_POST[\"read\"]){\r\n  \/\/ \u65e2\u5b58\u30d5\u30a1\u30a4\u30eb\u8aad\u8fbc\u306e\u51e6\u7406\r\n  read_file();\r\n}\r\n\r\nfunction create_file(){\r\n  \/\/ \u4f5c\u6210\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u4fdd\u5b58\u5148\u30d1\u30b9\r\n  $path = \".\/create\/\";\r\n  $file = \"sample.xlsx\";\r\n  \/\/ \u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u6642\u306e\u30d5\u30a1\u30a4\u30eb\u540d\r\n  $dl_file = \"\u30b5\u30f3\u30d7\u30eb.xlsx\";\r\n\r\n  \/\/ PHPExcel\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u4f5c\u6210\r\n  $obj = new PHPExcel();\r\n\r\n  \/\/ \u30b7\u30fc\u30c8\u3092\u9078\u629e(0\u304c1\u3064\u76ee\u306e\u30b7\u30fc\u30c8\u3067\u3059)\r\n  $obj->setActiveSheetIndex(0);\r\n  \/\/ \u64cd\u4f5c\u3059\u308b\u30b7\u30fc\u30c8\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\r\n  $sheet = $obj->getActiveSheet();\r\n  \/\/ \u30b7\u30fc\u30c8\u540d\u3092\u8a2d\u5b9a\r\n  $sheet->setTitle(\"\u30b7\u30fc\u30c8\u540d\");\r\n\r\n  \/\/ \u5185\u5bb9\u3092\u8a2d\u5b9a\r\n  $sheet->setCellValue(\"A1\", \"\u5c71\u7530\");\r\n  $sheet->setCellValue(\"A2\", \"\u4f50\u85e4\");\r\n  $sheet->setCellValue(\"A3\", \"\u7530\u4e2d\");\r\n\r\n  $sheet->setCellValue(\"B1\", \"20\");\r\n  $sheet->setCellValue(\"B2\", \"25\");\r\n  $sheet->setCellValue(\"B3\", \"32\");\r\n\r\n  $sheet->setCellValue(\"C1\", \"\u7537\u6027\");\r\n  $sheet->setCellValue(\"C2\", \"\u5973\u6027\");\r\n  $sheet->setCellValue(\"C3\", \"\u7537\u6027\");\r\n\r\n  \/\/ \u30d5\u30a1\u30a4\u30eb\u306e\u4fdd\u5b58\r\n  $writer = PHPExcel_IOFactory::createWriter($obj, 'Excel2007');\r\n  $writer->save($path.$file);\r\n\r\n  \/\/ \u30e1\u30e2\u30ea\u306e\u89e3\u653e\r\n  $obj->disconnectWorksheets();\r\n  unset($obj);\r\n\r\n  \/\/ \u30d5\u30a1\u30a4\u30eb\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\r\n  header('Content-Type: application\/force-download');\r\n  header('Content-Length: '.filesize($path.$file));\r\n  header('Content-Disposition: attachment; filename=\"'.mb_convert_encoding($dl_file, 'SJIS-win', 'UTF-8').'\"');\r\n  readfile($path.$file);\r\n  exit();\r\n}\r\n\r\nfunction read_file(){\r\n  \/\/ \u8aad\u8fbc\u3059\u308b\u30d5\u30a1\u30a4\u30eb\r\n  $readFile = \".\/create\/sample.xlsx\";\r\n\r\n  \/\/ \u6307\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\r\n  $obj = PHPExcel_IOFactory::load($readFile);\r\n  \/\/ \u8aad\u307f\u8fbc\u3093\u3060\u30a8\u30af\u30bb\u30eb\u306e\u53c2\u7167\u30b7\u30fc\u30c8\u3092\u6307\u5b9a\r\n  $sheet = $obj->getActiveSheet(0);\r\n  \/\/ \u914d\u5217\u3067\u4fdd\u6301\u3059\u308b\r\n  $ary = $sheet->toArray(null,true,true,true);\r\n\r\n  \/\/ \u7d50\u679c\u3092\u51fa\u529b\u3057\u3066\u307f\u308b\r\n  echo \"&lt;pre&gt;\";\r\n  print_r($ary);\r\n  echo \"&lt;\/pre&gt;\";\r\n\r\n  \/\/ \u30e1\u30e2\u30ea\u306e\u89e3\u653e\r\n  $obj->disconnectWorksheets();\r\n  unset($obj);\r\n}\r\n?&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n  &lt;meta charset=\"UTF-8\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n  &lt;form name=\"form\" action=\".\/\" method=\"post\"&gt;\r\n    &lt;input type=\"submit\" name=\"create\" value=\"\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210\"&gt;\r\n    &lt;input type=\"submit\" name=\"read\" value=\"\u30d5\u30a1\u30a4\u30eb\u8aad\u8fbc\"&gt;\r\n  &lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306fWEB\u306e\u4f50\u91ce\u3067\u3059\u3001\u3082\u3046\u3059\u3050\u685c\u306e\u5b63\u7bc0\u3067\u3059\u306d\u3002 \u79c1\u306f\u6700\u8fd1\u3001\u76ee\u304c\u75d2\u304f\u3066\u3001\u9f3b\u304c\u8a70\u3063\u3066\u3001\u304f\u3057\u3083\u307f\u304c\u3088\u304f\u51fa\u307e\u3059\u3002 \u82b1\u898b\u306e\u5b63\u7bc0\u306a\u306e\u306b\u3001\u82b1\u7c89\u75c7\u3067\u8f9b\u3044\u3067\u3059\u3002 \u305d\u3093\u306a\u6642\u306b\u306f\u3053\u308c\u3092\u898b\u3066\u82b1\u898b\u6c17\u5206\u3092\u5473\u308f\u3044\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 Canvas\u3067 [&hellip;]<\/p>\n","protected":false},"author":25,"featured_media":3586,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[23,112,113],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts\/3529"}],"collection":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/comments?post=3529"}],"version-history":[{"count":57,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts\/3529\/revisions"}],"predecessor-version":[{"id":4791,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts\/3529\/revisions\/4791"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/media\/3586"}],"wp:attachment":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/media?parent=3529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/categories?post=3529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/tags?post=3529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}