{"id":1001444,"date":"2024-12-27T10:00:16","date_gmt":"2024-12-27T02:00:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1001444.html"},"modified":"2024-12-27T10:00:21","modified_gmt":"2024-12-27T02:00:21","slug":"%e5%a6%82%e4%bd%95python%e5%ae%89%e8%a3%85xlrd%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1001444.html","title":{"rendered":"\u5982\u4f55python\u5b89\u88c5xlrd\u6a21\u5757"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25075628\/51694443-ca43-4e4c-bbe6-51b83870039c.webp\" alt=\"\u5982\u4f55python\u5b89\u88c5xlrd\u6a21\u5757\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u5b89\u88c5xlrd\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u3001\u786e\u4fddPython\u548cpip\u7248\u672c\u517c\u5bb9\u3001\u4e86\u89e3xlrd\u7684\u529f\u80fd\u548c\u7528\u9014<\/strong>\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/p>\n<\/p>\n<p><p>\u8981\u5728Python\u4e2d\u5b89\u88c5xlrd\u6a21\u5757\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\uff0c\u8fd9\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3002\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u7684\u8ba1\u7b97\u673a\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cpip\u3002\u6253\u5f00\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5xlrd\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install xlrd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u547d\u4ee4\u5c06\u4ecePython\u7684\u5b98\u65b9\u5305\u7d22\u5f15\uff08PyPI\uff09\u4e2d\u4e0b\u8f7d\u5e76\u5b89\u88c5xlrd\u6a21\u5757\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u901a\u8fc7<code>import xlrd<\/code>\u6765\u4f7f\u7528\u8be5\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528PIP\u5b89\u88c5xlrd<\/h3>\n<\/p>\n<p><p>PIP\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002\u5b89\u88c5xlrd\u6a21\u5757\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528pip\u547d\u4ee4\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5Python\u548cPIP\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5b89\u88c5xlrd\u4e4b\u524d\uff0c\u786e\u4fdd\u60a8\u7684Python\u548cPIP\u7248\u672c\u4e0exlrd\u517c\u5bb9\u3002\u901a\u5e38\uff0cPython 2.7\u62163.x\u7248\u672c\u90fd\u652f\u6301xlrd\u3002\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python --version<\/p>\n<p>pip --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5xlrd<\/strong><\/p>\n<\/p>\n<p><p>\u6253\u5f00\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5xlrd\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install xlrd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u547d\u4ee4\u4f1a\u81ea\u52a8\u4ecePython\u5b98\u65b9\u5305\u7d22\u5f15\u4e0b\u8f7d\u5e76\u5b89\u88c5xlrd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728Python\u4ea4\u4e92\u73af\u5883\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u9a8c\u8bc1xlrd\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import xlrd<\/p>\n<p>print(xlrd.__version__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u663e\u793a\u5df2\u5b89\u88c5\u7684xlrd\u6a21\u5757\u7684\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u786e\u4fddPython\u548cPIP\u7248\u672c\u517c\u5bb9<\/h3>\n<\/p>\n<p><p>\u5728\u5b89\u88c5\u4efb\u4f55Python\u5305\u4e4b\u524d\uff0c\u786e\u4fdd\u60a8\u7684Python\u548cPIP\u7248\u672c\u4e0e\u5305\u517c\u5bb9\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Python\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>xlrd\u6a21\u5757\u901a\u5e38\u652f\u6301Python 2.7\u548cPython 3.x\u7248\u672c\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u8f83\u65e7\u7684Python\u7248\u672c\uff0c\u5efa\u8bae\u5347\u7ea7\u5230\u6700\u65b0\u7684Python 3\u7248\u672c\uff0c\u4ee5\u786e\u4fdd\u517c\u5bb9\u6027\u548c\u5b89\u5168\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>PIP\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>PIP\u7684\u7248\u672c\u4e5f\u53ef\u80fd\u5f71\u54cd\u5305\u7684\u5b89\u88c5\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5347\u7ea7PIP\u5230\u6700\u65b0\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m pip install --upgrade pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u786e\u4fdd\u60a8\u80fd\u591f\u987a\u5229\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u4e86\u89e3xlrd\u7684\u529f\u80fd\u548c\u7528\u9014<\/h3>\n<\/p>\n<p><p>\u5728\u5b89\u88c5xlrd\u6a21\u5757\u540e\uff0c\u4e86\u89e3\u5176\u529f\u80fd\u548c\u7528\u9014\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u4f7f\u7528\u5b83\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8bfb\u53d6Excel\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>xlrd\u6a21\u5757\u4e13\u4e3a\u8bfb\u53d6Excel\u6587\u4ef6\u800c\u8bbe\u8ba1\uff0c\u652f\u6301xls\u548cxlsx\u683c\u5f0f\u3002\u5b83\u5141\u8bb8\u60a8\u4eceExcel\u6587\u4ef6\u4e2d\u63d0\u53d6\u6570\u636e\uff0c\u5e76\u5728Python\u4e2d\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u652f\u6301\u591a\u79cd\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<\/p>\n<p><p>xlrd\u652f\u6301\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u65e5\u671f\u7b49\u3002\u5b83\u80fd\u591f\u6b63\u786e\u8bc6\u522b\u548c\u5904\u7406Excel\u6587\u4ef6\u4e2d\u7684\u5404\u79cd\u6570\u636e\u683c\u5f0f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8de8\u5e73\u53f0\u652f\u6301<\/strong><\/p>\n<\/p>\n<p><p>xlrd\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684Python\u5e93\uff0c\u53ef\u5728Windows\u3001macOS\u548cLinux\u7cfb\u7edf\u4e0a\u4f7f\u7528\u3002\u5b83\u4e0d\u4f9d\u8d56\u4e8e\u4efb\u4f55\u7279\u5b9a\u7684\u64cd\u4f5c\u7cfb\u7edf\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4f7f\u7528xlrd\u8bfb\u53d6Excel\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5b89\u88c5\u5e76\u9a8c\u8bc1xlrd\u6a21\u5757\u540e\uff0c\u60a8\u53ef\u4ee5\u5f00\u59cb\u4f7f\u7528\u5b83\u6765\u8bfb\u53d6Excel\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00Excel\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>xlrd.open_workbook()<\/code>\u51fd\u6570\u6253\u5f00Excel\u6587\u4ef6\u3002\u6b64\u51fd\u6570\u8fd4\u56de\u4e00\u4e2aWorkbook\u5bf9\u8c61\uff0c\u8868\u793aExcel\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import xlrd<\/p>\n<p>workbook = xlrd.open_workbook(&#39;example.xls&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbf\u95ee\u5de5\u4f5c\u8868<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Workbook\u5bf9\u8c61\u7684<code>sheet_by_index()<\/code>\u6216<code>sheet_by_name()<\/code>\u65b9\u6cd5\u8bbf\u95ee\u7279\u5b9a\u5de5\u4f5c\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sheet = workbook.sheet_by_index(0)  # \u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u7b2c\u4e00\u4e2a\u5de5\u4f5c\u8868<\/p>\n<h2><strong>\u6216\u8005<\/strong><\/h2>\n<p>sheet = workbook.sheet_by_name(&#39;Sheet1&#39;)  # \u901a\u8fc7\u540d\u79f0\u8bbf\u95ee\u5de5\u4f5c\u8868<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bfb\u53d6\u5355\u5143\u683c\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Sheet\u5bf9\u8c61\u7684<code>cell_value()<\/code>\u65b9\u6cd5\u8bfb\u53d6\u7279\u5b9a\u5355\u5143\u683c\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">cell_value = sheet.cell_value(0, 0)  # \u8bfb\u53d6\u7b2c\u4e00\u884c\u7b2c\u4e00\u5217\u7684\u5355\u5143\u683c<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001xlrd\u7684\u6ce8\u610f\u4e8b\u9879\u548c\u9650\u5236<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528xlrd\u6a21\u5757\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4e00\u4e9b\u9650\u5236\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u53ea\u8bfb\u6a21\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>xlrd\u6a21\u5757\u4ec5\u652f\u6301\u8bfb\u53d6Excel\u6587\u4ef6\uff0c\u800c\u4e0d\u652f\u6301\u5199\u5165\u6216\u4fee\u6539\u3002\u8981\u5199\u5165Excel\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u5e93\u5982xlwt\u6216openpyxl\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4e0d\u652f\u6301\u8f83\u65b0\u7248\u672c\u7684Excel\u683c\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>xlrd\u5bf9\u8f83\u65b0\u7684Excel\u683c\u5f0f\uff08\u5982.xlsx\uff09\u7684\u652f\u6301\u6709\u9650\uff0c\u4e3b\u8981\u7528\u4e8e\u8bfb\u53d6\u65e7\u7248Excel\u683c\u5f0f\uff08.xls\uff09\u3002\u5bf9\u4e8e.xlsx\u6587\u4ef6\uff0c\u5efa\u8bae\u4f7f\u7528openpyxl\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u7c7b\u578b\u5904\u7406<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u8bfb\u53d6Excel\u6587\u4ef6\u65f6\uff0c\u786e\u4fdd\u6b63\u786e\u5904\u7406\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4f8b\u5982\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u548c\u65e5\u671f\u3002xlrd\u4f1a\u81ea\u52a8\u8bc6\u522b\u6570\u636e\u7c7b\u578b\uff0c\u4f46\u5728\u4f7f\u7528\u65f6\u4ecd\u9700\u6ce8\u610f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u6210\u529f\u5b89\u88c5\u548c\u4f7f\u7528xlrd\u6a21\u5757\u6765\u8bfb\u53d6Excel\u6587\u4ef6\uff0c\u5e76\u5728Python\u4e2d\u5904\u7406\u6570\u636e\u3002\u786e\u4fdd\u60a8\u7684Python\u548cPIP\u7248\u672c\u517c\u5bb9\uff0c\u5e76\u4e86\u89e3xlrd\u7684\u529f\u80fd\u548c\u9650\u5236\uff0c\u4ee5\u5145\u5206\u5229\u7528\u5176\u4f18\u52bf\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5xlrd\u6a21\u5757\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u5b89\u88c5xlrd\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u5de5\u5177\u3002\u6253\u5f00\u547d\u4ee4\u884c\u754c\u9762\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<code>pip install xlrd<\/code>\u3002\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u5df2\u6b63\u786e\u914d\u7f6e\uff0cpip\u5de5\u5177\u4e5f\u5df2\u5b89\u88c5\u3002\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fPython 3\uff0c\u786e\u4fdd\u4f7f\u7528<code>pip3 install xlrd<\/code>\u3002<\/p>\n<p><strong>xlrd\u6a21\u5757\u652f\u6301\u54ea\u4e9bExcel\u6587\u4ef6\u683c\u5f0f\uff1f<\/strong><br \/>xlrd\u6a21\u5757\u4e3b\u8981\u652f\u6301\u8bfb\u53d6.xls\u548c.xlsx\u683c\u5f0f\u7684Excel\u6587\u4ef6\u3002\u7136\u800c\uff0c\u4ece\u7248\u672c2.0.0\u5f00\u59cb\uff0cxlrd\u53ea\u652f\u6301.xls\u683c\u5f0f\u3002\u5982\u679c\u4f60\u9700\u8981\u8bfb\u53d6.xlsx\u6587\u4ef6\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5176\u4ed6\u5e93\uff0c\u5982openpyxl\u6216pandas\u3002<\/p>\n<p><strong>\u5982\u4f55\u9a8c\u8bc1xlrd\u6a21\u5757\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1f<\/strong><br \/>\u53ef\u4ee5\u5728Python\u4ea4\u4e92\u5f0f\u73af\u5883\u6216\u811a\u672c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<code>import xlrd<\/code>\u3002\u5982\u679c\u6ca1\u6709\u9519\u8bef\u4fe1\u606f\uff0c\u5219\u8868\u793axlrd\u6a21\u5757\u5df2\u6210\u529f\u5b89\u88c5\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>pip show xlrd<\/code>\u547d\u4ee4\u53ef\u4ee5\u67e5\u770bxlrd\u7684\u7248\u672c\u548c\u5176\u4ed6\u76f8\u5173\u4fe1\u606f\uff0c\u8fdb\u4e00\u6b65\u786e\u8ba4\u5b89\u88c5\u60c5\u51b5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u5b89\u88c5xlrd\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u3001\u786e\u4fddPython\u548cpip\u7248\u672c\u517c\u5bb9\u3001\u4e86\u89e3xlrd\u7684\u529f\u80fd\u548c [&hellip;]","protected":false},"author":3,"featured_media":1001455,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001444"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1001444"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001444\/revisions"}],"predecessor-version":[{"id":1001458,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001444\/revisions\/1001458"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1001455"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1001444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1001444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1001444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}