{"id":1676,"date":"2023-05-03T08:19:53","date_gmt":"2023-05-03T00:19:53","guid":{"rendered":"http:\/\/viplao.com\/?p=1676"},"modified":"2023-07-11T06:37:15","modified_gmt":"2023-07-10T22:37:15","slug":"%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7-python-%e6%97%a5%e5%b8%b8%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90-excel%e5%b8%b8%e7%94%a8%e8%81%9a%e5%90%88%e5%87%bd%e6%95%b0%e5%a4%84","status":"publish","type":"post","link":"http:\/\/viplao.com\/index.php\/2023\/05\/03\/%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7-python-%e6%97%a5%e5%b8%b8%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90-excel%e5%b8%b8%e7%94%a8%e8%81%9a%e5%90%88%e5%87%bd%e6%95%b0%e5%a4%84\/","title":{"rendered":"\u6570\u5b57\u5316\u8fd0\u7ef4 \u2013 PYTHON \u65e5\u5e38\u6570\u636e\u5206\u6790 \u2013\u00a0EXCEL\u5e38\u7528\u805a\u5408\u51fd\u6570\u5904\u7406\u6280\u5de7"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_71 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u6587\u7ae0\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/viplao.com\/index.php\/2023\/05\/03\/%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7-python-%e6%97%a5%e5%b8%b8%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90-excel%e5%b8%b8%e7%94%a8%e8%81%9a%e5%90%88%e5%87%bd%e6%95%b0%e5%a4%84\/#%E6%A1%88%E4%BE%8B01_%E5%AF%B9%E4%B8%80%E4%B8%AA%E5%B7%A5%E4%BD%9C%E7%B0%BF%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%B7%A5%E4%BD%9C%E8%A1%A8%E5%88%86%E5%88%AB%E6%B1%82%E5%92%8C\" title=\"\u6848\u4f8b01 \u5bf9\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868\u5206\u522b\u6c42\u548c\">\u6848\u4f8b01 \u5bf9\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868\u5206\u522b\u6c42\u548c<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/viplao.com\/index.php\/2023\/05\/03\/%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7-python-%e6%97%a5%e5%b8%b8%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90-excel%e5%b8%b8%e7%94%a8%e8%81%9a%e5%90%88%e5%87%bd%e6%95%b0%e5%a4%84\/#%E4%B8%BE%E4%B8%80%E5%8F%8D%E4%B8%89_%E5%AF%B9%E4%B8%80%E4%B8%AA%E5%B7%A5%E4%BD%9C%E7%B0%BF%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%B7%A5%E4%BD%9C%E8%A1%A8%E5%88%86%E5%88%AB%E6%B1%82%E5%92%8C%E5%B9%B6%E5%B0%86%E6%B1%82%E5%92%8C%E7%BB%93%E6%9E%9C%E5%86%99%E5%85%A5%E5%9B%BA%E5%AE%9A%E5%8D%95%E5%85%83%E6%A0%BC\" title=\"\u4e3e\u4e00\u53cd\u4e09 \u5bf9\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868\u5206\u522b\u6c42\u548c\u5e76\u5c06\u6c42\u548c\u7ed3\u679c\u5199\u5165\u56fa\u5b9a\u5355\u5143\u683c\">\u4e3e\u4e00\u53cd\u4e09 \u5bf9\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868\u5206\u522b\u6c42\u548c\u5e76\u5c06\u6c42\u548c\u7ed3\u679c\u5199\u5165\u56fa\u5b9a\u5355\u5143\u683c<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/viplao.com\/index.php\/2023\/05\/03\/%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7-python-%e6%97%a5%e5%b8%b8%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90-excel%e5%b8%b8%e7%94%a8%e8%81%9a%e5%90%88%e5%87%bd%e6%95%b0%e5%a4%84\/#%E6%A1%88%E4%BE%8B02_%E6%89%B9%E9%87%8F%E7%BB%9F%E8%AE%A1%E5%B7%A5%E4%BD%9C%E7%B0%BF%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC%E5%92%8C%E6%9C%80%E5%B0%8F%E5%80%BC\" title=\"\u6848\u4f8b02 \u6279\u91cf\u7edf\u8ba1\u5de5\u4f5c\u7c3f\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\">\u6848\u4f8b02 \u6279\u91cf\u7edf\u8ba1\u5de5\u4f5c\u7c3f\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c<\/a><\/li><\/ul><\/nav><\/div>\n<h1 class=\"wp-block-heading\" id=\"%E6%A1%88%E4%BE%8B04-%E5%AF%B9%E4%B8%80%E4%B8%AA%E5%B7%A5%E4%BD%9C%E7%B0%BF%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%B7%A5%E4%BD%9C%E8%A1%A8%E5%88%86%E5%88%AB%E6%B1%82%E5%92%8C\"><span class=\"ez-toc-section\" id=\"%E6%A1%88%E4%BE%8B01_%E5%AF%B9%E4%B8%80%E4%B8%AA%E5%B7%A5%E4%BD%9C%E7%B0%BF%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%B7%A5%E4%BD%9C%E8%A1%A8%E5%88%86%E5%88%AB%E6%B1%82%E5%92%8C\"><\/span><strong>\u6848\u4f8b01 \u5bf9\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868\u5206\u522b\u6c42\u548c<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul>\n<li>\u4ee3\u7801\u6587\u4ef6\uff1a\u5bf9\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868\u5206\u522b\u6c42\u548c.py &#8211; \u6570\u636e\u6587\u4ef6\uff1a\u91c7\u8d2d\u8868.xlsx<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport xlwings as xw\nimport pandas as pd\napp=xw.App(visible=True,add_book=False)\nworkbook=app.books.open(r'D:\\22\\\u91c7\u8d2d\u8868.xlsx')\nfor i in workbook.sheets:\n    values=i.range('A1').expand()\n    data=values.options(pd.DataFrame).value\n    sums=data&#91;'\u91c7\u8d2d\u91d1\u989d'].sum()\n    \n    column=values.value&#91;0].index('\u91c7\u8d2d\u91d1\u989d')+1\n    row=values.shape&#91;0]\n    i.range(row+1,column).value=sums\nworkbook.save()\nworkbook.close()\napp.quit()\n<\/code><\/pre>\n\n\n\n<p>\u7b2c10\u884c\u4ee3\u7801\u4e2d\u7684index()\u662fPython\u4e2d\u5217\u8868\u5bf9\u8c61\u7684\u51fd\u6570\uff0c\u5e38\u7528\u4e8e\u5728\u5217\u8868\u4e2d\u67e5\u627e\u67d0\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u4f4d\u7f6e\u3002\u8be5\u51fd\u6570\u7684\u8bed\u6cd5\u683c\u5f0f\u548c\u5e38\u7528\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002- \u7b2c11\u884c\u4ee3\u7801\u4e2d\u7684shape\u662fpandas\u6a21\u5757\u4e2dDataFrame\u5bf9\u8c61\u7684\u4e00\u4e2a\u5c5e\u6027\uff0c\u5b83\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5143\u7ec4\uff0c\u5176\u4e2d\u6709\u4e24\u4e2a\u5143\u7d20\uff0c\u5206\u522b\u4ee3\u8868DataFrame\u7684\u884c\u6570\u548c\u5217\u6570\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E4%B8%BE%E4%B8%80%E5%8F%8D%E4%B8%89-%E5%AF%B9%E4%B8%80%E4%B8%AA%E5%B7%A5%E4%BD%9C%E7%B0%BF%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%B7%A5%E4%BD%9C%E8%A1%A8%E5%88%86%E5%88%AB%E6%B1%82%E5%92%8C%E5%B9%B6%E5%B0%86%E6%B1%82%E5%92%8C%E7%BB%93%E6%9E%9C%E5%86%99%E5%85%A5%E5%9B%BA%E5%AE%9A%E5%8D%95%E5%85%83%E6%A0%BC\"><span class=\"ez-toc-section\" id=\"%E4%B8%BE%E4%B8%80%E5%8F%8D%E4%B8%89_%E5%AF%B9%E4%B8%80%E4%B8%AA%E5%B7%A5%E4%BD%9C%E7%B0%BF%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%B7%A5%E4%BD%9C%E8%A1%A8%E5%88%86%E5%88%AB%E6%B1%82%E5%92%8C%E5%B9%B6%E5%B0%86%E6%B1%82%E5%92%8C%E7%BB%93%E6%9E%9C%E5%86%99%E5%85%A5%E5%9B%BA%E5%AE%9A%E5%8D%95%E5%85%83%E6%A0%BC\"><\/span><strong>\u4e3e\u4e00\u53cd\u4e09 \u5bf9\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868\u5206\u522b\u6c42\u548c\u5e76\u5c06\u6c42\u548c\u7ed3\u679c\u5199\u5165\u56fa\u5b9a\u5355\u5143\u683c<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul>\n<li>\u4ee3\u7801\u6587\u4ef6\uff1a\u5bf9\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868\u5206\u522b\u6c42\u548c\u5e76\u5c06\u6c42\u548c\u7ed3\u679c\u5199\u5165\u56fa\u5b9a\u5355\u5143\u683c.py &#8211; \u6570\u636e\u6587\u4ef6\uff1a\u91c7\u8d2d\u8868.xlsx<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport xlwings as xw\nimport pandas as pd\napp=xw.App(visible=True,add_book=False)\nworkbook=app.books.open(r'D:\\22\\\u91c7\u8d2d\u8868.xlsx')\nfor i in workbook.sheets:\n    values=i.range('A1').expand().options(pd.DataFrame).value\n    sums=values&#91;'\u91c7\u8d2d\u91d1\u989d'].sum()\n    i.range('F1').value=sums   #\u5c06\u6c42\u548c\u540e\u7684\u5185\u5bb9\u5199\u5230F1\u5355\u5143\u683c\u4e2d\nworkbook.save()\nworkbook.close()\napp.quit()\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"732\" height=\"278\" src=\"http:\/\/viplao.com\/wp-content\/uploads\/2023\/05\/image-2.png\" alt=\"\" class=\"wp-image-1677\" srcset=\"http:\/\/viplao.com\/wp-content\/uploads\/2023\/05\/image-2.png 732w, http:\/\/viplao.com\/wp-content\/uploads\/2023\/05\/image-2-300x114.png 300w\" sizes=\"(max-width: 732px) 100vw, 732px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E6%A1%88%E4%BE%8B05-%E6%89%B9%E9%87%8F%E7%BB%9F%E8%AE%A1%E5%B7%A5%E4%BD%9C%E7%B0%BF%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC%E5%92%8C%E6%9C%80%E5%B0%8F%E5%80%BC\"><span class=\"ez-toc-section\" id=\"%E6%A1%88%E4%BE%8B02_%E6%89%B9%E9%87%8F%E7%BB%9F%E8%AE%A1%E5%B7%A5%E4%BD%9C%E7%B0%BF%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC%E5%92%8C%E6%9C%80%E5%B0%8F%E5%80%BC\"><\/span><strong>\u6848\u4f8b02 \u6279\u91cf\u7edf\u8ba1\u5de5\u4f5c\u7c3f\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul>\n<li>\u4ee3\u7801\u6587\u4ef6\uff1a\u6279\u91cf\u7edf\u8ba1\u5de5\u4f5c\u7c3f\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c.py &#8211; \u6570\u636e\u6587\u4ef6\uff1a\u4ea7\u54c1\u9500\u552e\u7edf\u8ba1\u8868\uff08\u6587\u4ef6\u5939\uff09<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport xlwings as xw\nimport pandas as pd\napp=xw.App(visible=True,add_book=False)\nfile_path=r'D:\\\\22\\\u4ea7\u54c1\u9500\u552e\u7edf\u8ba1\u8868'\nfile_list=os.listdir(file_path)\nfor j in file_list:\n    if os.path.splitext(j)&#91;1]=='.xlsx':\n        file_paths=os.path.join(file_path,j)\n        workbook=app.books.open(file_paths)\n        for i in workbook.sheets:\n            values=i.range('A1').expand().options(pd.DataFrame).value\n            max0=values&#91;'\u9500\u552e\u5229\u6da6'].max()\n            min0=values&#91;'\u9500\u552e\u5229\u6da6'].min()\n            i.range('I1').value='\u6700\u5927\u9500\u552e\u5229\u6da6'\n            i.range('J1').value=max0\n            i.range('I2').value='\u6700\u5c0f\u9500\u552e\u5229\u6da6'\n            i.range('J2').value=min0\n            i.autofit()\n        workbook.save()\n        workbook.close()\napp.quit()    \n<\/code><\/pre>\n\n\n\n<p><strong>\u4e3e\u4e00\u53cd\u4e09 \u6279\u91cf\u7edf\u8ba1\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u6240\u6709\u5de5\u4f5c\u8868\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c<\/strong><\/p>\n\n\n\n<ul>\n<li>\u4ee3\u7801\u6587\u4ef6\uff1a\u6279\u91cf\u7edf\u8ba1\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u6240\u6709\u5de5\u4f5c\u8868\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c.py- \u6570\u636e\u6587\u4ef6\uff1a\u4ea7\u54c1\u9500\u552e\u7edf\u8ba1\u8868.xlsx<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nimport pandas as pd\napp=xw.App(visible=True,add_book=False)\nworkbook=app.books.open(r'CD:\\22\\\u4ea7\u54c1\u9500\u552e\u7edf\u8ba1\u8868.xlsx')\nfor i in workbook.sheets:\n    values=i.range('A1').expand().options(pd.DataFrame).value\n    max0=values&#91;'\u9500\u552e\u5229\u6da6'].max()\n    min0=values&#91;'\u9500\u552e\u5229\u6da6'].min()\n    i.range('I3').value='\u6700\u5927\u9500\u552e\u5229\u6da6'\n    i.range('J3').value=max0\n    i.range('I4').value='\u6700\u5c0f\u9500\u552e\u5229\u6da6'\n    i.range('J4').value=min0\n    i.autofit()\nworkbook.save()\nworkbook.close()\napp.quit()   \n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6848\u4f8b01 \u5bf9\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868\u5206\u522b\u6c42\u548c \u7b2c10\u884c\u4ee3\u7801\u4e2d\u7684index()\u662fPython\u4e2d\u5217\u8868\u5bf9\u8c61&hellip; <a href=\"http:\/\/viplao.com\/index.php\/2023\/05\/03\/%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7-python-%e6%97%a5%e5%b8%b8%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90-excel%e5%b8%b8%e7%94%a8%e8%81%9a%e5%90%88%e5%87%bd%e6%95%b0%e5%a4%84\/\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u6570\u5b57\u5316\u8fd0\u7ef4 \u2013 PYTHON \u65e5\u5e38\u6570\u636e\u5206\u6790 \u2013\u00a0EXCEL\u5e38\u7528\u805a\u5408\u51fd\u6570\u5904\u7406\u6280\u5de7<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[14,26,28],"views":624,"_links":{"self":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1676"}],"collection":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/comments?post=1676"}],"version-history":[{"count":2,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1676\/revisions"}],"predecessor-version":[{"id":2193,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1676\/revisions\/2193"}],"wp:attachment":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/media?parent=1676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/categories?post=1676"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/tags?post=1676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}