{"id":3828,"date":"2018-09-19T21:42:46","date_gmt":"2018-09-19T13:42:46","guid":{"rendered":"https:\/\/dmesg.app\/?p=3828"},"modified":"2018-09-20T10:32:15","modified_gmt":"2018-09-20T02:32:15","slug":"python-excel-add-column","status":"publish","type":"post","link":"https:\/\/dmesg.app\/python-excel-add-column.html","title":{"rendered":"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217"},"content":{"rendered":"<p><span style=\"font-size: 12pt;\">\u524d\u51e0\u5929\u6709\u8fd9\u4e48\u4e00\u4e2a\u9700\u6c42\uff0c\u8981\u7ed9Excel\u8868\u683c\u7684\u6700\u524d\u9762\u52a0\u5165\u4e24\u5217\u3002\u6211\u60f3\u8fd9\u4e0d\u662f\u975e\u5e38\u7b80\u5355\u5417\uff1f\u51e0\u884c\u4ee3\u7801\u800c\u5df2\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">import openpyxl\r\n\r\nwb = openpyxl.load_workbook(&#039;simple.xlsx&#039;)\r\nsh = wb.active\r\nsh.insert_cols(1)\r\nwb.save(&#039;result.xlsx&#039;)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u975e\u5e38\u7b80\u5355\uff0c\u81ea\u5df1\u8fd8\u627e\u4e86\u4e2a\u8868\u683c\u8bd5\u4e86\u4e0b\uff0c\u597d\u50cf\u6ca1\u95ee\u9898\u3002<\/span><\/p>\n<p><a href=\"https:\/\/dmesg.app\/wp-content\/uploads\/2018\/09\/2018091913193939.png\" alt=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" title=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" rel=\"box\" class=\"fancybox\"><img loading=\"lazy\" decoding=\"async\" width=\"535\" height=\"171\" class=\"alignnone size-full wp-image-3831\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/09\/2018091913193939.png\" alt=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" title=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" alt=\"\" \/><\/a><\/p>\n<p><span style=\"font-size: 12pt;\">\u7136\u540e\u6211\u53d1\u73b0\u6211\u8981\u5904\u7406\u7684\u8868\u683c\u662f\u5e26\u6709\u5408\u5e76\u5355\u5143\u683c\u7684\uff0c\u7528\u8fd9\u51e0\u884c\u4ee3\u7801\u5904\u7406\u4e0b\u53d1\u73b0\u2026\u2026<\/span><\/p>\n<p><a href=\"https:\/\/dmesg.app\/wp-content\/uploads\/2018\/09\/2018091913194017.png\" alt=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" title=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" rel=\"box\" class=\"fancybox\"><img loading=\"lazy\" decoding=\"async\" width=\"761\" height=\"427\" class=\"alignnone size-full wp-image-3832\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/09\/2018091913194017.png\" alt=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" title=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" alt=\"\" \/><\/a><\/p>\n<p><span style=\"font-size: 12pt;\">\u6211\u7684\u5355\u5143\u683c\u90fd\u4e71\u5957\u4e86\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u53ef\u548b\u6574\u2026\u2026\u4e0d\u7ba1\u4e86\uff0c\u638f\u51fa\u4e86openpyxl<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">openpyxl<\/span><\/h2>\n<h3><span style=\"font-size: 12pt;\">\u5904\u7406xlsx\u5408\u5e76\u5355\u5143\u683c\u63d2\u5165\u5217<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u5176\u5b9e\u5904\u7406\u601d\u8def\u5f88\u7b80\u5355\uff0c\u904d\u5386\u6bcf\u4e00\u4e2a\u5355\u5143\u683c\uff0c\u7ed9\u7eb5\u5750\u6807+2\uff0c\u7136\u540e\u6837\u5f0f\u4ec0\u4e48\u7684\u4e5f\u62f7\u8d1d\u4e00\u4efd\u5199\u5230\u65b0\u7684\u8868\u683c\u91cc\u5c31\u597d\u4e86\u3002\u4f46\u662f\u4e00\u7247\u4e0d\u5927\u4e0d\u5c0f\u7684\u6c34\u57df\uff0c\u603b\u662f\u6709\u90a3\u4e48\u4e0d\u591a\u4e0d\u5c11\u7684\u6c34\u5751\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u5982\u4f55\u5224\u65ad\u5408\u5e76\u5355\u5143\u683c<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u5728openpyxl\u4e2d\uff0c \u5408\u5e76\u5355\u5143\u683c\u662f\u4ee5<code>ws.merged_cells<\/code>\u8fd9\u4e2a\u5217\u8868\u8868\u793a\u7684\uff0c\u8fd9\u4e2a\u5217\u8868\u91cc\u9762\u7684\u5f62\u5f0f\u5982\u4e0b\uff1aI1:I2 D1:E1 A1:A2 B1:C1 F1:H1\uff0c\u6bcf\u4e00\u5bf9\u7528\u5192\u53f7\u8fde\u63a5\u7684\u5750\u6807\u8868\u793a\u8fd9\u4e24\u4e2a\u4e4b\u95f4\u662f\u5408\u5e76\u7684\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u6837\u95ee\u9898\u5c31\u7b80\u5355\u5566\uff0c\u6211\u4eec\u53ea\u9700\u8981\u628a\u5750\u6807+2\u5c31\u597d\u4e86\uff0c\u6bd4\u5982\u8bf4A1:B2\u53d8C1:E2\uff0cK1:J5\u53d8M1:L1\uff0cZ1:AA1\u53d8AB1:AC1\uff0c\u7b49\u7b49\u4ec0\u4e48\uff1fZ1:AA1\u53d8AB1:AC1\uff1f\u6ca1\u529e\u6cd5\u6211\u8fd9\u4e2aExcel\u6709\u70b9\u957f\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u4e2a\u4e0d\u662f\u666e\u901a\u7684\u52a0\u6cd5\u554a\uff0c\u901a\u8fc7<code>ord()<\/code>\u548c<code>chr()<\/code>\u6765\u56de\u8f6c\u6362\u5427\uff1f\u8fdb\u5751\u4e86\u5427\u5c11\u5e74?<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u4e8c\u5341\u516d\u8fdb\u5236\uff1f\uff1f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u6211\u4eec\u4e86\u89e3\u5230\uff0cExcel\u7684\u5750\u6807\u53d8\u5316\u662f\u5b57\u6bcd\u8868\u7684\u8fdb\u4f4d\uff0c\u4e5f\u5c31\u662f26\u8fdb\u5236\uff01\u8fd9\u2026\u2026\u4e8c\u8fdb\u5236\uff0c\u516b\u8fdb\u5236\uff0c\u5341\u516d\u8fdb\u5236\u90fd\u662f\u54b1\u6bd4\u8f83\u5e38\u7528\u7684\uff0c\u8fd9\u4e8c\u5341\u516d\u8fdb\u5236\u662f\u4ec0\u4e48\u9b3c\uff1f\u6765\u6211\u4eec<code>if\u2026elif\u2026elif\u2026.elif<\/code>\u5199\u4e00\u6ce2\u2026\u2026<\/span><\/p>\n<pre class=\"prettyprint linenums\">def twenty_six(coord, size):\r\n# A1:B2, AB1:AC2\r\n    left = coord.split(&#039;:&#039;)[0]\r\n    right = coord.split(&#039;:&#039;)[-1]\r\n    left_char = left[0]\r\n    right_char = right[0]\r\n\r\n    if len(left_char) == 1 and len(right_char) == 1:\r\n        return &quot;%s:%s&quot; % (chr(ord(left_char + size)), chr(ord(right_char + size)))\r\n    elif len(left_char) == 2 and len(right_char) == 2:\r\n        return &quot;%s:%s&quot; % (chr(ord(left_char + size)), chr(ord(right_char + size)))\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u54ce\uff1f\u90a3\u8981\u5750\u6807\u662fA1:AZ3\u7684\u5462\uff1f\u4e0d\u7528\u60f3\u4e86\u8fd9\u6bb5\u4ee3\u7801\u662f\u9519\u7684\u26f2<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u90a3\u4e48\u6211\u4eec\u6765\u521b\u9020\u4eba\u7c7b\u53f2\u4e0a\u7684\u7b2c\u4e00\u4e2a26\u8fdb\u5236\u5427\uff01\u5c0f\u4f19\u5b50\uff0c\u53c8\u8fdb\u5751\u4e86\u5427\u2026\u2026?<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8981\u4ec0\u4e4826\u8fdb\u5236\u554a\uff0c\u76f4\u63a5\u5f04\u4e2aA, B, C, D\u2026.AA, AB, AC\u2026.BC, BD\u2026.ZZ\u4e00\u517126*26\u4e2a\u5143\u7d20\u7684\u5217\u8868\uff0c\u901a\u8fc7index\u67e5\u5f97\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6240\u4ee5\u6240\u8c13\u7684\u201c26\u8fdb\u5236\u201d\u54b1\u53ef\u4ee5\u8fd9\u4e48\u5904\u7406\u4e00\u6ce2\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">import itertools\r\nimport string\r\n\r\ntable = list(itertools.chain(string.ascii_uppercase,(&#039;&#039;.join(pair) for pair in itertools.product(string.ascii_uppercase, repeat=2))))\r\n\r\ndef twenty_six(char, size):\r\n    index = table.index(char)\r\n    return table[index + size]\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u5176\u4e2d<code>char<\/code>\u662f\u8868\u793a\u5b57\u6bcd\uff08\u4e0d\u5e26\u6570\u5b57\u7684\u90a3\u79cd\uff09<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u559c\u6b22\u6311\u523a\u7684\u7ae5\u978b\u4eec\u53ef\u80fd\u4f1a\u8bf4\uff0c\u4f60\u8fd9\u662f\u5217\u8868\uff0c\u5217\u8868\u67e5\u627e\u53ef\u80fd\u5f97\u5168\u90fd\u904d\u5386\u5b8c\u4e86\u624d\u67e5\u627e\u5230\uff0c\u4f60\u8fd9\u592a\u6d6a\u8d39\u65f6\u95f4\u4e86\u3002\u5f97\u7528\u5b57\u5178\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5582(#`O\u2032)\u7ae5\u978b\uff0c\u5982\u679c\u7528\u5b57\u5178\u7684\u8bdd\uff0c\u90a3\u4e48\u9700\u8981\u4e0d\u4ec5\u80fd\u4ece\u952e\uff08\u5b57\u6bcd\uff09\u627e\u5230\u503c\uff0c\u8fd8\u5f97\u9700\u8981\u901a\u8fc7\u503c\u627e\u5230\u952e\uff0c\u8fd9\u2026\u2026\u884c\u884c\u884c\uff0c\u6ca1\u5565\u4e0d\u53ef\u80fd\u7684\uff0c\u952e\u503c\u5bf9\u53cd\u8f6c\u561b\uff0c\u9762\u8bd5\u5fc5\u4f1a\u9898\u76ee\u3002\u90a3\u4e48\u7528\u5b57\u5178\uff0ctable\u5927\u6982\u5c31\u662f\u8fd9\u4e48\u6784\u9020\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4f7f\u7528dict\u65b9\u6cd5<\/span><\/p>\n<pre class=\"prettyprint linenums\">table = [dict(zip(itertools.chain(string.ascii_uppercase, \r\n(&#039;&#039;.join(pair) for pair in itertools.product(string.ascii_uppercase, repeat=2))),\r\n[i for i in range(26 * 26)])),\r\ndict(zip([i for i in range(26 * 26)], itertools.chain(string.ascii_uppercase,\r\n(&#039;&#039;.join(pair) for pair in itertools.product(string.ascii_uppercase, repeat=2)))))]\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc(\uff89*\uff65\u03c9\uff65)\uff89\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">base = dict(zip(itertools.chain(string.ascii_uppercase,\r\n(&#039;&#039;.join(pair) for pair in itertools.product(string.ascii_uppercase, repeat=2))),\r\n[i for i in range(26 * 26)]))\r\n\r\ntable = [base, {v: k for k, v in base.items()}]\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\"><code>table[0]<\/code>\u8868\u793a\u4ece\u5b57\u6bcd\u67e5\u627e\u6570\u5b57\uff0c\u7ed9\u6570\u5b57+2\u4e4b\u540e\u5728<code>table[1]<\/code>\u4ece\u6570\u5b57\u67e5\u627e\u5b57\u6bcd\uff0c\u8c03\u7528\u5c31\u66f4\u7b80\u5355\u4e86\u3002\u6211\u7231(\uff89*\uff65\u03c9\uff65)\uff89\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u7136\u800c\u5b9e\u9645\u4e0a\uff0c676\u4e2a\u5143\u7d20\u6709\u70b9\u5c11\uff0c\u5b57\u5178\u7684\u7a7a\u95f4\u6362\u65f6\u95f4\u51e0\u4e4e\u662f\u5212\u4e0d\u6765\u7684\u3002\u800c\u4e14<code>dict()<\/code>\u548c<code>zip()<\/code>\u65b9\u6cd5\u4ee5\u53ca\u904d\u5386\u5b57\u5178\u4e5f\u4f1a\u82b1\u8d39\u4e00\u70b9\u65f6\u95f4\uff0c\u4ee3\u7801\u8fd8\u5199\u5f97\u5f88\u957f\uff0c\u6240\u4ee5\u7b80\u5355\u8d77\u89c1\u751f\u6210\u4e2a\u5217\u8868\u5c31\u591f\u4e86\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u5904\u7406\u5b57\u6bcd\u5f0f\u5750\u6807<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u5728\u89e3\u51b3\u4e8626\u8fdb\u5236\u4e4b\u540e\uff0c\u6211\u4eec\u53ea\u9700\u8981\u628a\u5b57\u6bcd\u4ece\u4e00\u4e2a\u5408\u5e76\u5355\u5143\u683c\u5750\u6807\u4e2d\u63d0\u53d6\u51fa\u6765\u5c31\u53ef\u4ee5\u4e86\uff0c\u8981\u5b8c\u6210\u8fd9\u9879\u5de5\u4f5c\u5176\u5b9e\u65b9\u6cd5\u633a\u591a\u7684\uff0c\u6bd4\u8f83\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u76f4\u63a5\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u4e00\u641c\u5c31\u6709\u3002\u8fd9\u91cc\u5c31\u4e0d\u5199\u4e86\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u904d\u5386\u5355\u5143\u683c\u5185\u5bb9\u548c\u6837\u5f0f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u6211\u4eec\u9700\u8981\u904d\u5386\u6bcf\u4e2a\u5355\u5143\u683c\uff0c\u591a\u4e8f\u4e86PyCharm\u7684Evaluate Expression\u529f\u80fd\uff0c\u5f88\u5bb9\u6613\u5c31\u53d1\u73b0\u904d\u5386\u5355\u5143\u683c\u7684\u65b9\u6cd5\uff1a<\/span><\/p>\n<p><a href=\"https:\/\/dmesg.app\/wp-content\/uploads\/2018\/09\/2018091913194476.png\" alt=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" title=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" rel=\"box\" class=\"fancybox\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"545\" class=\"alignnone size-full wp-image-3833\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/09\/2018091913194476.png\" alt=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" title=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" alt=\"\" \/><\/a><\/p>\n<p><span style=\"font-size: 12pt;\">\u6211\u4eec\u53ef\u4ee5\u5f88\u6e05\u695a\u7684\u770b\u5230\uff0ci\u8fd9\u4e2a\u53d8\u91cf\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u90fd\u5305\u542b\u4e86\u8fd9\u4e2a\u8868\u683c\u7684\u5168\u90e8\u4fe1\u606f\uff0c\u5305\u62ec\u5185\u5bb9\uff0c\u8fb9\u6846\uff0c\u586b\u5145\uff0c\u5b57\u4f53\u7b49\u7b49\u3002\u90a3\u4e48\u83b7\u53d6\u5230\u8fd9\u4e9b\u4fe1\u606f\u5c31\u5f88\u7b80\u5355\u4e86\uff0c\u4e00\u4e2a\u53cc\u5faa\u73af\u5373\u53ef\uff1a <\/span><\/p>\n<pre class=\"prettyprint linenums\">for i in ws.rows:\r\n    for v in i:\r\n        print(v.coordinate, v.fill, v.border, v.value)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\"><code>v.coordinate<\/code>\u8868\u793a\u7684\u662f\u5355\u5143\u683c\u7684\u5b57\u6bcd\u5f0f\u5750\u6807\uff0c\u6211\u4eec\u53ef\u4ee5\u7ed9\u4e0a\u9762\u5c01\u88c5\u597d\u7684twenty_six\u8c03\u7528\u4e0b\uff0c\u5c31\u80fd\u591f\u505a\u597d\u65b0\u7684\u79fb\u52a8\u4e4b\u540e\u7684\u5750\u6807\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u90a3\u4e48\u62f7\u8d1d\u6837\u5f0f\u5427\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u62f7\u8d1d\u5355\u5143\u683c\u6837\u5f0f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u5728openpyxl\u4e2d\uff0c\u7ed9\u5355\u5143\u683c\u5199\u5165\u6837\u5f0f\u975e\u5e38\u7b80\u5355\uff0c\u5927\u6982\u5982\u4e0b\u5c31\u53ef\u4ee5\u4e86\uff1a<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><code>ws['A1'].fill='Your fill style'<\/code><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6211\u4eec\u628a\u4e0a\u9762\u904d\u5386\u8fc7\u6765\u7684\u5185\u5bb9\u76f4\u63a5\u8d4b\u503c\u5c31\u53ef\u4ee5\u4e86\uff0c\u5927\u6982\u5982\u4e0b\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">for i in ws.rows:\r\n    for v in i:\r\n        coord = &#039;\u79fb\u52a8\u4e4b\u540e\u7684\u5750\u6807&#039;\r\n        # copy fill border and everything\r\n        write_ws[coord].fill = v.fill\r\n        write_ws[coord].font = v.border\r\n        write_ws[coord].border = v.border\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u7ae5\u978b\uff0c\u4f60\u53c8\u8fdb\u5751\u4e86\u2501((*\u2032\u0434\uff40)\u723b(\u2032\u0434\uff40*))\u2501!!!!<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5c3d\u7ba1\u901a\u8fc7Evaluate\u80fd\u591f\u770b\u5230\u53f3\u9762\u7684\u7c7b\u578b\u662f\u5de6\u8fb9\u63a5\u53d7\u7684\u7c7b\u578b\uff0c\u4f46\u662f\u8fd8\u662f\u62a5\u9519\u3002\u4e3a\u4ec0\u4e48\u4e0d\u5c1d\u8bd5\u4e0b\u6d45\u62f7\u8d1d\u5462\uff1f\u55ef\u8fd9\u662f\u597d\u7528\u7684\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><code>from copy import copy<\/code>\u628a<code>v.fill<\/code>\u66ff\u6362\u6210<code>copy(v.fill)<\/code>\u5c31\u597d\u4e86<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u7ed9\u5408\u5e76\u5355\u5143\u683c\u5e94\u7528\u6837\u5f0f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u4e2a\u6709\u70b9\u7279\u6b8a\uff0c<a href=\"https:\/\/openpyxl.readthedocs.io\/en\/stable\/styles.html#styling-merged-cells\">openpyxl\u5b98\u7f51\u5199\u597d<\/a>\u4e86\u4e00\u4e2a\uff0c\u54b1\u62ff\u8fc7\u6765\u76f4\u63a5\u7528\u5c31\u597d\u4e86\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u62f7\u8d1d\u5355\u5143\u683c\u5185\u5bb9<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u5355\u5143\u683c\u5185\u5bb9\u7528<code>v.value<\/code>\u5c31\u80fd\u8bfb\u5230\u4e86\u3002\u4f46\u662f\u90a3\u4e9b\u5408\u5e76\u4e86\u7684\u5355\u5143\u683c\uff0c\u7a76\u7adf\u662f\u8bfb\u53d6\u54ea\u4e2a\u5750\u6807\u624d\u80fd\u8bfb\u5230\u5462?\u522b\u731c\u4e86\uff0c\u8ba9\u6211\u6765\u544a\u8bc9\u4f60\uff0c\u5de6\u4e0a\u89d2\u7684\u3002\u5176\u4ed6\u7684\u8bfb\u53d6\u51fa\u6765\u7684\u90fd\u662f<code>None<\/code><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6240\u4ee5\u62f7\u8d1d\u5355\u5143\u683c\u5185\u5bb9\u5c31\u592a\u7b80\u5355\u4e86\uff0c\u5224\u65ad\u4e0b\u5c31\u597d\u4e86\u3002<\/span><\/p>\n<pre class=\"prettyprint linenums\">if v.value:\r\n    self.write_ws[coord] = v.value\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u556a(\uffe3\u03b5(#\uffe3)\u6253\u98de\u4f60\u3002\u5982\u679c\u67d0\u4e2a\u5355\u5143\u683c\u7684\u5185\u5bb9\u662f0\uff0c0\u662f\u5e03\u5c14\u5047\u503c\u554a\u2026\u2026\u90a3\u5c82\u4e0d\u662f\u4e22\u6570\u636e\u4e86\uff1f\uff1f<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5c0f\u53ef\u7231\uff0c\u5224\u65ad\u4e0b\uff0c\u8fd9\u662f\u4e2a\u7279\u4f8b\u3002\u4e8e\u662f\u4e4e\u542d\u54e7\u542d\u54e7\u2026\u2026<\/span><\/p>\n<pre class=\"prettyprint linenums\">elif type(v.value) == int:\r\n    pass\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u556a(\u3002&gt;\ufe3f&lt;)_\u03b8\u518d\u6b21\u6253\u98de\u4f60\u3002\u96be\u9053\u4e0d\u77e5\u9053\u6709\u4e2a\u4e1c\u897f\u53eb<code>isinstance()<\/code>\u561b\uff1f\u540e\u9762\u7684\u7c7b\u578b\u53ef\u4ee5\u662f\u5143\u7ec4\uff0c\u5217\u8868\u6216\u8005\u5355\u4e2a\u7c7b\u578b\uff08\u7c7b\u554a\uff0cint\u554a\uff0cfloat\u554a\u5565\u7684\u90fd\u53ef\u4ee5\uff09<\/span><\/p>\n<pre class=\"prettyprint linenums\">elif isinstance(v.value, float):\r\n    pass\r\n<\/pre>\n<h3><span style=\"font-size: 12pt;\">\u7ec4\u88c5\u2026\u2026<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u597d\u5427\uff0c\u90a3\u4e48\u5751\u90fd\u8e29\u7684\u5dee\u4e0d\u591a\u4e86\uff0c\u7ec4\u88c5\u7ec4\u88c5\u5c31\u597d\u4e86\uff0c\u5148\u62f7\u8d1d\u6bcf\u4e2a\u5355\u5143\u683c\uff0c\u518d\u7ed9<code>merge_cell<\/code>\u62f7\u8d1d\u8fc7\u53bb\uff0c\u57fa\u672c\u4e0a\u5c31\u6ca1\u5565\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">biu biu biu\u4e8e\u662f\u522b\u4eba\u7ed9\u4f60\u53d1\u4e86\u4e00\u4e2axls\u683c\u5f0f\u7684Excel\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">openpyxl\u4e0d\u652f\u6301xls\u54e6\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u8f6c\u6362\u683c\u5f0f\uff1f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u6015\u5565\uff0copenpyxl\u4e0d\u652f\u6301\u8bfbxls\uff0c\u6211\u4eec\u5c31\u627e\u4e2a\u4e1c\u897f\u7ed9\u8f6c\u6362\u6210xlsx\uff0c\u518d\u62ff\u4ed6\u5904\u7406\u3002\u4ec0\u4e48pandas\u554a\uff0cpyexcel\u554a\u90fd\u884c\uff0c\u8981\u4e0d\u968f\u624b\u627e\u4e2a\u4ec0\u4e48\u5728\u7ebf\u8f6c\u6362\u7684\u652f\u6301REST API\u7684\u54b1\u7528requests\u8d70\u8d77\u554a\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4f60\u770b\uff0c\u8fd9\u4e2a?\u662f\u4ec0\u4e48\uff0c\u9ed1\u4e4e\u4e4e\u7684\u6211\u770b\u4e0d\u6e05\uff0c\u8981\u4e0d\u4f60\u8df3\u8fdb\u53bb\u770b\u4e0b\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e0d\u7528\u8bd5\u4e86\uff0c\u90a3\u4e9b\u5e93\u628axls\u8f6c\u6362\u6210xlsx\u4e4b\u540e\uff0c\u5408\u5e76\u5355\u5143\u683c\u57fa\u672c\u4e22\u7684\u5dee\u4e0d\u591a\u7684\u4e86\u3002\u7528\u5728\u7ebf\u8f6c\u6362\uff0c\u6bd4\u5982\u8bf4\u725b\u903c\u54c4\u54c4\u7684Google Docs\uff1f\u6050\u6015\u6211\u662f\u8981\u8bf7<a href=\"https:\/\/zh.wikipedia.org\/wiki\/Legal_High\" target=\"_blank\" rel=\"noopener\">\u9edb\u771f\u77e5\u5b50<\/a>\u5f53\u6211\u7684\u8fa9\u62a4\u5f8b\u5e08\u5440\u2026\u2026\u554a\u4e0d\uff0c\u6211\u613f\u610f\uff0c\u975e\u5e38\u613f\u610f\uff0c\u771f\u7684\u771f\u7684\u90a3\u5c31\u5728\u7ebf\u8f6c\u6362\u5427\u3002\u5c0f\u9edb\u8bf7\u4f60\u4e3a\u6211\u5531\u4e00\u9996\u6b4c(\/\u2267\u25bd\u2266)\/<\/span><\/p>\n<p><iframe src=\"\/\/player.bilibili.com\/player.html?aid=4012670&amp;cid=6469605&amp;page=1\" frameborder=\"no\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/p>\n<p><span style=\"font-size: 12pt;\">\u54e6\u90a3\u4e2a\u5bf9\u4e0d\u8d77\uff0c\u5176\u5b9e\u6211\u5bb6\u5c0f\u9edb\u5531\u6b4c\u597d\u597d\u542c\u7684\u3002\u7231\u8001\u5a46\u7684\u6e05\u5531??(*\uffe33\uffe3)\u256d<\/span><\/p>\n<p><iframe src=\"\/\/player.bilibili.com\/player.html?aid=2440565&amp;cid=3820356&amp;page=1\" frameborder=\"no\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/p>\n<p><span style=\"font-size: 12pt;\">(\u3065\uffe3 3\uffe3)\u3065<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">xlrd xlwt xlutils<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u6240\u4ee5\u8bf4\u5230\u5e95\uff0c\u6211\u4eec\u53c8\u7528\u56de\u6765\u4e86xlrd\u8fd9\u4e00\u7cfb\u5217\uff1f\u4e0d\u8fc7\u597d\u5728\u601d\u8def\u5df2\u7ecf\u6709\u4e86\uff0c\u90a3\u4e48\u5c31\u7b80\u5355\u4e86\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u8bfb\u53d6\u5408\u5e76\u5355\u5143\u683c<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u540c\u6837\u7684\uff0c\u501f\u52a9PyCharm\u7684Debug\uff0c\u54b1\u5f88\u5feb\u5c31\u627e\u5230\u4e86\u5408\u5e76\u5355\u5143\u683c\u5b58\u4e8e<code>read_ws.merged_cells<\/code>\u4e2d\u3002\u5f53\u7136\u8981\u904d\u5386\u5566\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u5305\u542b\u4e86\u56db\u4e2a\u6570\u5b57\u7684\u5143\u7ec4\u3002\u8fd9\u56db\u4e2a\u6570\u5b57\u90fd\u662f\u5565\u554a\u2026\u2026\u54ce\u563f\u563f\u5750\u6807\u5457\uff0c\u2196\u2198\u9171\u7d2b\u7684\u5457\uff0c\u4ece0\u5f00\u59cb\u6570\u6570\u54e6\uff0c\u524d\u5f00\u540e\u95ed\u54e6\uff08\u54e6\u5bf9\u4e0d\u8d77\u6211\u9ad8\u4e2d\u6570\u5b66\u5c31\u6ca1\u53ca\u683c\u8fc7\uff09\u3002<\/span><\/p>\n<pre class=\"prettyprint linenums\">for (rlow, rhigh, clow, chigh) in read_ws.merged_cells:\r\n    print(rlow, rhigh, clow, chigh)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u90a3\u600e\u4e48\u8bfb\u53d6\u5230\u5408\u5e76\u5355\u5143\u683c\u7684\u503c\u5462\uff1f\u5f53\u7136\u8fd8\u662f\u5de6\u4e0a\u89d2\u7684\u5750\u6807\u5566\u3002\u90a3\u662f\u4ec0\u4e48\u5462\uff0c\u53cd\u6b63\u5c314\u4e2a\u6570\u5b57\uff0c\u6392\u5217\u7ec4\u5408\u4e5f\u5c31\u5341\u51e0\u79cd\uff0c\u54ce\u2026\u2026\u597d\u5427\uff0c\u662frlow\u548cclow\u5566\u3002\u8bfb\u53d6\u7684\u8bdd\u5c31<code>read_ws.cell(1,2).value<\/code>\u5c31\u62ff\u5230\u4e86\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u5199\u5165\u5408\u5e76\u5355\u5143\u683c<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u4e2a\u4e5f\u5f88\u7b80\u5355\u5566\uff0c<code>write_merge()<\/code>\u63a5\u53d74\u4e2a\u5fc5\u9009\u53c2\u6570\uff0c\u4e5f\u5c31\u662f\u5750\u6807\uff0c1\u4e2a\u53ef\u9009\u53c2\u6570\u63d2\u5165\u7684\u503c\uff0c\u53e6\u4e00\u4e2a\u53ef\u9009\u53c2\u6570\u6837\u5f0f\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6240\u4ee5\u590d\u5236\u5408\u5e76\u5355\u5143\u683c\u5c31\u8fd9\u6837\u5b50\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">for (rlow, rhigh, clow, chigh) in read_ws.merged_cells:\r\n    # 2nd &amp; 4th parameter have to -1\r\n    write_ws.write_merge(rlow, rhigh - 1, clow + size, chigh - 1 + size, read_ws.cell(rlow, clow).value)\r\n<\/pre>\n<h3><span style=\"font-size: 12pt;\">\u8bfb\u53d6\u5355\u5143\u683c\u6837\u5f0f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">xlrd\u7684\u6837\u5f0f\u662f\u600e\u4e48\u8bfb\u51fa\u6765\u7684\u5462\uff1f\u627e\u904d\u4e86<code>sh.cell()<\/code>\u7684\u8fd4\u56de\u503c\u4e5f\u6ca1\u53d1\u73b0\u6709\u4ec0\u4e48\u7ed3\u6784\u662f\u5b58\u7740\u6837\u5f0f\u7684\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u731b\u7136\u95f4\u53d1\u73b0\u4e00\u4e2a<code>sh.cell_xf_index()<\/code>\u4f3c\u4e4e\u53ef\u4ee5\u62ff\u5230\u6837\u5f0f\u7684\u7d22\u5f15\u7684\u2026\u2026\u8fd8\u6709\u4e2a<code>wb.xf_list<\/code>\uff0c\u4e8e\u662f\u7528\u7d22\u5f15\u53bb\u53d6\uff0c\u5b8c\u7f8e\u4e86\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u5e94\u7528\u5355\u5143\u683c\u6837\u5f0f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u6837\u5f0f\u5df2\u7ecf\u53d6\u5230\u4e86\uff0c\u90a3\u4e48\u8d4b\u503c\u7ed9\u5173\u952e\u5b57\u53c2\u6570style\uff0c\u274c\uff1bcopy\u4e00\u4e0b\u8d4b\u503c\uff0c\u274c\u2026\u2026\u7c7b\u578b\u4f3c\u4e4e\u6b63\u786e\u554a\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e00\u628a\u68ad\u4e00\u628a\u68ad\uff0c\u62ff\u8d77\u6765\u5c31\u662f\u5e72\uff0c\u6211\u4e0d\u4f1a\u7f16\u7a0b\uff0c\u5168\u90fd\u662f\u6284StackOverflow\u7684\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">xlrd\u7684\u6837\u5f0f\u4e0d\u80fd\u5e94\u7528\u7ed9xlwt\u54e6\u4eb2\u4eb2\u3002(\u256f\u2035\u25a1\u2032)\u256f\ufe35\u253b\u2501\u253b\u6c14\u5f97\u6211\u5f53\u573a\u5c31\u628a\u684c\u5b50\u6380\u4e86\u3002<\/span><\/p>\n<pre class=\"prettyprint linenums\">w = XLWTWriter()\r\nprocess(XLRDReader(wb, &#039;unknown.xls&#039;), w)\r\nw.style_list\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u4ece\u8fd9\u4e2a<code>w.style_list<\/code>\u53d6\u4e0b\u6807\uff0c\u8fd9\u4e2a\u503c\u5c31\u662f\u53ef\u4ee5\u4f20\u7ed9xlwt\u7684\u5173\u952e\u5b57\u53c2\u6570style\u7684\u4e86\u2714\u25cb( \uff3e\u76bf\uff3e)\u3063Hiahiahia\u2026<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u904d\u5386\u5e76\u5199\u5165\u5355\u5143\u683c\u5185\u5bb9\u548c\u6837\u5f0f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">xlrd\u7684<code>read_ws.nrows<\/code>\u548c<code>read_ws.ncols<\/code>\u8868\u793a\u4e86\u8fd9\u4e2a\u8868\u683c\u603b\u8ba1\u7684\u884c\u6570\u548c\u5217\u6570\uff0c\u7b80\u5355\u7c97\u66b4\u53cc\u5faa\u73af\uff0c\u540c\u6837\u9700\u8981\u6ce8\u610f\u5e03\u5c14\u503c\u4e3a\u5047\u76840\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">for i in range(__nrows):\r\n    for j in range(__ncols):\r\n        # copy style and value\r\n        if read_ws.cell(i, j).value:\r\n            write_ws.write(i, j + size, read_ws.cell(i, j).value, style=__generate_style(i, j))\r\n        elif isinstance(read_ws.cell(i, j).value, float):\r\n            write_ws.write(i, j + size, read_ws.cell(i, j).value)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">?<strong>\u662f\u4e00\u79cd\u795e\u5947\u7684\u4e1c\u897f\uff0c\u6211\u4eec\u6bcf\u4e2a\u4eba\u90fd\u89c1\u8fc7\uff0c\u4f46\u662f\u5374\u53c8\u4e0d\u77e5\u9053\u5b83\u7684\u672c\u8d28\uff0c\u4e0d\u77e5\u9053\u5b83\u7a76\u7adf\u4e3a\u4f55\u3002<\/strong><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">?\u6709\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u67d0\u4e9b\u5355\u5143\u683c\uff0c\u5b83\u662f\u6709\u586b\u5145\u8272\u7684\uff0c\u4f46\u662f\u5185\u5bb9\u4e3a\u7a7a\u54e6\u3002\u90a3\u4f60\u8fd9\u2026\u2026\u4e0d\u5c31\u9519\u4e86\u5417\uff1f<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u89e3\u51b3\u65b9\u6848\u4e5f\u5f88\u7b80\u5355\uff0c\u518d\u6765\u4e2aelse\uff0c\u7ee7\u7eedcopy style\u4f46\u662f\u63d2\u5165\u7a7a\u503c\u5457\u2026\u2026\u54ce\uff1f\u6709\u6ca1\u6709\u4eba\u60f3\u95ee\u4e0bopenpyxl\u5c31\u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\u554a\uff0c\u600e\u4e48\u8fd9\u5c31\u51fa\u73b0\u4e86\u2026\u2026(*\/\u03c9\uff3c*)\u90a3\u4e2a\u4f60\u6700\u597d\u770b\u4e0bopenpyxl\u6211\u662f\u5728\u54ea\u91cc\u5e94\u7528\u7684\u6837\u5f0f\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4eba\u751f\u5728\u4e16\uff0c?\u603b\u662f\u6709\u7684\uff0c\u8bf4\u4e0d\u5b9a\u54ea\u4e00\u5929\u8d70\u5728\u9a6c\u8def\u4e0a\u5c31\u2026\u2026\u8fd9\u6837\u505a\u53ef\u80fd\u4f1a\u629b\u51faValueError\u7684\u5f02\u5e38\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u662f\u4e3a\u5565\u5462\uff1f\u5176\u5b9e\u6211\u4e5f\u4e0d\u77e5\u9053\u3002try\u4e00\u6ce2\u6355\u83b7\u4e86\u5c31\u597d\u4e86\u3002<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u90a3\u4e48\u5c01\u88c5\u6210\u4e00\u4e2a\u7c7b<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u8fd8\u7528\u8bf4\u561b\uff0c\u7b80\u5355\uff0c\u628aopenpyxl\u548cxlrd\u5bb6\u65cf\u7684\u5c01\u88c5\u5230\u7c7b\u91cc\uff0c<code>__init__()<\/code>\u63a5\u53d7\u4fe9\u53c2\u6570\uff0c\u4e5f\u5c31\u662f\u8f93\u5165\u548c\u8f93\u51fa\u6587\u4ef6\u540d\uff0c\u8be5\u7528\u53cc\u4e0b\u5212\u7ebf\u201c\u4fdd\u62a4\u201d\u7684\u6210\u5458\u53d8\u91cf\u5c31\u5199\u4e0a\uff0c\u8be5\u9759\u6001\u65b9\u6cd5\u5c31\u9759\u6001\u65b9\u6cd5\uff0c\u6700\u540e\u4fdd\u7559\u4e00\u4e2a<code>insert_col()<\/code>\u63a5\u53d7\u4e00\u4e2asize\u53c2\u6570\uff0c\u4e00\u4e2a<code>save()<\/code>\u4fdd\u5b58\u6587\u4ef6\u5c31\u5f97\u4e86\uff0c\u5b9e\u4f8b\u80fd\u8bbf\u95ee\u8bfb\u53d6\u548c\u5199\u5165\u7684workbook\u548cworksheet\u5c31\u8db3\u591f\u4e86\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u4e3a\u4ec0\u4e48\u8981\u6709save()\u5462\uff1f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u56e0\u4e3a\u7075\u6d3b\u554a\uff0c\u4e07\u4e00\u4eba\u5bb6\u60f3\u63d2\u4e86\u4e24\u5217\u7a7a\u767d\uff0c\u987a\u4fbf\u52a0\u70b9\u5b57\u5462\uff1f\u96be\u4e0d\u6210\u8981\u8ba9\u4eba\u518d\u6253\u5f00\u4e00\u904d\u6587\u4ef6\u554a\uff1f\u5f53\u7136\u4e0d\u4e86\uff0c\u76f4\u63a5\u5b9e\u4f8b\u8c03\u7528\u5199\u5165\u7684worksheet\u7684\u90a3\u4e2a\u53d8\u91cf\uff0c\u60f3\u600e\u4e48\u6765\u5c31\u600e\u4e48\u6765\u4e86\u3002<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u8fd9\u4e2a\u65b0\u7684\u5217\u7684\u8868\u5934\u4e5f\u5f97\u4f60\u52a0<\/span><\/h2>\n<h3><span style=\"font-size: 12pt;\">\u81ea\u5b9a\u4e49\u524d\u666f\u8272<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u6ca1\u5565\uff0c\u5f88\u7b80\u5355\uff0cxlwt\u548copenpyxl\u90fd\u5e26\uff0c\u81ea\u5df1\u770b\u4e0b\u6587\u6863\uff0c\u5f88\u5bb9\u6613\u5c31\u505a\u51fa\u6765\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e0d\u8fc7\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cxlwt\u7684\u8bbe\u8ba1\u6709\u4e00\u70b9\u79c0\u9017\uff0c\u8fd9\u4e2a\u63d2\u5165\u7684\u80cc\u666f\u8272\u7684\u8bdd\uff0c\u5982\u679c\u60f3\u81ea\u5b9a\u4e49\u7684\u8bdd\uff0c\u662f\u7528\u4e0d\u4e86\u5341\u516d\u8fdb\u5236\u7684\u989c\u8272\u503c\u7684\u2026\u2026\u90a3\u4e48\u81ea\u5b9a\u4e49\u989c\u8272\u503c\u5927\u6982\u662f\u2026\u2026<\/span><\/p>\n<pre class=\"prettyprint linenums\">pattern = xlwt.Pattern()\r\nxlwt.add_palette_colour(&quot;custom_color&quot;, 0x21)\r\nc.write_wb.set_colour_RGB(0x21, 0, 204, 255)\r\npattern.pattern = xlwt.Pattern.SOLID_PATTERN\r\npattern.pattern_fore_colour = 0x21\r\n<\/pre>\n<h3><span style=\"font-size: 12pt;\">\u8fd9\u4e2a\u65b0\u52a0\u7684\u8868\u5934\u4e5f\u8981\u5c01\u88c5<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u4e8e\u662f\u54b1\u5494\u5494\u5494\u7684\u8981\u7ed9\u8fd9\u4e2a\u7c7b\u518d\u52a0\u4e2a\u65b9\u6cd5\uff0c\u518d\u7ed9\u6784\u9020\u65b9\u6cd5\u6dfb\u52a0\u4e2a\u53c2\u6570\u5565\u7684\uff08\u56e0\u4e3a\u8981\u5904\u7406\u4e24\u4e2a\u4e0d\u540c\u7684\u8868\u5934\u6837\u5f0f\uff09<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u556a\u311f( \u2594, \u2594 )\u310f\u624b\u75bc\u30fd(*\u3002&gt;\u0414&lt;)o\u309c<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u96be\u9053\u4e0d\u77e5\u9053\u6709\u4e2a\u4e1c\u897f\u53eb\u505a\u7ee7\u627f\u5417\uff1f\u8fd9\u4e2a\u7c7b\u5df2\u7ecf\u5f88\u7eaf\u7cb9\u4e86\uff0c\u5c31\u662f\u7ed9Excel\u524d\u9762\u52a0\u4e24\u5217\uff0c\u8fd9\u4e48\u52a0\u4e2a\u4e0d\u76f8\u5e72\u7684\u65b9\u6cd5\u8fdb\u53bb\u90a3\u5c31\u662f<del>\u8001\u9f20\u5c4e\u91cc\u8fdb\u4e86\u7c73\u996d\u2026\u2026\u554a\u4e0d\u662f\u7c73\u996d\u91cc\u8fdb\u4e86\u8001\u9f20\u5c4e<\/del>\u3002\u7ee7\u627f\u4e0b\u66f4\u597d\u54df(\uff3e\uff35\uff3e)\u30ce~\uff39\uff2f<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u7ed3\u679c<\/span><\/h2>\n<p><a href=\"https:\/\/dmesg.app\/wp-content\/uploads\/2018\/09\/2018091913194557.png\" alt=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" title=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" rel=\"box\" class=\"fancybox\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"464\" class=\"alignnone size-full wp-image-3834\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/09\/2018091913194557.png\" alt=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" title=\"\u4f7f\u7528Python\u7ed9\u5e26\u5408\u5e76\u5355\u5143\u683c\u7684Excel\u52a0\u4e00\u5217\" alt=\"\" \/><\/a><\/p>\n<p><span style=\"font-size: 12pt;\">\u5b8c\u7f8e(o\u309c\u25bd\u309c)o\u2606<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5168\u90e8\u6e90\u4ee3\u7801\u4ee5\u53ca\u793a\u4f8b\u6587\u4ef6\u53ef\u4ee5\u6233\u4e0b\u9762\u7684\u7ae0\u9c7c\u732b\u54e6o(=\u2022\u30a7\u2022=)m<\/span><br \/>\n<a class=\"dl\" href=\"https:\/\/github.com\/BennyThink\/tools\/tree\/master\/xls\" target=\"_blank\" rel=\"nofollow\"><i class=\"fa fa-github-alt\"><\/i>\u5f00\u6e90\u5730\u5740<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u51e0\u5929\u6709\u8fd9\u4e48\u4e00\u4e2a\u9700\u6c42\uff0c\u8981\u7ed9Excel\u8868\u683c\u7684\u6700\u524d\u9762\u52a0\u5165\u4e24\u5217\u3002\u6211\u60f3\u8fd9\u4e0d\u662f\u975e\u5e38\u7b80\u5355\u5417\uff1f\u51e0\u884c\u4ee3\u7801\u800c\u5df2\uff1a import  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-3828","post","type-post","status-publish","format-standard","hentry","category-program"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts\/3828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/comments?post=3828"}],"version-history":[{"count":0,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts\/3828\/revisions"}],"wp:attachment":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/media?parent=3828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/categories?post=3828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/tags?post=3828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}