{"id":1714,"date":"2020-06-22T17:40:01","date_gmt":"2020-06-22T09:40:01","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1714"},"modified":"2020-06-22T17:40:01","modified_gmt":"2020-06-22T09:40:01","slug":"%e4%bd%bf%e7%94%a8-python-%e7%9a%84-openpyxl-%e8%af%bb%e5%8f%96-excel","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1714","title":{"rendered":"\u4f7f\u7528 python \u7684 openpyxl \u8bfb\u53d6 Excel"},"content":{"rendered":"<div>\n<div>\n<div>\n<div>Python \u7684 openpyxl \u6a21\u5757\u53ef\u4ee5\u8ba9\u6211\u4eec\u80fd\u8bfb\u53d6\u548c\u4fee\u6539 Excel \u6587\u4ef6\u3002<\/div>\n<\/div>\n<\/div>\n<\/div>\n<article>\u9996\u5148\u8ba9\u6211\u4eec\u5148\u7406\u89e3\u4e00\u4e9b Excel \u57fa\u7840\u6982\u5ff5\u3002<\/p>\n<h2>1 Excel \u57fa\u7840\u6982\u5ff5<\/h2>\n<p>Excel \u6587\u4ef6\u4e5f\u79f0\u505a\u4e3a\u5de5\u4f5c\u7c3f\u3002\u6bcf\u4e2a\u5de5\u4f5c\u7c3f\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u5de5\u4f5c\u8868(Sheet)\u3002\u7528\u6237\u5f53\u524d\u67e5\u770b\u7684\u8868\u6216\u5173\u95ed Excel \u524d\u6700\u540e\u67e5\u770b\u7684\u8868\uff0c\u79f0\u4e3a\u6d3b\u52a8\u8868\u3002<br \/>\n\u6bcf\u4e00\u5f20\u8868\u90fd\u662f\u7531\u5217\u548c\u884c\u6784\u6210\u7684\u3002\u5217\u662f\u4ee5 A \u5f00\u59cb\u7684\u5b57\u6bcd\u8868\u793a\uff1b\u800c\u884c\u662f\u4ee5 1 \u5f00\u59cb\u7684\u6570\u5b57\u8868\u793a\u7684\u3002\u7531\u7279\u5b9a\u884c\u548c\u5217\u6240\u6307\u5b9a\u7684\u65b9\u683c\u79f0\u4e3a\u5355\u5143\u683c\u3002\u6bcf\u4e2a\u5355\u5143\u683c\u90fd\u53ef\u4ee5\u5305\u542b\u4e00\u4e2a\u6570\u5b57\u6216\u6587\u672c\u3002\u8fd9\u4e9b\u5355\u5143\u683c\u5c31\u6784\u6210\u4e86\u8fd9\u5f20\u8868\u3002<\/p>\n<h2>2 \u5b89\u88c5 openpyxl<\/h2>\n<p>\u901a\u8fc7 pip \u5c31\u53ef\u4ee5\u5b89\u88c5\u6700\u65b0\u7248\u7684 openpyxl\u3002<\/p>\n<div>\n<pre>pip install openpyxl\n<\/pre>\n<\/div>\n<h2>3 \u8bfb\u53d6 Excel<\/h2>\n<p>\u5047\u8bbe\u6709\u8fd9\u6837\u4e00\u4efd\u4e16\u754c\u4eba\u53e3\u7edf\u8ba1 Excel \u6587\u6863\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<div>\n<div>\n<div><\/div>\n<div data-width=\\\"495\\\" data-height=\\\"348\\\"><img src=\\\"https:\/\/upload-images.jianshu.io\/upload_images\/3386108-44144952c474ea54.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/495\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/3386108-44144952c474ea54.png\\\" data-original-width=\\\"495\\\" data-original-height=\\\"348\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"32556\\\" data-image-index=\\\"1\\\" \/><\/div>\n<\/div>\n<\/div>\n<h3>3.1 \u52a0\u8f7d Excel<\/h3>\n<div>\n<pre>wb = openpyxl.load_workbook(\\'population.xlsx\\')\nprint(\\'wb \u7c7b\u578b :\\')\nprint(type(wb), \\'\\\\n\\')\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<blockquote><p>wb \u7c7b\u578b :<br \/>\n&lt;class \\&#8217;openpyxl.workbook.workbook.Workbook\\&#8217;&gt;<\/p><\/blockquote>\n<p>\u5bfc\u5165 openpyxl \u6a21\u5757\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 openpyxl.load_workbook() \u51fd\u6570\u6765\u52a0\u8f7d Excel \u6587\u6863\u54af\u3002\u8fd9\u4e2a Excel \u6587\u4ef6\u8868\u793a\u4e3a Workbook \u5bf9\u8c61\u3002<br \/>\n\u6ce8\u610f\uff1a load_workbook() \u51fd\u6570\u4e2d\u7684\u6587\u4ef6\uff0c\u5fc5\u987b\u5728\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u3002\u53ef\u4ee5\u5bfc\u5165 os \u6a21\u5757\uff0c\u5229\u7528 os.getcwd() \u6765\u83b7\u6089\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u3002os \u8fd8\u63d0\u4f9b\u4e86 chdir() \u65b9\u6cd5\uff0c\u53ef\u4ee5\u6539\u53d8\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u3002<\/p>\n<div>\n<pre>import os\nprint(\\'\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55 :\\')\nprint(os.getcwd(), \\'\\\\n\\')\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<div>\n<div><\/div>\n<div data-width=\\\"552\\\" data-height=\\\"75\\\"><img src=\\\"https:\/\/upload-images.jianshu.io\/upload_images\/3386108-b148b5c0119a7a47.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/552\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/3386108-b148b5c0119a7a47.png\\\" data-original-width=\\\"552\\\" data-original-height=\\\"75\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"7852\\\" data-image-index=\\\"2\\\" \/><\/div>\n<\/div>\n<\/div>\n<h3>3.2 \u8bfb\u53d6 Excel \u5de5\u4f5c\u8868\uff08sheet\uff09<\/h3>\n<div>\n<pre>...\nprint(\\'\u53d6\u5f97\u6240\u6709\u5de5\u4f5c\u8868\u7684\u8868\u540d :\\')\nprint(wb.sheetnames, \\'\\\\n\\')\nprint(\\'\u53d6\u5f97\u67d0\u5f20\u5de5\u4f5c\u8868 :\\')\nsheet = wb[\\'Sheet3\\']\nprint(type(sheet))\nprint(\\'\u8868\u540d - \\' + sheet.title, \\'\\\\n\\')\nprint(\\'\u53d6\u5f97\u6d3b\u52a8\u5de5\u4f5c\u8868 :\\')\nactive_sheet = wb.active\nprint(\\'\u8868\u540d - \\' + active_sheet.title, \\'\\\\n\\')\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<blockquote><p>\u53d6\u5f97\u6240\u6709\u5de5\u4f5c\u8868\u7684\u8868\u540d :<br \/>\n[\\&#8217;Sheet1\\&#8217;, \\&#8217;Sheet2\\&#8217;, \\&#8217;Sheet3\\&#8217;]<\/p><\/blockquote>\n<blockquote><p>\u53d6\u5f97\u67d0\u5f20\u5de5\u4f5c\u8868 :<br \/>\n&lt;class \\&#8217;openpyxl.worksheet.worksheet.Worksheet\\&#8217;&gt;<br \/>\n\u8868\u540d &#8211; Sheet3<\/p><\/blockquote>\n<blockquote><p>\u53d6\u5f97\u6d3b\u52a8\u5de5\u4f5c\u8868 :<br \/>\n\u8868\u540d &#8211; Sheet1<\/p><\/blockquote>\n<ul>\n<li>Workbook \u5bf9\u8c61\u7684 sheetnames \u5c5e\u6027\u53ef\u4ee5\u83b7\u53d6\u6240\u6709 sheet \u8868\u7684\u8868\u540d\u5217\u8868\u3002<\/li>\n<li>Workbook \u5bf9\u8c61\u7684 active \u5c5e\u6027\uff0c\u4f1a\u83b7\u53d6\u5f53\u524d\u6d3b\u52a8\u8868\uff0c\u5373\u6253\u5f00 Excel \u65f6\u51fa\u73b0\u7684\u5de5\u4f5c\u8868\u3002<\/li>\n<li>\u83b7\u53d6 Worksheet \u5bf9\u8c61\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7 title \u5c5e\u6027\u5f97\u5230 sheet \u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<h3>3.3 \u8bfb\u53d6\u5355\u5143\u683c \uff08Cell\uff09<\/h3>\n<div>\n<pre>...\nprint(\\'\u53d6\u5f97 A1 \u5355\u5143\u683c :\\')\ncell = active_sheet[\\'A1\\']\nprint(cell)\nprint(cell.value, \\'\\\\n\\')\nprint(\\'\u53d6\u5f97 B1 \u5355\u5143\u683c :\\')\ncell = active_sheet[\\'B1\\']\nprint(cell)\nprint(cell.value, \\'\\\\n\\')\nprint(\\'\u884c\u53f7\u4e3a \\' + str(cell.row) + \\',\u5217\u53f7\u4e3a \\' + str(cell.column) + \\' \u7684\u5355\u5143\u683c\uff0c\u5176\u503c\u4e3a \\' + cell.value, \\'\\\\n\\')\nprint(\\'\u5355\u5143\u683c \\' + cell.coordinate + \\' \u5176\u503c\u4e3a \\' + cell.value, \\'\\\\n\\')\nprint(\\'\u53d6\u5f97 C1 \u5355\u5143\u683c\u7684\u503c :\\')\nprint(active_sheet[\\'C1\\'].value, \\'\\\\n\\')\nprint(\\'\u901a\u8fc7\u6307\u5b9a\u884c\u4e0e\u5217\uff0c\u6765\u83b7\u53d6\u5355\u5143\u683c:\\')\nprint(active_sheet.cell(row=1, column=2))\nprint(active_sheet.cell(row=1, column=2).value)\nprint(\\'\u8fed\u4ee3\u884c\u4e0e\u5217\uff0c\u6765\u83b7\u53d6\u5355\u5143\u683c\u7684\u503c:\\')\nfor i in range(1, 8, 2):\n    print(i, active_sheet.cell(row=i, column=2).value)\nprint(\\'\\\\n\\')\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<blockquote><p>\u53d6\u5f97 A1 \u5355\u5143\u683c :<br \/>\n&lt;Cell \\&#8217;Sheet1\\&#8217;.A1&gt;<br \/>\n\u6392\u540d<\/p><\/blockquote>\n<blockquote><p>\u53d6\u5f97 B1 \u5355\u5143\u683c :<br \/>\n&lt;Cell \\&#8217;Sheet1\\&#8217;.B1&gt;<br \/>\n\u56fd\u5bb6<\/p><\/blockquote>\n<blockquote><p>\u884c\u53f7\u4e3a 1,\u5217\u53f7\u4e3a 2 \u7684\u5355\u5143\u683c\uff0c\u5176\u503c\u4e3a \u56fd\u5bb6<\/p><\/blockquote>\n<blockquote><p>\u5355\u5143\u683c B1 \u5176\u503c\u4e3a \u56fd\u5bb6<\/p><\/blockquote>\n<blockquote><p>\u53d6\u5f97 C1 \u5355\u5143\u683c\u7684\u503c :<br \/>\n\u4eba\u53e3<\/p><\/blockquote>\n<blockquote><p>\u901a\u8fc7\u6307\u5b9a\u884c\u4e0e\u5217\uff0c\u6765\u83b7\u53d6\u5355\u5143\u683c:<br \/>\n&lt;Cell \\&#8217;Sheet1\\&#8217;.B1&gt;<br \/>\n\u56fd\u5bb6<br \/>\n\u8fed\u4ee3\u884c\u4e0e\u5217\uff0c\u6765\u83b7\u53d6\u5355\u5143\u683c\u7684\u503c:<br \/>\n1 \u56fd\u5bb6<br \/>\n3 \u5370\u5ea6<br \/>\n5 \u5370\u5ea6\u5c3c\u897f\u4e9a<br \/>\n7 \u5df4\u57fa\u65af\u5766<\/p><\/blockquote>\n<ul>\n<li>\u53ef\u4ee5\u901a\u8fc7\u5355\u5143\u683c\u7684\u540d\u5b57\uff08\u6bd4\u5982\uff1aA1\uff09\u6765\u83b7\u53d6 Cell \u5bf9\u8c61\u3002<\/li>\n<li>Cell \u5bf9\u8c61\u7684 value \u5c5e\u6027\uff0c\u5b58\u653e\u7684\u662f\u8be5\u5355\u5143\u683c\u4e2d\u6240\u4fdd\u5b58\u7684\u503c\u3002<\/li>\n<li>Cell \u5bf9\u8c61\u7684 row\u3001 column \u548c coordinate \u5c5e\u6027\uff0c\u5b58\u653e\u7684\u662f\u8be5\u5355\u5143\u683c\u7684\u4f4d\u7f6e\u4fe1\u606f\u3002<\/li>\n<li>\u7528\u5b57\u6bcd\u6765\u6307\u5b9a\u5217\u6bd4\u8f83\u5947\u602a\uff0c\u56e0\u6b64\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7 sheet \u7684 cell \u65b9\u6cd5\u76f4\u63a5\u6307\u5b9a\u884c\uff08row\uff09\u4e0e\u5217\uff08column\uff09\uff0c\u6765\u83b7\u53d6\u5355\u5143\u683c Cell \u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<h3>3.4 \u83b7\u53d6\u5de5\u4f5c\u8868\u5927\u5c0f<\/h3>\n<div>\n<pre>print(\\'\u83b7\u53d6\u5de5\u4f5c\u8868\u7684\u5927\u5c0f:\\')\nprint(\\'\u603b\u884c\u6570 -&gt; \\' + str(active_sheet.max_row))\nprint(\\'\u603b\u5217\u6570 -&gt; \\' + str(active_sheet.max_column))\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<blockquote><p>\u83b7\u53d6\u5de5\u4f5c\u8868\u7684\u5927\u5c0f:<br \/>\n\u603b\u884c\u6570 -&gt; 11<br \/>\n\u603b\u5217\u6570 -&gt; 4<\/p><\/blockquote>\n<p>Worksheet \u5bf9\u8c61\u7684 max_row \u4e0e max_column\uff0c\u53ef\u4ee5\u83b7\u53d6\u5de5\u4f5c\u8868\u7684\u603b\u884c\u6570\u4e0e\u603b\u5217\u6570\uff0c\u5373\u5de5\u4f5c\u8868\u7684\u5927\u5c0f\u3002<\/p>\n<h3>3.5 \u5217\u8f6c\u6362\u51fd\u6570<\/h3>\n<p>openpyxl \u63d0\u4f9b\u4e86\u4e24\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u8f6c\u6362\u5217\u53f7\uff1a<\/p>\n<ul>\n<li>openpyxl.utils.get_column_letter -&gt; \u4f1a\u628a\u6570\u5b57\u8f6c\u5316\u4e3a\u5b57\u6bcd\u3002<\/li>\n<li>openpyxl.utils.column_index_from_string -&gt; \u4f1a\u628a\u5b57\u6bcd\u8f6c\u5316\u4e3a\u6570\u5b57\u3002<\/li>\n<\/ul>\n<div>\n<pre>import openpyxl\nfrom openpyxl.utils import get_column_letter, column_index_from_string\n...\nprint(\\'\u5217\u8f6c\u6362\u51fd\u6570:\\')\nprint(\\'[\u6570\u5b57\u8f6c\u6362\u4e3a\u5b57\u6bcd]\\')\nprint(\\'\u7b2c 1 \u5217 -&gt; \\' + get_column_letter(1))\nprint(\\'\u7b2c 2 \u5217 -&gt; \\' + get_column_letter(2))\nprint(\\'\u7b2c 37 \u5217 -&gt; \\' + get_column_letter(37))\nprint(\\'\u7b2c 818 \u5217 -&gt; \\' + get_column_letter(818))\nprint(\\'[\u5b57\u6bcd\u8f6c\u6362\u4e3a\u6570\u5b57]\\')\nprint(\\'\u7b2c A \u5217 -&gt; \\' + str(column_index_from_string(\\'A\\')))\nprint(\\'\u7b2c CC \u5217 -&gt; \\' + str(column_index_from_string(\\'CC\\')))\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<blockquote><p>[\u6570\u5b57\u8f6c\u6362\u4e3a\u5b57\u6bcd]<br \/>\n\u7b2c 1 \u5217 -&gt; A<br \/>\n\u7b2c 2 \u5217 -&gt; B<br \/>\n\u7b2c 37 \u5217 -&gt; AK<br \/>\n\u7b2c 818 \u5217 -&gt; AEL<br \/>\n[\u5b57\u6bcd\u8f6c\u6362\u4e3a\u6570\u5b57]<br \/>\n\u7b2c A \u5217 -&gt; 1<br \/>\n\u7b2c CC \u5217 -&gt; 81<\/p><\/blockquote>\n<h3>3.6 \u5207\u7247<\/h3>\n<p>\u6211\u4eec\u53ef\u4ee5\u5bf9 Worksheet \u5bf9\u8c61\u5207\u7247\uff0c\u53d6\u5f97\u8868\u683c\u4e2d\u7684\u4e00\u4e2a\u77e9\u5f62\u533a\u57df\uff0c\u8fed\u4ee3\u904d\u5386\u8fd9\u4e2a\u533a\u57df\u4e2d\u7684\u6240\u6709 Cell \u5bf9\u8c61\u3002<\/p>\n<div>\n<pre>print(tuple(active_sheet[\\'A2\\':\\'D4\\']))\nfor row_objects in active_sheet[\\'A2\\':\\'D4\\']:\n    for cell_object in row_objects:\n        print(cell_object.coordinate, cell_object.value)\n    print(\\'-- \u5f53\u524d\u884c\u83b7\u53d6\u7ed3\u675f --\\')\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<blockquote><p>((&lt;Cell \\&#8217;Sheet1\\&#8217;.A2&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.B2&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C2&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.D2&gt;), (&lt;Cell \\&#8217;Sheet1\\&#8217;.A3&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.B3&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C3&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.D3&gt;), (&lt;Cell \\&#8217;Sheet1\\&#8217;.A4&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.B4&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C4&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.D4&gt;))<br \/>\nA2 1<br \/>\nB2 \u4e2d\u56fd<br \/>\nC2 13.83\u4ebf\u4eba(2016)<br \/>\nD2 9634057<br \/>\n&#8212; \u5f53\u524d\u884c\u83b7\u53d6\u7ed3\u675f &#8212;<br \/>\nA3 2<br \/>\nB3 \u5370\u5ea6<br \/>\nC3 1339180127<br \/>\nD3 2973190<br \/>\n&#8212; \u5f53\u524d\u884c\u83b7\u53d6\u7ed3\u675f &#8212;<br \/>\nA4 3<br \/>\nB4 \u7f8e\u56fd<\/p><\/blockquote>\n<p>C4 324459463<br \/>\nD4 9147420<br \/>\n&#8212; \u5f53\u524d\u884c\u83b7\u53d6\u7ed3\u675f &#8212;<\/p>\n<ul>\n<li>\u8fd9\u91cc\u9996\u5148\u901a\u8fc7 tuple() \u65b9\u6cd5\uff0c\u5c55\u793a\u51fa\u4e86\u5207\u7247\u540e\u7684\u6240\u6709 Cell \u5bf9\u8c61\u3002<\/li>\n<li>\u7136\u540e\u4f7f\u7528\u4e86\u4e24\u4e2a for \u5faa\u73af\uff0c\u5916\u5c42 for \u5faa\u73af\u4f1a\u904d\u5386\u8fd9\u4e2a\u5207\u7247\u4e2d\u7684\u6bcf\u4e00\u884c\uff1b\u800c\u5185\u5c42 for \u5faa\u73af\u4f1a\u904d\u5386\u8be5\u884c\u4e2d\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u3002<\/li>\n<\/ul>\n<h3>3.7 \u83b7\u53d6\u6307\u5b9a\u884c\u6216\u6307\u5b9a\u5217<\/h3>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Worksheet \u5bf9\u8c61\u7684 rows \u548c columns \u5c5e\u6027\uff0c\u6765\u83b7\u53d6\u6307\u5b9a\u884c\u6216\u8005\u5217\uff1a<\/p>\n<div>\n<pre>print(\\'\u83b7\u53d6\u7279\u5b9a\u884c:\\')\nprint(list(active_sheet.rows)[2])\nfor cell_object in list(active_sheet.rows)[2]:\n    print(cell_object.value)\nprint(\\'\u83b7\u53d6\u7279\u5b9a\u5217:\\')\nprint(list(active_sheet.columns)[2])\nfor cell_object in list(active_sheet.columns)[2]:\n    print(cell_object.value)\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<blockquote><p>\u83b7\u53d6\u7279\u5b9a\u884c:<br \/>\n(&lt;Cell \\&#8217;Sheet1\\&#8217;.A3&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.B3&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C3&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.D3&gt;)<br \/>\n2<br \/>\n\u5370\u5ea6<br \/>\n1339180127<br \/>\n2973190<br \/>\n\u83b7\u53d6\u7279\u5b9a\u5217:<br \/>\n(&lt;Cell \\&#8217;Sheet1\\&#8217;.C1&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C2&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C3&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C4&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C5&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C6&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C7&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C8&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C9&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C10&gt;, &lt;Cell \\&#8217;Sheet1\\&#8217;.C11&gt;)<br \/>\n\u4eba\u53e3<br \/>\n13.83\u4ebf\u4eba(2016)<br \/>\n1339180127<br \/>\n324459463<br \/>\n263991379<br \/>\n209288278<br \/>\n197015955<br \/>\n190886311<br \/>\n164669751<br \/>\n143989754<br \/>\n129163276<\/p><\/blockquote>\n<ul>\n<li>Worksheet \u5bf9\u8c61\u7684 rows \u6216\u8005 columns \u5c5e\u6027\uff0c\u90fd\u4f1a\u8fd4\u56de\u4e00\u4e2a\u7531 \u201c\u884c\u5143\u7ec4\u201d \u6784\u6210\u7684\u5143\u7ec4\u3002\u6bcf\u4e2a\u884c\u5143\u7ec4\u90fd\u62e5\u6709\u8be5\u884c\u4e2d\u7684\u6240\u6709 Cell \u5bf9\u8c61\u3002<\/li>\n<li>\u53ef\u4ee5\u901a\u8fc7\u884c\u5143\u7ec4\u7684\u4e0b\u6807\uff0c\u6765\u8bbf\u95ee\u5177\u4f53\u7684 Cell \u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<hr \/>\n<p>\u8bfb\u53d6 Excel \u6b65\u9aa4\uff0c\u603b\u7ed3\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u5bfc\u5165 openpyxl \u6a21\u5757\u3002<\/li>\n<li>\u8c03\u7528 openpyxl.load_workbook() \u51fd\u6570\uff0c\u52a0\u8f7d excel \u6587\u6863\uff0c\u83b7\u53d6 Workbook \u5bf9\u8c61\u3002<\/li>\n<li>\u8c03\u7528 workbook#active \u6216 workbook[${sheet_name}]\uff0c\u83b7\u53d6 sheet \u5de5\u4f5c\u7c3f\u3002<\/li>\n<li>\u4f20\u5165 row \u548c column \u5173\u952e\u5b57\u53c2\u6570\u5e76\u8c03\u7528\u7d22\u5f15\u6216\u5de5\u4f5c\u8868\u7684 cell() \u65b9\u6cd5\uff0c\u83b7\u53d6 Cell \u5bf9\u8c61\u3002<\/li>\n<li>\u6709\u4e86 Cell \u5bf9\u8c61\uff0c\u5c31\u53ef\u4ee5\u6267\u884c\u5177\u4f53\u7684\u4e1a\u52a1\u903b\u8f91\u54af\u3002<\/li>\n<\/ol>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>Python \u7684 openpyxl \u6a21\u5757\u53ef\u4ee5\u8ba9\u6211\u4eec\u80fd\u8bfb\u53d6\u548c\u4fee\u6539 Excel \u6587\u4ef6\u3002 \u9996\u5148\u8ba9\u6211\u4eec\u5148\u7406\u89e3\u4e00\u4e9b Ex &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1714\"> <span class=\"screen-reader-text\">\u4f7f\u7528 python \u7684 openpyxl \u8bfb\u53d6 Excel<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[106,126],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"Python \u7684 openpyxl \u6a21\u5757\u53ef\u4ee5\u8ba9\u6211\u4eec\u80fd\u8bfb\u53d6\u548c\u4fee\u6539 Excel \u6587\u4ef6\u3002 \u9996\u5148\u8ba9\u6211\u4eec\u5148\u7406\u89e3\u4e00\u4e9b Ex&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1714"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1714"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1714\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1714"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}