
{"id":646,"date":"2015-11-27T12:01:02","date_gmt":"2015-11-27T04:01:02","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=646"},"modified":"2015-11-27T12:01:02","modified_gmt":"2015-11-27T04:01:02","slug":"php-phpexcel-%e7%94%a2%e7%94%9f%e6%9c%88%e6%9b%86%e8%b3%87%e6%96%99","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=646","title":{"rendered":"[ PHP ] &#8211; PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599"},"content":{"rendered":"<div style='text-align:center' class='yasr-auto-insert-overall'><\/div><div style='text-align:center' class='yasr-auto-insert-visitor'><\/div><div style=\"margin-top: 0px; margin-bottom: 0px;\" class=\"sharethis-inline-share-buttons\" ><\/div>\n<p>PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599<\/p>\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\ninclude('Classes\/PHPExcel.php');\nrequire_once('Classes\/PHPExcel\/IOFactory.php');\nfunction getthemonth($date){\n    $firstday = date('Y-m-01', strtotime($date));\/\/\u53d6\u5f97\u8a72\u65e5\u671f\u6708\u4efd\u7684\u7b2c\u4e00\u5929\n    $lastday = date('Y-m-d', strtotime(\"$firstday +1 month -1 day\"));\/\/\u53d6\u5f97\u8a72\u65e5\u671f\u6708\u4efd\u7684\u6700\u5f8c\u4e00\u5929\n    return array($firstday,$lastday);\n}\n$YM = (isset($_GET&#091;'date'])?$_GET&#091;'date']:date(\"Y-m\"));\n$day=getthemonth($YM);\n$dayCount = date(\"t\",strtotime($day&#091;0])); \/\/\u8a72\u6708\u4efd\u7684\u7e3d\u5929\u6578\n$weekday = date('w', strtotime($day&#091;0]));\n$d_last=date(\"j\",strtotime($day&#091;1]));\n$d_last=$dayCount+$weekday-1;\/\/\u82e5\u7b2c\u4e00\u5929\u4e0d\u662f\u79ae\u62dc\u65e5\n$w=array(1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G');\n$objPHPExcel = new PHPExcel();\n$objPHPExcel->setActiveSheetIndex(0);\n$objPHPExcel->getActiveSheet()->setTitle('\u6392\u73ed\u8868');\n$objPHPExcel->getActiveSheet()->setCellValue('A1','\u661f\u671f \u65e5');\n$objPHPExcel->getActiveSheet()->setCellValue('B1','\u661f\u671f \u4e00');\n$objPHPExcel->getActiveSheet()->setCellValue('C1','\u661f\u671f \u4e8c');\n$objPHPExcel->getActiveSheet()->setCellValue('D1','\u661f\u671f \u4e09');\n$objPHPExcel->getActiveSheet()->setCellValue('E1','\u661f\u671f \u56db');\n$objPHPExcel->getActiveSheet()->setCellValue('F1','\u661f\u671f \u4e94');\n$objPHPExcel->getActiveSheet()->setCellValue('G1','\u661f\u671f \u516d');\n$i=1;\/\/\u65e5\u671f\nfor($r=0;$r&lt;=5;$r++){\/\/\u8dd1\u516d\u6b21\n    for($r1=1;$r1&lt;=7;$r1++){\/\/\u8dd1\u4e03\u6b21\n        $x=($r1+($r>0?$r*7:0));\n        $objPHPExcel->getActiveSheet()->setCellValue($w&#091;$r1].($r+2),$x.($x>$weekday &amp;&amp; $x&lt;=$d_last+1?'\u3010'.$i.'\u3011':'')); \/\/\u7522\u751f42\u683c\n        $i=($x>$weekday?$i+1:1);\n    }\n}\n$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');\n$objWriter->save('export\/export_'.$YM.'.xlsx');\nheader('Location:export\/export_'.$YM.'.xlsx');\nexit;\n?>\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><\/code><\/pre>\n<div style='text-align:center' class='yasr-auto-insert-overall'><\/div><div style='text-align:center' class='yasr-auto-insert-visitor'><\/div>","protected":false},"excerpt":{"rendered":"<p>PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599<\/p>\n","protected":false},"author":1,"featured_media":2201,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"yasr_overall_rating":0,"yasr_post_is_review":"","yasr_auto_insert_disabled":"","yasr_review_type":"","footnotes":""},"categories":[37],"tags":[244,448,452,946],"class_list":["post-646","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-phpexcel","tag-excel","tag-php","tag-phpexcel","tag-946"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[ PHP ] - PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599 - \u6df7\u6c34\u6478\u9b5a<\/title>\n<meta name=\"description\" content=\"PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webteach.tw\/?p=646\" \/>\n<meta property=\"og:locale\" content=\"zh_TW\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[ PHP ] - PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599 - \u6df7\u6c34\u6478\u9b5a\" \/>\n<meta property=\"og:description\" content=\"PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webteach.tw\/?p=646\" \/>\n<meta property=\"og:site_name\" content=\"\u6df7\u6c34\u6478\u9b5a\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-27T04:01:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webteach.tw\/wp-content\/uploads\/2017\/12\/1-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"680\" \/>\n\t<meta property=\"og:image:height\" content=\"454\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"jeff\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005:\" \/>\n\t<meta name=\"twitter:data1\" content=\"jeff\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9810\u4f30\u95b1\u8b80\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\u9418\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646\"},\"author\":{\"name\":\"jeff\",\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/#\\\/schema\\\/person\\\/d434d754fd581338113eecfa923d7520\"},\"headline\":\"[ PHP ] &#8211; PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599\",\"datePublished\":\"2015-11-27T04:01:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646\"},\"wordCount\":4,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.webteach.tw\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/1-1.png\",\"keywords\":[\"excel\",\"php\",\"phpexcel\",\"\u6708\u66c6\"],\"articleSection\":[\"phpexcel\"],\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.webteach.tw\\\/?p=646#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646\",\"url\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646\",\"name\":\"[ PHP ] - PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599 - \u6df7\u6c34\u6478\u9b5a\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.webteach.tw\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/1-1.png\",\"datePublished\":\"2015-11-27T04:01:02+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/#\\\/schema\\\/person\\\/d434d754fd581338113eecfa923d7520\"},\"description\":\"PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646#breadcrumb\"},\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.webteach.tw\\\/?p=646\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646#primaryimage\",\"url\":\"https:\\\/\\\/www.webteach.tw\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/1-1.png\",\"contentUrl\":\"https:\\\/\\\/www.webteach.tw\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/1-1.png\",\"width\":680,\"height\":454,\"caption\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/?p=646#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9801\",\"item\":\"https:\\\/\\\/www.webteach.tw\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[ PHP ] &#8211; PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/#website\",\"url\":\"https:\\\/\\\/www.webteach.tw\\\/\",\"name\":\"\u6df7\u6c34\u6478\u9b5a\",\"description\":\"\u5b78\u7121\u6b62\u5883,\u6559\u5b78\u76f8\u9577\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.webteach.tw\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-TW\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.webteach.tw\\\/#\\\/schema\\\/person\\\/d434d754fd581338113eecfa923d7520\",\"name\":\"jeff\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5797200e421b670a2ce64d6e7382054c69b231d4aab55742c96bb1e51bc9fefc?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5797200e421b670a2ce64d6e7382054c69b231d4aab55742c96bb1e51bc9fefc?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5797200e421b670a2ce64d6e7382054c69b231d4aab55742c96bb1e51bc9fefc?s=96&d=mm&r=g\",\"caption\":\"jeff\"},\"sameAs\":[\"http:\\\/\\\/35.72.55.111\"],\"url\":\"https:\\\/\\\/www.webteach.tw\\\/?author=1\"},false]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[ PHP ] - PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599 - \u6df7\u6c34\u6478\u9b5a","description":"PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webteach.tw\/?p=646","og_locale":"zh_TW","og_type":"article","og_title":"[ PHP ] - PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599 - \u6df7\u6c34\u6478\u9b5a","og_description":"PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599","og_url":"https:\/\/www.webteach.tw\/?p=646","og_site_name":"\u6df7\u6c34\u6478\u9b5a","article_published_time":"2015-11-27T04:01:02+00:00","og_image":[{"width":680,"height":454,"url":"https:\/\/www.webteach.tw\/wp-content\/uploads\/2017\/12\/1-1.png","type":"image\/png"}],"author":"jeff","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005:":"jeff","\u9810\u4f30\u95b1\u8b80\u6642\u9593":"1 \u5206\u9418"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webteach.tw\/?p=646#article","isPartOf":{"@id":"https:\/\/www.webteach.tw\/?p=646"},"author":{"name":"jeff","@id":"https:\/\/www.webteach.tw\/#\/schema\/person\/d434d754fd581338113eecfa923d7520"},"headline":"[ PHP ] &#8211; PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599","datePublished":"2015-11-27T04:01:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webteach.tw\/?p=646"},"wordCount":4,"commentCount":0,"image":{"@id":"https:\/\/www.webteach.tw\/?p=646#primaryimage"},"thumbnailUrl":"https:\/\/www.webteach.tw\/wp-content\/uploads\/2017\/12\/1-1.png","keywords":["excel","php","phpexcel","\u6708\u66c6"],"articleSection":["phpexcel"],"inLanguage":"zh-TW","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webteach.tw\/?p=646#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webteach.tw\/?p=646","url":"https:\/\/www.webteach.tw\/?p=646","name":"[ PHP ] - PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599 - \u6df7\u6c34\u6478\u9b5a","isPartOf":{"@id":"https:\/\/www.webteach.tw\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webteach.tw\/?p=646#primaryimage"},"image":{"@id":"https:\/\/www.webteach.tw\/?p=646#primaryimage"},"thumbnailUrl":"https:\/\/www.webteach.tw\/wp-content\/uploads\/2017\/12\/1-1.png","datePublished":"2015-11-27T04:01:02+00:00","author":{"@id":"https:\/\/www.webteach.tw\/#\/schema\/person\/d434d754fd581338113eecfa923d7520"},"description":"PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599","breadcrumb":{"@id":"https:\/\/www.webteach.tw\/?p=646#breadcrumb"},"inLanguage":"zh-TW","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webteach.tw\/?p=646"]}]},{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/www.webteach.tw\/?p=646#primaryimage","url":"https:\/\/www.webteach.tw\/wp-content\/uploads\/2017\/12\/1-1.png","contentUrl":"https:\/\/www.webteach.tw\/wp-content\/uploads\/2017\/12\/1-1.png","width":680,"height":454,"caption":""},{"@type":"BreadcrumbList","@id":"https:\/\/www.webteach.tw\/?p=646#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9801","item":"https:\/\/www.webteach.tw\/"},{"@type":"ListItem","position":2,"name":"[ PHP ] &#8211; PHPEXCEL \u7522\u751f\u6708\u66c6\u8cc7\u6599"}]},{"@type":"WebSite","@id":"https:\/\/www.webteach.tw\/#website","url":"https:\/\/www.webteach.tw\/","name":"\u6df7\u6c34\u6478\u9b5a","description":"\u5b78\u7121\u6b62\u5883,\u6559\u5b78\u76f8\u9577","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webteach.tw\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-TW"},{"@type":"Person","@id":"https:\/\/www.webteach.tw\/#\/schema\/person\/d434d754fd581338113eecfa923d7520","name":"jeff","image":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/secure.gravatar.com\/avatar\/5797200e421b670a2ce64d6e7382054c69b231d4aab55742c96bb1e51bc9fefc?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5797200e421b670a2ce64d6e7382054c69b231d4aab55742c96bb1e51bc9fefc?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5797200e421b670a2ce64d6e7382054c69b231d4aab55742c96bb1e51bc9fefc?s=96&d=mm&r=g","caption":"jeff"},"sameAs":["http:\/\/35.72.55.111"],"url":"https:\/\/www.webteach.tw\/?author=1"},false]}},"views":697,"yasr_visitor_votes":{"stars_attributes":{"read_only":false,"span_bottom":false},"number_of_votes":0,"sum_votes":0},"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=646"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/646\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/2201"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}