{"id":3945,"date":"2019-06-21T02:51:11","date_gmt":"2019-06-20T17:51:11","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=3945"},"modified":"2020-04-14T02:28:35","modified_gmt":"2020-04-13T17:28:35","slug":"phpspreadsheet%e3%81%a7excel%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b%e5%85%a826%e5%ae%9f%e4%be%8b%ef%bc%81","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=3945","title":{"rendered":"PhpSpreadsheet\u3067Excel\u3092\u64cd\u4f5c\u3059\u308b\u516828\u5b9f\u4f8b\uff01"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u30a6\u30a7\u30d6\u958b\u767a\u306e\u5206\u91ce\u306f\u7279\u306b\u5909\u5316\u306e\u30b9\u30d4\u30fc\u30c9\u304c\u901f\u3044\u696d\u754c\u3067\u3059\u306e\u3067\u3001\u5c11\u3057\u524d\u307e\u3067\u4f7f\u3063\u3066\u3044\u305f\u6280\u8853\u304c<strong>\u305f\u3063\u305f\uff12\u3001\uff13\u5e74\u3067\u53e4\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u3053\u3068\u3082\u7d50\u69cb\u30b6\u30e9\u306b\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/strong><\/p>\n<p>\u305d\u306e\u305f\u3081\u666e\u6bb5\u304b\u3089\u65b0\u3057\u3044\u60c5\u5831\u306f\u5e38\u306b\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u305d\u308c\u3067\u3082\u5168\u3066\u3092\u30ab\u30d0\u30fc\u3059\u308b\u3053\u3068\u306f\u96e3\u3057\u3044\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u4eca\u56de\u7d39\u4ecb\u3059\u308b<strong>\u300cPhpSpreadsheet\u300d<\/strong>\u3082\u305d\u306e\u3072\u3068\u3064\u3067\u3001\u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u5c11\u3057\u524d\u307e\u3067\u306f<code>PhpExcel<\/code>\u3068\u3044\u3046\u540d\u524d\u3067\u516c\u958b\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u3002\u3057\u304b\u3057\u3001\u3069\u3046\u3084\u3089<code>PhpExcel<\/code>\u306f2017\u5e74\u306b\u975e\u63a8\u5968\u3068\u306a\u308a\u3001\u73fe\u5728\u306f<code>PhpSpreadsheet<\/code>\u3068\u3057\u3066\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u3055\u308c\u3066\u3044\u307e\u3059\u3002\uff08\u516c\u5f0f\u306eGitHub\u306b\u3088\u308b\u30682015\u5e74\u306b\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u30662017\u5e74\u306b\u975e\u63a8\u5968\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u305f\u3063\u305f\uff12\u5e74\u3060\u3063\u305f\u3093\u3067\u3059\u306d\u30fb\u30fb\u30fb\ud83d\ude05\uff09<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<strong>PHP\u3067Excel\u3092\u4f5c\u6210\u3084\u8aad\u307f\u8fbc\u307f\u306a\u3069\u304c\u3067\u304d\u308b<code>PhpSpreadsheet<\/code>\u306e\u4f7f\u3044\u65b9\u3092\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/strong><\/p>\n<p>\u6700\u5f8c\u306b\u4eca\u56de\u5b9f\u969b\u306b\u4f7f\u3063\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\uff01<br \/>\n\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3566 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1.png\" alt=\"\" width=\"306\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1.png 306w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1-287x300.png 287w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/p>\n<p><strong>\u3010\u8ffd\u8a18\uff1a2020.4.14\u3011<br \/>\n<\/strong>\u3053\u306e\u8a18\u4e8b\u306f\u30012019\u5e746\u670821\u65e5\u306b\u6295\u7a3f\u3055\u308c\u305f\u5185\u5bb9\u306b\u52a0\u7b46\u4fee\u6b63\u3055\u308c\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<h1>\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h1>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>composer require phpoffice\/phpspreadsheet<\/strong><\/pre>\n<p>\u203b \u79c1\u306e\u74b0\u5883\u306f<code>Laravel<\/code>\u3067\u3059\u304c\u3001<code>PhpSpreadsheet<\/code>\u306fPHP\u5168\u822c\u3067\u5229\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n<h1>PhpSpreadsheet\u3067Excel\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b<\/h1>\n<h2>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h2>\n<pre><strong>$spreadsheet = new \\PhpOffice\\PhpSpreadsheet\\Spreadsheet();<\/strong>\r\n<strong>$sheet = $spreadsheet-&gt;getActiveSheet();<\/strong>\r\n\r\n\/\/ \u3053\u3053\u3067 $sheet \u3092\u901a\u3057\u3066\u30bb\u30eb\u306a\u3069\u3092\u64cd\u4f5c\u3057\u307e\u3059\u3002\r\n\r\n<strong>$writer = new \\PhpOffice\\PhpSpreadsheet\\Writer\\Xlsx($spreadsheet);<\/strong>\r\n<strong>$writer-&gt;save('\/PATH\/TO\/YOUR\/PROJECT\/test.xlsx');<\/strong><\/pre>\n<h2>\u30bb\u30eb\u306e\u5165\u529b<\/h2>\n<p>\u30bb\u30eb\u306b\u6587\u5b57\u3084\u6570\u5b57\u3092\u5165\u529b\u3059\u308b\u306b\u306f\u3001<code>setCellValue()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setCellValue('A1', '\u30c6\u30b9\u30c8\u6587\u5b57\u5217');<\/strong>\r\n<strong>$sheet-&gt;setCellValue('B1', 100);<\/strong>\r\n<strong>$sheet-&gt;setCellValue('C1', true);<\/strong>\r\n<strong>$sheet-&gt;setCellValue('D1', null);<\/strong>   \/\/ \u7a7a\u767d<\/pre>\n<p>\u203b <code>setCellValue()<\/code>\u3092\u4f7f\u3063\u305f\u5834\u5408\u3001\u81ea\u52d5\u7684\u306b\u66f8\u5f0f\u304c\u6c7a\u5b9a\u3055\u308c\u307e\u3059\u3002\u66f8\u5f0f\u3092\u660e\u78ba\u306b\u6c7a\u5b9a\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u6b21\u306e<code>setCellValueExplicit()<\/code>\u3092\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u66f8\u5f0f\u3092\u6307\u5b9a\u3057\u3066\u30bb\u30eb\u306b\u5165\u529b\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300c\u6570\u5b57\u306a\u3093\u3060\u3051\u3069\u6587\u5b57\u5217\u3068\u3057\u3066\u30bb\u30eb\u306b\u5165\u529b\u3057\u305f\u3044\u300d\u3068\u3044\u3046\u5834\u5408\u3067\u3059\u3002<br \/>\n\u305d\u306e\u5834\u5408\u3001<code>setCellValueExplicit()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setCellValueExplicit(<\/strong>\r\n<strong>    'E1',<\/strong>\r\n<strong>    '012345',<\/strong>\r\n<strong>    \\PhpOffice\\PhpSpreadsheet\\Cell\\DataType::TYPE_STRING<\/strong>\r\n<strong>);<\/strong><\/pre>\n<p>\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u306f\u4e3b\u306b\u4ed6\u306b\u3082\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u6587\u5b57\u5217\u3000\u30fb\u30fb\u30fb\u3000DataType::TYPE_STRING<\/li>\n<li>\u6570\u5b57\u3000\u30fb\u30fb\u30fb\u3000DataType::TYPE_NUMERIC<\/li>\n<li>true \/ false\u3000\u30fb\u30fb\u30fb\u3000DataType::TYPE_BOOL<\/li>\n<li>null\u3000\u30fb\u30fb\u30fb\u3000DataType::TYPE_NULL<\/li>\n<li>\u5f0f\u3000\u30fb\u30fb\u30fb\u3000DataType::TYPE_FORMULA<\/li>\n<\/ul>\n<h2>\u6539\u884c\u3092\u542b\u3080\u30c6\u30ad\u30b9\u30c8\u3092\u5165\u529b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8907\u6570\u884c\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u5165\u529b\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>1\u884c\u76ee\r\n2\u884c\u76ee\r\n3\u884c\u76ee<\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001\u6b21\u306e\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>$text = \"1\u884c\u76ee\\n2\u884c\u76ee\\n3\u884c\u76ee\";\r\n$sheet-&gt;getStyle('A1')\r\n    -&gt;getAlignment()\r\n    -&gt;setWrapText(true);\r\n$sheet-&gt;setCellValue('A1', $text);\r\n<\/strong><\/pre>\n<h2>\u90f5\u4fbf\u756a\u53f7\u3068\u3057\u3066\u5165\u529b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300c\u5143\u306e\u90f5\u4fbf\u756a\u53f7\u30c7\u30fc\u30bf\u306f\u6570\u5b57\u3060\u3051\u306a\u3093\u3060\u3051\u3069\u3001\u30cf\u30a4\u30d5\u30f3\u3092\u3044\u308c\u305f\u3044\u300d\u3068\u3044\u3046\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;getStyle('F1')<\/strong>\r\n<strong>    -&gt;getNumberFormat()<\/strong>\r\n<strong>    -&gt;setFormatCode('000-0000');<\/strong>\r\n<strong>$sheet-&gt;setCellValue('F1', 1310045);<\/strong><\/pre>\n<p>\u203b <code>000-0000<\/code>\u306e\u90e8\u5206\u304c\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u65e5\u6642\u3068\u3057\u3066\u5165\u529b<\/h2>\n<p>\u30bb\u30eb\u306b\u65e5\u6642\u3092\u5165\u529b\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3068<code>Date::PHPToExcel<\/code>\u3092\u5229\u7528\u3057\u3066\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;getStyle('G1')<\/strong>\r\n<strong>    -&gt;getNumberFormat()<\/strong>\r\n<strong>    -&gt;setFormatCode('yyyy-mm-dd h:mm:ss');<\/strong>\r\n<strong>$datetime = \\PhpOffice\\PhpSpreadsheet\\Shared\\Date::PHPToExcel('2019\/01\/01 01:02:03');<\/strong>\r\n<strong>$sheet-&gt;setCellValue('G1', $datetime);<\/strong><\/pre>\n<h2>\u30ea\u30f3\u30af\u3092\u5165\u529b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u30af\u30ea\u30c3\u30af\u3057\u305f\u3089\u30d6\u30e9\u30a6\u30b6\u3067URL\u3092\u958b\u304f\u30ea\u30f3\u30af\u3092\u3064\u304f\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setCellValue('A1', '\u30ea\u30f3\u30af\u6587\u5b57\u5217');<\/strong>\r\n<strong>$sheet-&gt;getCell('A1')<\/strong>\r\n<strong>    -&gt;getHyperlink()<\/strong>\r\n<strong>    -&gt;setUrl('http:\/\/example.com');<\/strong><\/pre>\n<h2>\u4e00\u6c17\u306b\u5165\u529b<\/h2>\n<p>\u3082\u3061\u308d\u3093\u4e00\u500b\u305a\u3064\u30bb\u30eb\u306b\u30c7\u30fc\u30bf\u5165\u529b\u3057\u3066\u3082\u3044\u3044\u3067\u3059\u304c\u3001\u3082\u3057\u30c7\u30fc\u30bf\u304c\u5927\u91cf\u306b\u3042\u308b\u5834\u5408\u306f\u52b9\u7387\u3088\u304f\u5b9f\u884c\u3057\u305f\u3044\u3082\u306e\u3067\u3059\u3002\u305d\u3093\u306a\u5834\u5408\u306f<code>fromArray()<\/code>\u3067\u4e00\u6c17\u306b\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>$data = [<\/strong>\r\n<strong>    ['\u30c6\u30b9\u30c81-1', '\u30c6\u30b9\u30c81-2', '\u30c6\u30b9\u30c81-3'],<\/strong>\r\n<strong>    ['\u30c6\u30b9\u30c82-1', '\u30c6\u30b9\u30c82-2', '\u30c6\u30b9\u30c82-3'],<\/strong>\r\n<strong>    ['\u30c6\u30b9\u30c83-1', '\u30c6\u30b9\u30c83-2', '\u30c6\u30b9\u30c83-3']<\/strong>\r\n<strong>];<\/strong>\r\n<strong>$exception_value = '\u30c6\u30b9\u30c82-2';<\/strong>   \/\/ \u3053\u306e\u5024\u306e\u3082\u306e\u306f\u53cd\u6620\u3055\u308c\u306a\u3044\uff08\u5168\u3066\u53cd\u6620\u3059\u308b\u306b\u306fnull\u3092\u6307\u5b9a\uff09\r\n<strong>$sheet-&gt;fromArray($data, $exception_value, 'A3');<\/strong><\/pre>\n<p>\u203b \u3053\u306e\u5834\u5408<code>A3<\/code>\u306b\u300c\u30c6\u30b9\u30c81-1\u300d\u304c\u5165\u529b\u3055\u308c\u3001\u305d\u3053\u304b\u3089\u53f3\u65b9\u5411\u3068\u4e0b\u65b9\u5411\u306e\u30bb\u30eb\u306b\u30c7\u30fc\u30bf\u5165\u529b\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u5f0f\u306e\u5165\u529b<\/h2>\n<p>\u30a8\u30af\u30bb\u30eb\u306b\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u69d8\u3005\u306a\u5f0f\u3092\u5165\u529b\u3057\u305f\u3044\u5834\u5408\u3067\u3059\u3002<br \/>\n\u6b21\u306e\u4f8b\u3067\u306f\u3001\uff12\u3064\u306e\u30bb\u30eb\u306e\u6587\u5b57\u3092\u7d50\u5408\u3057\u3066\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setCellValue('A7', '=CONCATENATE(A1, \" - \", B1)');<\/strong><\/pre>\n<h2>\u30bb\u30eb\u306e\u7d50\u5408<\/h2>\n<p>\uff12\u3064\u306e\u30bb\u30eb\u3092\u7d50\u5408\u3059\u308b\u5834\u5408\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u3001<code>A9<\/code>\u3068<code>C9<\/code>\u3092\u7d50\u5408\u3057\u3066\u3072\u3068\u3064\u306e\u30bb\u30eb\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;mergeCells('A9:C9');<\/strong>\r\n<strong>$sheet-&gt;setCellValue('A9', '\u7d50\u5408\u3055\u308c\u305f\u30bb\u30eb');<\/strong><\/pre>\n<h2>\u6539\u30da\u30fc\u30b8<\/h2>\n<p>\u6539\u30da\u30fc\u30b8\u3092\u8a2d\u5b9a\u3057\u305f\u3044\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setBreak('A11', \\PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet::BREAK_ROW);\r\n<\/strong><\/pre>\n<h2>\u30c9\u30ed\u30c3\u30d7\u30c0\u30a6\u30f3\u3092\u4f5c\u6210\u3059\u308b<\/h2>\n<h3>\u9078\u629e\u80a2\u3092\u76f4\u63a5\u6307\u5b9a\u3059\u308b\u5834\u5408<\/h3>\n<p>\u9078\u629e\u80a2\u3092\u76f4\u63a5\u6307\u5b9a\u3059\u308b\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setCellValue('A13', '\u9078\u629e\u80a21');<\/strong>\r\n<strong>$validation = new DataValidation();<\/strong>\r\n<strong>$validation-&gt;setFormula1('\"\u9078\u629e\u80a21,\u9078\u629e\u80a22,\u9078\u629e\u80a23\"');<\/strong>\r\n<strong>$validation-&gt;setType('list');<\/strong>\r\n<strong>$validation-&gt;setAllowBlank(true);<\/strong>\r\n<strong>$validation-&gt;setShowDropDown(true);<\/strong>\r\n<strong>$sheet-&gt;setDataValidation('A13', $validation);<\/strong><\/pre>\n<p>\u203b <code>setFomula1()<\/code>\u5185\u306e\u30c0\u30d6\u30eb\u30af\u30a9\u30fc\u30c8\u304c\u306a\u3044\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u306e\u3067\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u6c17\u3092\u3064\u3051\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u9078\u629e\u80a2\u3092\u53c2\u7167\u3059\u308b\u5834\u5408<\/h3>\n<p>\u4ed6\u306e\u30bb\u30eb\u3092\u53c2\u7167\u3057\u3066\u9078\u629e\u80a2\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<pre>$sheet-&gt;setCellValue('A15', '\u9078\u629e\u80a2A');    \/\/\u3000\u3053\u3053\u304c\u9078\u629e\u30dc\u30c3\u30af\u30b9\r\n$sheet-&gt;setCellValue('B16', '\u9078\u629e\u80a2A');    \/\/ \u53c2\u7167\u3059\u308b\u9078\u629e\u80a2\r\n$sheet-&gt;setCellValue('B17', '\u9078\u629e\u80a2B');    \/\/ \u53c2\u7167\u3059\u308b\u9078\u629e\u80a2\r\n$sheet-&gt;setCellValue('B18', '\u9078\u629e\u80a2C');    \/\/ \u53c2\u7167\u3059\u308b\u9078\u629e\u80a2\r\n\r\n<strong>$validation = new DataValidation();<\/strong>\r\n<strong>$validation-&gt;setFormula1('$B$15:$B$18');<\/strong>\r\n<strong>$validation-&gt;setType('list');<\/strong>\r\n<strong>$validation-&gt;setAllowBlank(true);<\/strong>\r\n<strong>$validation-&gt;setShowDropDown(true);<\/strong>\r\n<strong>$sheet-&gt;setDataValidation('A15', $validation);<\/strong><\/pre>\n<h2>\u30aa\u30fc\u30c8\u30d5\u30a3\u30eb\u30bf<\/h2>\n<p>\u30aa\u30fc\u30c8\u30d5\u30a3\u30eb\u30bf\u3092\u8a2d\u5b9a\u3057\u305f\u3044\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setCellValue('A20', '\u30aa\u30fc\u30c8\u30d5\u30a3\u30eb\u30bf');<\/strong>\r\n<strong>$sheet-&gt;setCellValue('A21', '\u9078\u629e\u80a2\uff08\uff11\uff09');<\/strong>\r\n<strong>$sheet-&gt;setCellValue('A22', '\u9078\u629e\u80a2\uff08\uff12\uff09');<\/strong>\r\n<strong>$sheet-&gt;setCellValue('A23', '\u9078\u629e\u80a2\uff08\uff13\uff09');<\/strong>\r\n<strong>$sheet-&gt;setAutoFilter('A20:A20');<\/strong><\/pre>\n<h2>\u67a0\u7dda\u306e\u8868\u793a\u3001\u975e\u8868\u793a<\/h2>\n<p>Excel\u3067\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3046\u3063\u3059\u3089\u3068\u67a0\u7dda\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u3092\u975e\u8868\u793a\u306b\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setShowGridlines(false);<\/strong><\/pre>\n<h2>\u6587\u5b57\u306e\u8272\u3092\u6307\u5b9a\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u6587\u5b57\u306e\u8272\u3092\u8d64\u306b\u3057\u305f\u3044\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setCellValue('A25', '\u6587\u5b57\u306e\u8272\u30fb\u8d64');<\/strong>\r\n<strong>$sheet-&gt;getStyle('A25')<\/strong>\r\n<strong>    -&gt;getFont()<\/strong>\r\n<strong>    -&gt;getColor()<\/strong>\r\n<strong>    -&gt;setARGB('FFFF0000');<\/strong><\/pre>\n<p>\u203b \u6307\u5b9a\u3059\u308b\u8272\u306f<code>ARGB<\/code>\u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u80cc\u666f\u8272\u3092\u6307\u5b9a\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u30bb\u30eb\u306e\u80cc\u666f\u3092\u8d64\u306b\u3057\u305f\u3044\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>$sheet-&gt;setCellValue('A27', '\u80cc\u666f\u8272\u30fb\u8d64');<\/strong>\r\n<strong>$sheet-&gt;getStyle('A27')<\/strong>\r\n<strong>    -&gt;getFill()<\/strong>\r\n<strong>    -&gt;setFillType('solid')<\/strong>\r\n<strong>    -&gt;getStartColor()<\/strong>\r\n<strong>    -&gt;setARGB('FFFF0000');<\/strong><\/pre>\n<h2>\u67a0\u7dda\u3092\u6307\u5b9a\u3059\u308b<\/h2>\n<p>\u30bb\u30eb\u306b\u67a0\u7dda\u3092\u3064\u3051\u305f\u3044\u5834\u5408\u3067\u3059\u3002<br \/>\n\u592a\u7dda\u3068\u7d30\u7dda\u304c\u6307\u5b9a\u3067\u304d\u307e\u3059<\/p>\n<pre>$sheet-&gt;setCellValue('A29', '\u67a0\u7dda');\r\n\r\n<strong>$borders = $sheet-&gt;getStyle('A29')-&gt;getBorders();<\/strong>\r\n<strong>$borders<\/strong>\r\n<strong>    -&gt;getTop()<\/strong>\r\n<strong>    -&gt;setBorderStyle('thick');  \/\/ \u592a\u7dda<\/strong>\r\n<strong>$borders<\/strong>\r\n<strong>    -&gt;getRight()<\/strong>\r\n<strong>    -&gt;setBorderStyle('thin');   \/\/ \u7d30\u7dda<\/strong>\r\n<strong>$borders<\/strong>\r\n<strong>    -&gt;getBottom()<\/strong>\r\n<strong>    -&gt;setBorderStyle('thick');  \/\/ \u592a\u7dda<\/strong>\r\n<strong>$borders<\/strong>\r\n<strong>    -&gt;getLeft()<\/strong>\r\n<strong>    -&gt;setBorderStyle('thin');   \/\/ \u7d30\u7dda<\/strong><\/pre>\n<h2>\u53f3\u5bc4\u305b\u3001\u5de6\u5bc4\u305b\u3001\u4e2d\u592e\u5bc4\u305b<\/h2>\n<pre><strong>$sheet-&gt;setCellValue('A31', '\u53f3\u5bc4\u305b');\r\n$sheet-&gt;getStyle('A31')\r\n    -&gt;getAlignment()\r\n    -&gt;setHorizontal('right');\r\n$sheet-&gt;setCellValue('B31', '\u5de6\u5bc4\u305b');\r\n$sheet-&gt;getStyle('B31')\r\n    -&gt;getAlignment()\r\n    -&gt;setHorizontal('left');\r\n$sheet-&gt;setCellValue('C31', '\u4e2d\u592e\u5bc4\u305b');\r\n$sheet-&gt;getStyle('C31')\r\n    -&gt;getAlignment()\r\n    -&gt;setHorizontal('center');<\/strong><\/pre>\n<h2>\u6587\u5b57\u3092\u592a\u5b57\u306b\u3059\u308b<\/h2>\n<pre>$sheet-&gt;setCellValue('A33', '\u592a\u5b57');\r\n\r\n<strong>$sheet-&gt;getStyle('A33')<\/strong>\r\n<strong>    -&gt;getFont()<\/strong>\r\n<strong>    -&gt;setBold(true);<\/strong><\/pre>\n<h2>\u6587\u5b57\u3092\u659c\u4f53\u306b\u3059\u308b<\/h2>\n<pre>$sheet-&gt;setCellValue('A35', '\u306a\u306a\u3081\u6587\u5b57');\r\n\r\n<strong>$sheet-&gt;getStyle('A35')<\/strong>\r\n<strong>    -&gt;getFont()<\/strong>\r\n<strong>    -&gt;setItalic(true);\r\n<\/strong><\/pre>\n<h2>\u6587\u5b57\u306e\u30b5\u30a4\u30ba\u3092\u6307\u5b9a\u3059\u308b<\/h2>\n<pre>$sheet-&gt;setCellValue('A37', '\u6587\u5b57\u30b5\u30a4\u30ba\u3092\u6307\u5b9a');\r\n\r\n<strong>$sheet-&gt;getStyle('A37')<\/strong>\r\n<strong>    -&gt;getFont()<\/strong>\r\n<strong>    -&gt;setSize(8);<\/strong><\/pre>\n<h2>\u6587\u5b57\u306b\u4e0b\u7dda\u3092\u3064\u3051\u308b<\/h2>\n<pre>$sheet-&gt;setCellValue('A39', '\u4e0b\u7dda\u3042\u308a');\r\n\r\n<strong>$sheet-&gt;getStyle('A39')<\/strong>\r\n<strong>    -&gt;getFont()<\/strong>\r\n<strong>    -&gt;setUnderline(true);<\/strong><\/pre>\n<h1>PhpSpreadsheet\u3067Excel\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080<\/h1>\n<h2>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h2>\n<p>\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u3001Excel\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067\u5168\u3066\u306e\u30c7\u30fc\u30bf\u3092\u914d\u5217\u306b\u683c\u7d0d\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>$reader = \\PhpOffice\\PhpSpreadsheet\\IOFactory::createReader('Xlsx');<\/strong>\r\n<strong>$spreadsheet = $reader-&gt;load('\/PATH\/TO\/YOUR\/PROJECT\/test2.xlsx');<\/strong>\r\n<strong>$sheet = $spreadsheet-&gt;getActiveSheet();<\/strong>\r\n\r\n<strong>$data = [];<\/strong>\r\n\r\n<strong>foreach ($sheet-&gt;getRowIterator() as $i =&gt; $row) {<\/strong>\r\n\r\n<strong>    $row_data = [];<\/strong>\r\n<strong>    $cellIterator = $row-&gt;getCellIterator();<\/strong>\r\n<strong>    $cellIterator-&gt;setIterateOnlyExistingCells(FALSE);<\/strong>\r\n\r\n<strong>    foreach ($cellIterator as $j =&gt; $cell) {<\/strong>\r\n\r\n<strong>        $cell_id = $i .'-'. $j;<\/strong>\r\n<strong>        $row_data[$cell_id] = $cell-&gt;getValue();<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n<strong>    $data[$i] = $row_data;<\/strong>\r\n\r\n<strong>}<\/strong>\r\n\r\n<strong>print_r($data);<\/strong><\/pre>\n<h2>\u5024\u306e\u53d6\u5f97<\/h2>\n<p>\u73fe\u5728\u306e\u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u304b\u3089\u30bb\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u306e\u4f8b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u901a\u5e38\u306e\u53d6\u5f97<\/h3>\n<pre><strong>echo $sheet-&gt;getCell('A1')-&gt;getValue();<\/strong><\/pre>\n<h3>\u5f0f\u3092\u8a08\u7b97\u3057\u305f\u5f8c\u306e\u30c7\u30fc\u30bf\u53d6\u5f97<\/h3>\n<p>\u4f8b\u3048\u3070\u3001\u30bb\u30eb\u306e\u4e2d\u8eab\u304c\u3001<code>=CONCATENATE(A1, \" - \", B1)<\/code> \u3060\u3063\u305f\u5834\u5408\u3001\u7d50\u5408\u3057\u305f\u5f8c\u306e\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>echo $sheet-&gt;getCell('A7')-&gt;getCalculatedValue();<\/strong><\/pre>\n<h3>\u8868\u793a\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u53d6\u5f97<\/h3>\n<p>\u4f8b\u3048\u3070\u3001\u65e5\u4ed8\u306a\u3069\u306e\u8868\u793a\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u6307\u5b9a\u3057\u3066\u3044\u305f\u5834\u5408\u3001\u305d\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u5f93\u3063\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><strong>echo $sheet-&gt;getCell('G1')-&gt;getFormattedValue();<\/strong><\/pre>\n<h3>\u914d\u5217\u3067\u4e00\u6c17\u306b\u30c7\u30fc\u30bf\u53d6\u5f97<\/h3>\n<p>\u7bc4\u56f2\u3092\u6307\u5b9a\u3057\u3066\u914d\u5217\u3068\u3057\u3066\u30c7\u30fc\u30bf\u53d6\u5f97\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>$data = $sheet-&gt;rangeToArray('A3:C5');<\/strong>\r\n<strong>print_r($data);<\/strong><\/pre>\n<h1>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u4f5c\u6210\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u203b \u305f\u3060\u3057\u3001\u4fdd\u5b58\u3059\u308b\u30d1\u30b9\u3001\u8aad\u307f\u8fbc\u3080Excel\u30d5\u30a1\u30a4\u30eb\u306f\u3054\u81ea\u8eab\u3067\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\uff08\u305d\u306e\u307e\u307e\u3060\u3068\u304a\u305d\u3089\u304f\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3059\uff09<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=3946&amp;tmstv=1777538059\" rel=\"nofollow\" id=\"download-link-3946\" data-redirect=\"false\" >\n\tPhpSpreadsheet\u3067Excel\u3092\u64cd\u4f5c\u3059\u308b<\/a>\n\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u4eca\u56de\u306f\u3058\u3081\u3066<code>PhpSpreadsheet<\/code>\u3092\u4f7f\u3063\u305f\u308f\u3051\u3067\u3059\u3051\u3069\u3001\u79c1\u306e\u8a18\u61b6\u304c\u6b63\u3057\u3051\u308c\u3070\u524d\u30d0\u30fc\u30b8\u30e7\u30f3\u306e<code>PhpExcel<\/code>\u3088\u308a\u30b3\u30fc\u30c9\u304c\u3068\u3066\u3082\u66f8\u304d\u3084\u3059\u304f\u306a\u3063\u3066\u3044\u308b\u30a4\u30e1\u30fc\u30b8\u3067\u3059\u3002\u76f4\u611f\u7684\u306b\u30b3\u30fc\u30c9\u306e\u7406\u89e3\u3082\u3057\u3084\u3059\u3044\u3093\u3058\u3083\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u307e\u305f\u3001\u305f\u3081\u3057\u306b<code>Microsoft Excel<\/code>\u4ee5\u5916\u306b\u3082\u30d5\u30ea\u30fc\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u306e<code>Libre Office<\/code>\u306e<code>Calc<\/code>\u3001\u305d\u308c\u304b\u3089<code>Google Spreadsheet<\/code>\u3067\u3082\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3053\u308c\u3082\u554f\u984c\u3082\u306a\u304f\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u3063\u3061\u306e\u65b9\u306e\u6280\u8853\u3082\u9032\u5316\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u306d\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u7686\u3055\u3093\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306b\u3082<code>Excel<\/code>\u4f5c\u6210\u6a5f\u80fd\u3092\u3064\u3051\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-25 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2017\/06\/15.png\" alt=\"\" width=\"348\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2017\/06\/15.png 348w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2017\/06\/15-300x276.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2017\/06\/15-30x28.png 30w\" sizes=\"auto, (max-width: 348px) 100vw, 348px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u30a6\u30a7\u30d6\u958b\u767a\u306e\u5206\u91ce\u306f\u7279\u306b\u5909\u5316\u306e\u30b9\u30d4\u30fc\u30c9\u304c\u901f\u3044\u696d\u754c\u3067\u3059\u306e\u3067\u3001\u5c11\u3057\u524d\u307e\u3067\u4f7f\u3063\u3066\u3044\u305f\u6280\u8853\u304c\u305f\u3063\u305f\uff12\u3001\uff13\u5e74\u3067\u53e4\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u3053\u3068\u3082\u7d50\u69cb\u30b6\u30e9\u306b\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002 \u305d &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=3945\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;PhpSpreadsheet\u3067Excel\u3092\u64cd\u4f5c\u3059\u308b\u516828\u5b9f\u4f8b\uff01&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":3953,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[54],"class_list":["post-3945","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-excel"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3945"}],"version-history":[{"count":8,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3945\/revisions"}],"predecessor-version":[{"id":6935,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3945\/revisions\/6935"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/3953"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}