{"id":109180,"date":"2026-09-23T14:08:48","date_gmt":"2026-09-23T06:08:48","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/109180.html"},"modified":"2026-09-23T14:08:48","modified_gmt":"2026-09-23T06:08:48","slug":"%e5%b9%b2%e8%b4%a7%ef%bc%9aopenpyxl-%e5%af%b9%e8%b1%a1%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/109180.html","title":{"rendered":"\u5e72\u8d27\uff1aopenpyxl \u5bf9\u8c61\u6a21\u578b"},"content":{"rendered":"<h2>openpyxl \u5bf9\u8c61\u6a21\u578b&#xff1a;workbook \/ worksheet \/ cell<\/h2>\n<h3>\u5148\u5efa\u7acb\u4e09\u5c42<\/h3>\n<p>openpyxl \u5904\u7406 xlsx&#xff0c;\u5176\u5b9e\u548c\u5b83\u540d\u5b57\u4e00\u6837\u4e09\u5c42&#xff1a;<\/p>\n<p>Workbook                  <span class=\"token comment\"># \u6574\u672c\u5de5\u4f5c\u7c3f&#xff08;\u4e00\u4e2a .xlsx \u6587\u4ef6&#xff09;<\/span><br \/>\n  \u2514\u2500\u2500 Worksheet           <span class=\"token comment\"># \u4e00\u4e2a sheet \u8868<\/span><br \/>\n        \u2514\u2500\u2500 Cell          <span class=\"token comment\"># \u4e00\u4e2a\u5355\u5143\u683c &#061; \u5750\u6807(x, y) &#043; \u503c &#043; \u6837\u5f0f<\/span><\/p>\n<p>\u51e0\u4e4e\u6240\u6709\u64cd\u4f5c\u90fd\u662f&#034;\u6253\u5f00\u5de5\u4f5c\u7c3f \u2192 \u9009\u4e2d\u5de5\u4f5c\u8868 \u2192 \u5b9a\u4f4d\u5355\u5143\u683c\/\u884c\u5217 \u2192 \u8bfb\u5199&#034;\u3002<\/p>\n<h3>\u6253\u5f00\u65b9\u5f0f&#xff0c;\u4e24\u6761\u8def<\/h3>\n<p><span class=\"token keyword\">from<\/span> openpyxl <span class=\"token keyword\">import<\/span> load_workbook<\/p>\n<p><span class=\"token comment\"># \u8bfb\u6a21\u5f0f&#xff1a;\u53ea\u770b\u503c&#xff0c;\u5feb&#xff0c;\u9002\u5408\u53d6\u6570<\/span><br \/>\nwb <span class=\"token operator\">&#061;<\/span> load_workbook<span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">,<\/span> data_only<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u8bfb\u5199\u6a21\u5f0f&#xff1a;\u53ef\u5199&#xff0c;\u80fd\u4fdd\u5b58<\/span><br \/>\nwb <span class=\"token operator\">&#061;<\/span> load_workbook<span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u533a\u522b\u5728\u540e\u9762\u51e0\u7bc7\u4f1a\u7ec6\u8bb2&#xff08;data_only \u662f\u91cd\u707e\u533a&#xff09;\u3002<\/p>\n<h3>\u57fa\u672c\u8bfb\u5199<\/h3>\n<p>ws <span class=\"token operator\">&#061;<\/span> wb<span class=\"token punctuation\">.<\/span>active          <span class=\"token comment\"># \u9ed8\u8ba4\u7b2c\u4e00\u4e2asheet<\/span><br \/>\n<span class=\"token comment\"># \u6216\u6309\u540d\u5b57\u53d6<\/span><br \/>\nws <span class=\"token operator\">&#061;<\/span> wb<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;Sheet1&#034;<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p><span class=\"token comment\"># \u8bfb<\/span><br \/>\nval <span class=\"token operator\">&#061;<\/span> ws<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;A1&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>value<br \/>\n<span class=\"token comment\"># \u5199<\/span><br \/>\nws<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;A1&#034;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">123<\/span><br \/>\nws<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;B2&#034;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;january&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u904d\u5386<\/span><br \/>\n<span class=\"token keyword\">for<\/span> row <span class=\"token keyword\">in<\/span> ws<span class=\"token punctuation\">.<\/span>iter_rows<span class=\"token punctuation\">(<\/span>min_row<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> max_row<span class=\"token operator\">&#061;<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> max_col<span class=\"token operator\">&#061;<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> cell <span class=\"token keyword\">in<\/span> row<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>cell<span class=\"token punctuation\">.<\/span>coordinate<span class=\"token punctuation\">,<\/span> cell<span class=\"token punctuation\">.<\/span>value<span class=\"token punctuation\">)<\/span><\/p>\n<h3>\u6211\u4eec\u9879\u76ee\u91cc&#034;\u6309\u52a8\u6001\u5750\u6807\u5199&#034;\u7684\u573a\u666f<\/h3>\n<p>\u5199\u6807\u51c6\u8f93\u51fa\u65f6&#xff0c;\u8868\u5934\u4e24\u884c\u56fa\u5b9a&#xff0c;\u6570\u636e\u4ece\u7b2c 3 \u884c\u5f00\u59cb&#xff0c;\u9010\u683c\u586b&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> openpyxl <span class=\"token keyword\">import<\/span> Workbook<\/p>\n<p>wb <span class=\"token operator\">&#061;<\/span> Workbook<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\nws <span class=\"token operator\">&#061;<\/span> wb<span class=\"token punctuation\">.<\/span>active<br \/>\n<span class=\"token comment\"># \u7b2c\u4e00\u884c\u82f1\u6587\u8868\u5934&#xff0c;\u7b2c\u4e8c\u884c\u4e2d\u6587\u8868\u5934<\/span><br \/>\n<span class=\"token keyword\">for<\/span> col<span class=\"token punctuation\">,<\/span> head <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">enumerate<\/span><span class=\"token punctuation\">(<\/span>headers_en<span class=\"token punctuation\">,<\/span> start<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    ws<span class=\"token punctuation\">.<\/span>cell<span class=\"token punctuation\">(<\/span>row<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> column<span class=\"token operator\">&#061;<\/span>col<span class=\"token punctuation\">,<\/span> value<span class=\"token operator\">&#061;<\/span>head<span class=\"token punctuation\">)<\/span><br \/>\nwb<span class=\"token punctuation\">.<\/span>save<span class=\"token punctuation\">(<\/span>out_path<span class=\"token punctuation\">)<\/span><\/p>\n<p>ws.cell(row, column, value) \u662f&#034;\u5750\u6807\u5bfb\u5740&#034;\u6700\u7a33\u7684\u5199\u6cd5&#xff0c;\u6bd4 &#034;A1&#034; \u8fd9\u79cd\u5b57\u6bcd\u5750\u6807\u597d\u7528&#xff0c;\u56e0\u4e3a\u5217\u6570\u7528\u4e86\u53d8\u91cf\u3002<\/p>\n<h3>\u8bb0\u4f4f\u4e24\u6761<\/h3>\n<li>\u5bf9\u8c61\u6a21\u578b&#xff1a;Workbook \u2192 Worksheet \u2192 Cell&#xff0c;\u4e00\u5207\u7684\u5bb9\u5668\u3002<\/li>\n<li>\u5750\u6807\u5bfb\u5740&#xff1a;cell(row, column, value) \u6bd4 &#034;A1&#034; \u66f4\u6297\u5217\u6570\u53d8\u5316\u3002<\/li>\n<p>openpyxl \u7b49\u597d\u61c2&#xff0c;\u628a\u4e09\u5c42\u5bf9\u8c61\u548c\u5750\u6807\u5efa\u7acb\u8d77\u6765&#xff0c;\u8bfb\u5199\u90fd\u987a\u3002<\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>openpyxl \u5bf9\u8c61\u6a21\u578b&#xff1a;workbook \/ worksheet \/ cell<br \/>\n\u5148\u5efa\u7acb\u4e09\u5c42<br \/>\nopenpyxl \u5904\u7406 xlsx&#xff0c;\u5176\u5b9e\u548c\u5b83\u540d\u5b57\u4e00\u6837\u4e09\u5c42&#xff1a;<br \/>\nWorkbook                  # \u6574\u672c\u5de5\u4f5c\u7c3f&#xff08;\u4e00\u4e2a .xlsx \u6587\u4ef6&#xff09;\u2514\u2500\u2500 Worksheet           # \u4e00\u4e2a sheet \u8868\u2514\u2500\u2500 Cell          # \u4e00\u4e2a\u5355\u5143\u683c  \u5750\u6807(x, y)  \u503c  \u6837\u5f0f\u51e0\u4e4e\u6240\u6709<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[12453,81],"topic":[],"class_list":["post-109180","post","type-post","status-publish","format-standard","hentry","category-server","tag-openpyxl","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5e72\u8d27\uff1aopenpyxl \u5bf9\u8c61\u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\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.wsisp.com\/helps\/109180.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5e72\u8d27\uff1aopenpyxl \u5bf9\u8c61\u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"openpyxl \u5bf9\u8c61\u6a21\u578b&#xff1a;workbook \/ worksheet \/ cell \u5148\u5efa\u7acb\u4e09\u5c42 openpyxl \u5904\u7406 xlsx&#xff0c;\u5176\u5b9e\u548c\u5b83\u540d\u5b57\u4e00\u6837\u4e09\u5c42&#xff1a; Workbook         # \u6574\u672c\u5de5\u4f5c\u7c3f&#xff08;\u4e00\u4e2a .xlsx \u6587\u4ef6&#xff09;\u2514\u2500\u2500 Worksheet      # \u4e00\u4e2a sheet \u8868\u2514\u2500\u2500 Cell     # \u4e00\u4e2a\u5355\u5143\u683c \u5750\u6807(x, y) \u503c \u6837\u5f0f\u51e0\u4e4e\u6240\u6709\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/109180.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-23T06:08:48+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/109180.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/109180.html\",\"name\":\"\u5e72\u8d27\uff1aopenpyxl \u5bf9\u8c61\u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-23T06:08:48+00:00\",\"dateModified\":\"2026-09-23T06:08:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/109180.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/109180.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/109180.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5e72\u8d27\uff1aopenpyxl \u5bf9\u8c61\u6a21\u578b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5e72\u8d27\uff1aopenpyxl \u5bf9\u8c61\u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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.wsisp.com\/helps\/109180.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5e72\u8d27\uff1aopenpyxl \u5bf9\u8c61\u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"openpyxl \u5bf9\u8c61\u6a21\u578b&#xff1a;workbook \/ worksheet \/ cell \u5148\u5efa\u7acb\u4e09\u5c42 openpyxl \u5904\u7406 xlsx&#xff0c;\u5176\u5b9e\u548c\u5b83\u540d\u5b57\u4e00\u6837\u4e09\u5c42&#xff1a; Workbook         # \u6574\u672c\u5de5\u4f5c\u7c3f&#xff08;\u4e00\u4e2a .xlsx \u6587\u4ef6&#xff09;\u2514\u2500\u2500 Worksheet      # \u4e00\u4e2a sheet \u8868\u2514\u2500\u2500 Cell     # \u4e00\u4e2a\u5355\u5143\u683c \u5750\u6807(x, y) \u503c \u6837\u5f0f\u51e0\u4e4e\u6240\u6709","og_url":"https:\/\/www.wsisp.com\/helps\/109180.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-23T06:08:48+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/109180.html","url":"https:\/\/www.wsisp.com\/helps\/109180.html","name":"\u5e72\u8d27\uff1aopenpyxl \u5bf9\u8c61\u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-23T06:08:48+00:00","dateModified":"2026-09-23T06:08:48+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/109180.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/109180.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/109180.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5e72\u8d27\uff1aopenpyxl \u5bf9\u8c61\u6a21\u578b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/109180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=109180"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/109180\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=109180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=109180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=109180"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=109180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}