{"id":974539,"date":"2024-12-27T06:06:00","date_gmt":"2024-12-26T22:06:00","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/974539.html"},"modified":"2024-12-27T06:06:02","modified_gmt":"2024-12-26T22:06:02","slug":"%e5%a6%82%e4%bd%95%e5%af%bc%e5%85%a5python%e7%9a%84xlrd","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/974539.html","title":{"rendered":"\u5982\u4f55\u5bfc\u5165python\u7684xlrd"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24200208\/dc5ace93-0af1-4cf7-a963-a9f96d0aa3fd.webp\" alt=\"\u5982\u4f55\u5bfc\u5165python\u7684xlrd\" \/><\/p>\n<p><p> \u5bfc\u5165Python\u7684<code>xlrd<\/code>\u5e93\u662f\u4e3a\u4e86\u5904\u7406Excel\u6587\u4ef6\uff0c\u7279\u522b\u662f\u8bfb\u53d6Excel\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u3002<strong>\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u5df2\u5b89\u88c5<code>xlrd<\/code>\u5e93\uff0c\u5e76\u901a\u8fc7<code>import xlrd<\/code>\u5bfc\u5165\u5e93\u3002\u5728\u5b89\u88c5\u65f6\uff0c\u4f7f\u7528\u547d\u4ee4<code>pip install xlrd<\/code><\/strong>\u3002\u63a5\u4e0b\u6765\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>xlrd.open_workbook<\/code>\u51fd\u6570\u6253\u5f00Excel\u6587\u4ef6\uff0c\u5e76\u901a\u8fc7<code>sheet_by_index<\/code>\u6216<code>sheet_by_name<\/code>\u65b9\u6cd5\u8bbf\u95ee\u5de5\u4f5c\u8868\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528<code>xlrd<\/code>\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u7684\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5\u4e0e\u5bfc\u5165xlrd<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528<code>xlrd<\/code>\u5e93\u4e4b\u524d\uff0c\u5fc5\u987b\u786e\u4fdd\u5728\u60a8\u7684Python\u73af\u5883\u4e2d\u5b89\u88c5\u4e86\u8be5\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install xlrd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u8be5\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import xlrd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5bfc\u5165\u5e93\u540e\uff0c\u60a8\u53ef\u4ee5\u5f00\u59cb\u5904\u7406Excel\u6587\u4ef6\u3002<\/strong>\u9996\u5148\uff0c\u901a\u8fc7<code>xlrd.open_workbook<\/code>\u51fd\u6570\u6253\u5f00\u6587\u4ef6\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a<code>Workbook<\/code>\u5bf9\u8c61\u3002\u7136\u540e\uff0c\u4f7f\u7528\u8be5\u5bf9\u8c61\u7684\u65b9\u6cd5\u8bbf\u95ee\u5de5\u4f5c\u8868\u548c\u5355\u5143\u683c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u6253\u5f00Excel\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u6253\u5f00Excel\u6587\u4ef6\u662f\u4f7f\u7528<code>xlrd<\/code>\u5e93\u7684\u7b2c\u4e00\u6b65\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528open_workbook\u51fd\u6570\uff1a<\/strong><\/p>\n<\/p>\n<p><p><code>open_workbook<\/code>\u51fd\u6570\u7528\u4e8e\u6253\u5f00Excel\u6587\u4ef6\u3002\u5047\u8bbe\u60a8\u7684Excel\u6587\u4ef6\u540d\u4e3a<code>example.xlsx<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6253\u5f00\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">workbook = xlrd.open_workbook(&#39;example.xlsx&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8bf7\u6ce8\u610f\uff0c<code>xlrd<\/code>\u5e93\u53ea\u652f\u6301.xls\u683c\u5f0f\u7684Excel\u6587\u4ef6\u3002\u5bf9\u4e8e.xlsx\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>openpyxl<\/code>\u5e93\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u83b7\u53d6\u5de5\u4f5c\u8868\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u6253\u5f00\u6587\u4ef6\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u6216\u540d\u79f0\u83b7\u53d6\u5de5\u4f5c\u8868\u3002\u4f7f\u7528<code>sheet_by_index<\/code>\u6216<code>sheet_by_name<\/code>\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sheet = workbook.sheet_by_index(0)  # \u901a\u8fc7\u7d22\u5f15\u83b7\u53d6\u7b2c\u4e00\u4e2a\u5de5\u4f5c\u8868<\/p>\n<h2><strong>\u6216<\/strong><\/h2>\n<p>sheet = workbook.sheet_by_name(&#39;Sheet1&#39;)  # \u901a\u8fc7\u540d\u79f0\u83b7\u53d6\u5de5\u4f5c\u8868<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u9009\u62e9\u9002\u5408\u60a8\u7684\u65b9\u5f0f\u6765\u83b7\u53d6\u5de5\u4f5c\u8868\u3002<\/strong>\u5982\u679c\u5de5\u4f5c\u8868\u540d\u79f0\u5df2\u77e5\uff0c\u4f7f\u7528<code>sheet_by_name<\/code>\u66f4\u65b9\u4fbf\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u8bfb\u53d6\u5de5\u4f5c\u8868\u6570\u636e<\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u83b7\u53d6\u5230\u5de5\u4f5c\u8868\uff0c\u53ef\u4ee5\u5f00\u59cb\u8bfb\u53d6\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u83b7\u53d6\u884c\u6570\u548c\u5217\u6570\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>nrows<\/code>\u548c<code>ncols<\/code>\u5c5e\u6027\u83b7\u53d6\u5de5\u4f5c\u8868\u7684\u884c\u6570\u548c\u5217\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_rows = sheet.nrows<\/p>\n<p>num_cols = sheet.ncols<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8fd9\u4e9b\u5c5e\u6027\u975e\u5e38\u6709\u7528\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u904d\u5386\u6574\u4e2a\u5de5\u4f5c\u8868\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bfb\u53d6\u5355\u5143\u683c\u6570\u636e\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>cell_value<\/code>\u65b9\u6cd5\u8bfb\u53d6\u7279\u5b9a\u5355\u5143\u683c\u7684\u6570\u636e\u3002<code>cell_value<\/code>\u65b9\u6cd5\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff1a\u884c\u7d22\u5f15\u548c\u5217\u7d22\u5f15\uff08\u4ece0\u5f00\u59cb\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">cell_data = sheet.cell_value(0, 0)  # \u8bfb\u53d6\u7b2c\u4e00\u884c\u7b2c\u4e00\u5217\u7684\u6570\u636e<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u901a\u8fc7\u5d4c\u5957\u5faa\u73af\uff0c\u53ef\u4ee5\u904d\u5386\u6574\u4e2a\u5de5\u4f5c\u8868\u7684\u6570\u636e\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for row in range(num_rows):<\/p>\n<p>    for col in range(num_cols):<\/p>\n<p>        cell_value = sheet.cell_value(row, col)<\/p>\n<p>        print(cell_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5904\u7406\u65e5\u671f\u548c\u5176\u4ed6\u6570\u636e\u7c7b\u578b<\/p>\n<\/p>\n<p><p>\u5728Excel\u6587\u4ef6\u4e2d\uff0c\u6570\u636e\u53ef\u80fd\u4ee5\u4e0d\u540c\u7684\u683c\u5f0f\u5b58\u50a8\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5904\u7406\u5e38\u89c1\u6570\u636e\u7c7b\u578b\u7684\u6280\u5de7\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5904\u7406\u65e5\u671f\uff1a<\/strong><\/p>\n<\/p>\n<p><p><code>xlrd<\/code>\u5e93\u5c06\u65e5\u671f\u5b58\u50a8\u4e3a\u6d6e\u70b9\u6570\u3002\u53ef\u4ee5\u4f7f\u7528<code>xlrd.xldate_as_tuple<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3aPython\u7684\u65e5\u671f\u65f6\u95f4\u683c\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import datetime<\/p>\n<h2><strong>\u5047\u8bbe\u5355\u5143\u683c\u4e2d\u5b58\u50a8\u7684\u662f\u65e5\u671f<\/strong><\/h2>\n<p>date_value = sheet.cell_value(1, 0)<\/p>\n<p>date_tuple = xlrd.xldate_as_tuple(date_value, workbook.datemode)<\/p>\n<p>date = datetime.datetime(*date_tuple)<\/p>\n<p>print(date)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8fd9\u79cd\u8f6c\u6362\u5bf9\u4e8e\u5904\u7406\u65e5\u671f\u6570\u636e\u975e\u5e38\u6709\u7528\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bc6\u522b\u6570\u636e\u7c7b\u578b\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>cell_type<\/code>\u65b9\u6cd5\u53ef\u4ee5\u8bc6\u522b\u5355\u5143\u683c\u7684\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">cell_type = sheet.cell_type(0, 0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6839\u636e\u8fd4\u56de\u7684\u7c7b\u578b\uff0c\u60a8\u53ef\u4ee5\u91c7\u53d6\u4e0d\u540c\u7684\u5904\u7406\u65b9\u5f0f\u3002\u4f8b\u5982\uff0c\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u6216\u5e03\u5c14\u503c\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5904\u7406\u5927\u6587\u4ef6\u548c\u6027\u80fd\u4f18\u5316<\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u578bExcel\u6587\u4ef6\u65f6\uff0c\u6027\u80fd\u53ef\u80fd\u6210\u4e3a\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f18\u5316\u6280\u5de7\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9010\u884c\u8bfb\u53d6\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u6587\u4ef6\u975e\u5e38\u5927\uff0c\u53ef\u4ee5\u9010\u884c\u8bfb\u53d6\u6570\u636e\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u6027\u8bfb\u53d6\u6240\u6709\u6570\u636e\u3002\u8fd9\u6837\u53ef\u4ee5\u8282\u7701\u5185\u5b58\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for row in range(num_rows):<\/p>\n<p>    row_data = sheet.row_values(row)<\/p>\n<p>    print(row_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u9700\u8981\u9010\u884c\u5904\u7406\u6570\u636e\u7684\u60c5\u51b5\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9650\u5236\u8bfb\u53d6\u8303\u56f4\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u53ea\u9700\u8981\u5904\u7406\u7279\u5b9a\u8303\u56f4\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u9650\u5236\u8bfb\u53d6\u8303\u56f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for row in range(10, 20):  # \u53ea\u8bfb\u53d6\u7b2c10\u523020\u884c<\/p>\n<p>    for col in range(5):  # \u53ea\u8bfb\u53d6\u524d5\u5217<\/p>\n<p>        cell_value = sheet.cell_value(row, col)<\/p>\n<p>        print(cell_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u9650\u5236\u8303\u56f4\u6709\u52a9\u4e8e\u63d0\u9ad8\u6548\u7387\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u9519\u8bef\u5904\u7406\u548c\u8c03\u8bd5<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528<code>xlrd<\/code>\u5e93\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u9519\u8bef\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u53ca\u5176\u5904\u7406\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6587\u4ef6\u4e0d\u5b58\u5728\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u6587\u4ef6\u8def\u5f84\u9519\u8bef\u6216\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u4f1a\u5f15\u53d1<code>FileNotFoundError<\/code>\u3002\u786e\u4fdd\u8def\u5f84\u6b63\u786e\uff0c\u6216\u4f7f\u7528<code>try-except<\/code>\u8fdb\u884c\u9519\u8bef\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    workbook = xlrd.open_workbook(&#39;example.xlsx&#39;)<\/p>\n<p>except FileNotFoundError:<\/p>\n<p>    print(&quot;\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u8bf7\u68c0\u67e5\u8def\u5f84\u3002&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8fd9\u79cd\u65b9\u6cd5\u6709\u52a9\u4e8e\u9632\u6b62\u7a0b\u5e8f\u5d29\u6e83\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5de5\u4f5c\u8868\u4e0d\u5b58\u5728\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u901a\u8fc7\u540d\u79f0\u83b7\u53d6\u5de5\u4f5c\u8868\uff0c\u4f46\u540d\u79f0\u4e0d\u6b63\u786e\uff0c\u4f1a\u5f15\u53d1<code>XLRDError<\/code>\u3002\u540c\u6837\uff0c\u53ef\u4ee5\u4f7f\u7528<code>try-except<\/code>\u8fdb\u884c\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    sheet = workbook.sheet_by_name(&#39;Sheet1&#39;)<\/p>\n<p>except xlrd.biffh.XLRDError:<\/p>\n<p>    print(&quot;\u5de5\u4f5c\u8868\u4e0d\u5b58\u5728\uff0c\u8bf7\u68c0\u67e5\u540d\u79f0\u3002&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u786e\u4fdd\u5de5\u4f5c\u8868\u540d\u79f0\u6b63\u786e\uff0c\u6216\u4f7f\u7528\u7d22\u5f15\u83b7\u53d6\u5de5\u4f5c\u8868\u4ee5\u907f\u514d\u6b64\u9519\u8bef\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u66ff\u4ee3\u65b9\u6848\u4e0e\u6269\u5c55\u529f\u80fd<\/p>\n<\/p>\n<p><p>\u968f\u7740Excel\u6587\u4ef6\u683c\u5f0f\u7684\u6f14\u53d8\uff0c<code>xlrd<\/code>\u5e93\u7684\u529f\u80fd\u53ef\u80fd\u4f1a\u53d7\u5230\u9650\u5236\u3002\u4f8b\u5982\uff0c<code>xlrd<\/code>\u4e0d\u518d\u652f\u6301<code>.xlsx<\/code>\u6587\u4ef6\u683c\u5f0f\u7684\u8bfb\u53d6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u66ff\u4ee3\u65b9\u6848\u548c\u6269\u5c55\u529f\u80fd\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528openpyxl\u5e93\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u8bfb\u53d6\u6216\u5199\u5165<code>.xlsx<\/code>\u683c\u5f0f\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>openpyxl<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from openpyxl import load_workbook<\/p>\n<p>workbook = load_workbook(&#39;example.xlsx&#39;)<\/p>\n<p>sheet = workbook.active<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong><code>openpyxl<\/code>\u652f\u6301\u66f4\u591a\u7684Excel\u529f\u80fd\uff0c\u4f8b\u5982\u5199\u5165\u548c\u683c\u5f0f\u5316\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528pandas\u5e93\uff1a<\/strong><\/p>\n<\/p>\n<p><p><code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86\u66f4\u9ad8\u5c42\u6b21\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u8f7b\u677e\u8bfb\u53d6\u548c\u5904\u7406Excel\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>df = pd.read_excel(&#39;example.xlsx&#39;, sheet_name=&#39;Sheet1&#39;)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u9700\u8981\u6570\u636e\u5206\u6790\u548c\u6570\u636e\u64cd\u4f5c\u7684\u573a\u666f\u3002<\/strong><\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3\uff0c\u901a\u8fc7<code>xlrd<\/code>\u5e93\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u8bfb\u53d6Excel\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u3002\u7136\u800c\uff0c\u7531\u4e8e\u5176\u529f\u80fd\u9650\u5236\uff0c\u5bf9\u4e8e\u590d\u6742\u7684Excel\u64cd\u4f5c\uff0c\u5efa\u8bae\u7ed3\u5408\u5176\u4ed6\u5e93\uff08\u5982<code>openpyxl<\/code>\u6216<code>pandas<\/code>\uff09\u4e00\u8d77\u4f7f\u7528\u3002\u786e\u4fdd\u5728\u4f7f\u7528\u524d\u4e86\u89e3\u6bcf\u4e2a\u5e93\u7684\u529f\u80fd\u548c\u9650\u5236\uff0c\u4ee5\u4fbf\u9009\u62e9\u6700\u5408\u9002\u7684\u5de5\u5177\u6765\u5b8c\u6210\u4efb\u52a1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u6211\u7684Python\u73af\u5883\u4e2d\u5b89\u88c5xlrd\u5e93\uff1f<\/strong><br \/>\u8981\u5728Python\u73af\u5883\u4e2d\u5b89\u88c5xlrd\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pip install xlrd<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u5df2\u7ecf\u6b63\u786e\u914d\u7f6e\uff0c\u5e76\u4e14pip\u5df2\u7ecf\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\u5bfc\u5165xlrd\u5e93\u3002<\/p>\n<p><strong>xlrd\u5e93\u652f\u6301\u54ea\u4e9bExcel\u6587\u4ef6\u683c\u5f0f\uff1f<\/strong><br \/>xlrd\u5e93\u4e3b\u8981\u652f\u6301.xls\u683c\u5f0f\u7684Excel\u6587\u4ef6\u3002\u5bf9\u4e8e.xlsx\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u4f60\u9700\u8981\u4f7f\u7528\u5176\u4ed6\u5e93\uff0c\u5982openpyxl\u6216\u8005pandas\u3002\u786e\u4fdd\u5728\u5904\u7406Excel\u6587\u4ef6\u65f6\u9009\u62e9\u5408\u9002\u7684\u5e93\uff0c\u4ee5\u907f\u514d\u683c\u5f0f\u4e0d\u517c\u5bb9\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u4f7f\u7528xlrd\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u7684\u57fa\u672c\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u4f7f\u7528xlrd\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u7684\u57fa\u672c\u6b65\u9aa4\u5305\u62ec\uff1a\u9996\u5148\uff0c\u5bfc\u5165xlrd\u5e93\uff1b\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528<code>xlrd.open_workbook()<\/code>\u51fd\u6570\u6253\u5f00Excel\u6587\u4ef6\uff1b\u7136\u540e\uff0c\u901a\u8fc7<code>workbook.sheet_by_index()<\/code>\u6216<code>workbook.sheet_by_name()<\/code>\u83b7\u53d6\u5de5\u4f5c\u8868\uff1b\u6700\u540e\uff0c\u4f7f\u7528<code>sheet.cell_value(row, col)<\/code>\u65b9\u6cd5\u8bfb\u53d6\u5177\u4f53\u5355\u5143\u683c\u7684\u6570\u636e\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6Excel\u4e2d\u7684\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5bfc\u5165Python\u7684xlrd\u5e93\u662f\u4e3a\u4e86\u5904\u7406Excel\u6587\u4ef6\uff0c\u7279\u522b\u662f\u8bfb\u53d6Excel\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u3002\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u5df2\u5b89\u88c5xl [&hellip;]","protected":false},"author":3,"featured_media":974551,"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\/974539"}],"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=974539"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/974539\/revisions"}],"predecessor-version":[{"id":974553,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/974539\/revisions\/974553"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/974551"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=974539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=974539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=974539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}