{"id":930981,"date":"2024-12-26T17:27:41","date_gmt":"2024-12-26T09:27:41","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/930981.html"},"modified":"2024-12-26T17:27:43","modified_gmt":"2024-12-26T09:27:43","slug":"python%e5%a6%82%e4%bd%95%e9%85%8d%e7%bd%aexlrd","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/930981.html","title":{"rendered":"python\u5982\u4f55\u914d\u7f6exlrd"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065454\/f34fc2a0-de39-4f75-b71c-ad0621187c23.webp\" alt=\"python\u5982\u4f55\u914d\u7f6exlrd\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u914d\u7f6exlrd\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5\u5e93\u3001\u5bfc\u5165\u5e93\u3001\u8bfb\u53d6Excel\u6587\u4ef6\u3001\u5904\u7406\u6570\u636e\u7b49\u6b65\u9aa4\u5b9e\u73b0\u3002\u5efa\u8bae\u4f7f\u7528pip\u5b89\u88c5xlrd\u5e93\u3001\u786e\u4fdd\u6587\u4ef6\u683c\u5f0f\u517c\u5bb9\u3001\u4f7f\u7528xlrd\u6253\u5f00\u6587\u4ef6\u3001\u7406\u89e3\u6570\u636e\u7ed3\u6784\u3002\u8fd9\u4e9b\u6b65\u9aa4\u5c06\u5e2e\u52a9\u4f60\u6709\u6548\u5904\u7406Excel\u6587\u4ef6\u3002<\/strong>\u4e3a\u4e86\u8be6\u7ec6\u63cf\u8ff0\u5176\u4e2d\u4e00\u4e2a\u6b65\u9aa4\uff0c\u91cd\u70b9\u662f\u786e\u4fdd\u6587\u4ef6\u683c\u5f0f\u517c\u5bb9\u3002\u56e0\u4e3axlrd\u53ea\u652f\u6301.xls\u683c\u5f0f\u7684Excel\u6587\u4ef6\uff0c\u800c\u4e0d\u652f\u6301.xlsx\u683c\u5f0f\u3002\u56e0\u6b64\uff0c\u5728\u5904\u7406.xlsx\u6587\u4ef6\u65f6\uff0c\u9700\u8981\u5c06\u5176\u8f6c\u6362\u4e3a.xls\u683c\u5f0f\uff0c\u6216\u8005\u9009\u62e9\u5176\u4ed6\u5e93\u5982openpyxl\u6765\u5904\u7406\u3002\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u5728Python\u4e2d\u914d\u7f6e\u548c\u4f7f\u7528xlrd\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5\u4e0e\u5bfc\u5165xlrd\u5e93<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4f7f\u7528xlrd\u5e93\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u8be5\u5e93\u5df2\u6b63\u786e\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5xlrd\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u6765\u5b89\u88c5xlrd\u5e93\u3002\u6253\u5f00\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install xlrd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4ecePython Package Index\uff08PyPI\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684xlrd\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165xlrd\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u5b89\u88c5\u5b8c\u6210\uff0c\u5c31\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165xlrd\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import xlrd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u786e\u4fdd\u5728\u4f7f\u7528\u8be5\u5e93\u4e4b\u524d\u6b63\u786e\u5bfc\u5165\uff0c\u4ee5\u4fbf\u80fd\u591f\u8c03\u7528\u5176\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u786e\u4fddExcel\u6587\u4ef6\u683c\u5f0f\u517c\u5bb9<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528xlrd\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u65f6\uff0c\u6587\u4ef6\u683c\u5f0f\u7684\u517c\u5bb9\u6027\u662f\u4e00\u4e2a\u5173\u952e\u95ee\u9898\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u652f\u6301\u7684\u6587\u4ef6\u683c\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>xlrd\u5e93\u4ec5\u652f\u6301.xls\u683c\u5f0f\u7684Excel\u6587\u4ef6\uff0c\u800c\u4e0d\u652f\u6301.xlsx\u683c\u5f0f\u3002\u8fd9\u662f\u56e0\u4e3axlrd\u5e93\u4e13\u95e8\u8bbe\u8ba1\u7528\u4e8e\u5904\u7406Excel 97-2003\u683c\u5f0f\u7684\u6587\u4ef6\uff08\u5373.xls\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8f6c\u6362\u6587\u4ef6\u683c\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684\u6587\u4ef6\u662f.xlsx\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528Microsoft Excel\u6216\u5176\u4ed6\u5de5\u5177\u5c06\u5176\u8f6c\u6362\u4e3a.xls\u683c\u5f0f\u3002\u6b64\u5916\uff0c\u4e5f\u53ef\u4ee5\u8003\u8651\u4f7f\u7528openpyxl\u5e93\u6765\u5904\u7406.xlsx\u6587\u4ef6\uff0c\u56e0\u4e3aopenpyxl\u652f\u6301\u66f4\u73b0\u4ee3\u7684Excel\u6587\u4ef6\u683c\u5f0f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528xlrd\u6253\u5f00Excel\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u6587\u4ef6\u683c\u5f0f\u51c6\u5907\u5c31\u7eea\uff0c\u53ef\u4ee5\u5f00\u59cb\u4f7f\u7528xlrd\u5e93\u6253\u5f00\u5e76\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\u7528xlrd\u5e93\u63d0\u4f9b\u7684<code>open_workbook<\/code>\u51fd\u6570\u6253\u5f00Excel\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">workbook = xlrd.open_workbook(&#39;example.xls&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u786e\u4fdd\u6587\u4ef6\u8def\u5f84\u6b63\u786e\uff0c\u5e76\u4e14\u6587\u4ef6\u5177\u6709\u8bfb\u53d6\u6743\u9650\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u83b7\u53d6\u5de5\u4f5c\u8868<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u6253\u5f00Excel\u6587\u4ef6\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u6216\u540d\u79f0\u83b7\u53d6\u5de5\u4f5c\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sheet = workbook.sheet_by_index(0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sheet = workbook.sheet_by_name(&#39;Sheet1&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5141\u8bb8\u4f60\u8bbf\u95ee\u5de5\u4f5c\u8868\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u8bfb\u53d6\u4e0e\u5904\u7406Excel\u6570\u636e<\/p>\n<\/p>\n<p><p>\u4f7f\u7528xlrd\u5e93\uff0c\u53ef\u4ee5\u8f7b\u677e\u8bfb\u53d6Excel\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u5e76\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8bfb\u53d6\u5355\u5143\u683c\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u884c\u548c\u5217\u7684\u7d22\u5f15\u8bfb\u53d6\u5355\u5143\u683c\u7684\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">cell_value = sheet.cell_value(rowx=0, colx=0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8fd4\u56de\u6307\u5b9a\u5355\u5143\u683c\u4e2d\u7684\u503c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u904d\u5386\u6574\u4e2a\u5de5\u4f5c\u8868<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u904d\u5386\u6574\u4e2a\u5de5\u4f5c\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for row_idx in range(sheet.nrows):<\/p>\n<p>    row = sheet.row(row_idx)<\/p>\n<p>    for cell in row:<\/p>\n<p>        print(cell.value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u9010\u884c\u8bfb\u53d6\u5e76\u6253\u5370\u5de5\u4f5c\u8868\u4e2d\u7684\u6240\u6709\u6570\u636e\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u7406\u89e3\u6570\u636e\u7ed3\u6784\u4e0e\u683c\u5f0f<\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406Excel\u6570\u636e\u65f6\uff0c\u7406\u89e3\u6570\u636e\u7684\u7ed3\u6784\u548c\u683c\u5f0f\u662f\u5173\u952e\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<\/p>\n<p><p>xlrd\u5e93\u8fd4\u56de\u7684\u6570\u636e\u53ef\u4ee5\u662f\u591a\u79cd\u7c7b\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u65e5\u671f\u7b49\u3002\u5728\u5904\u7406\u6570\u636e\u65f6\uff0c\u9700\u8981\u6839\u636e\u6570\u636e\u7c7b\u578b\u8fdb\u884c\u76f8\u5e94\u7684\u8f6c\u6362\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u65e5\u671f\u5904\u7406<\/strong><\/p>\n<\/p>\n<p><p>Excel\u4e2d\u7684\u65e5\u671f\u901a\u5e38\u4ee5\u6d6e\u70b9\u6570\u5b58\u50a8\uff0c\u56e0\u6b64\u9700\u8981\u4f7f\u7528xlrd\u63d0\u4f9b\u7684<code>xldate_as_tuple<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3aPython\u7684\u65e5\u671f\u683c\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">date_tuple = xlrd.xldate_as_tuple(cell_value, workbook.datemode)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u65e5\u671f\u7684\u5143\u7ec4\uff0c\u4fbf\u4e8e\u8fdb\u4e00\u6b65\u5904\u7406\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528xlrd\u5e93\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\uff0c\u9700\u8981\u53ca\u65f6\u89e3\u51b3\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5e93\u7248\u672c\u517c\u5bb9\u6027<\/strong><\/p>\n<\/p>\n<p><p>\u786e\u4fdd\u5b89\u88c5\u7684xlrd\u5e93\u7248\u672c\u4e0ePython\u7248\u672c\u517c\u5bb9\u3002\u53ef\u4ee5\u901a\u8fc7<code>pip show xlrd<\/code>\u547d\u4ee4\u67e5\u770b\u5df2\u5b89\u88c5\u7684xlrd\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6587\u4ef6\u6743\u9650\u95ee\u9898<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u5728\u6253\u5f00\u6587\u4ef6\u65f6\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u8bf7\u786e\u4fdd\u6587\u4ef6\u8def\u5f84\u6b63\u786e\uff0c\u5e76\u4e14\u5177\u6709\u8bfb\u53d6\u6743\u9650\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u683c\u5f0f\u9519\u8bef<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u6570\u636e\u683c\u5f0f\u4e0d\u6b63\u786e\uff0c\u53ef\u80fd\u5bfc\u81f4\u8bfb\u53d6\u9519\u8bef\u3002\u786e\u4fddExcel\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u683c\u5f0f\u7b26\u5408\u9884\u671f\uff0c\u5e76\u5728\u8bfb\u53d6\u65f6\u8fdb\u884c\u5fc5\u8981\u7684\u8f6c\u6362\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u6269\u5c55\u4e0e\u4f18\u5316<\/p>\n<\/p>\n<p><p>\u5728\u638c\u63e1\u57fa\u672c\u4f7f\u7528xlrd\u5e93\u7684\u6280\u80fd\u540e\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u6269\u5c55\u548c\u4f18\u5316\u6570\u636e\u5904\u7406\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7ed3\u5408\u5176\u4ed6\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u7ed3\u5408\u5176\u4ed6\u5e93\uff08\u5982pandas\uff09\u6765\u8fdb\u4e00\u6b65\u5904\u7406\u548c\u5206\u6790\u6570\u636e\u3002pandas\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u4e0exlrd\u7ed3\u5408\u4f7f\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>df = pd.read_excel(&#39;example.xls&#39;, engine=&#39;xlrd&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6279\u91cf\u5904\u7406\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u5904\u7406\u591a\u4e2aExcel\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u548c\u51fd\u6570\u6765\u6279\u91cf\u8bfb\u53d6\u548c\u5904\u7406\u6570\u636e\u3002\u8fd9\u5c06\u663e\u8457\u63d0\u9ad8\u6548\u7387\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u5904\u7406\u5927\u91cf\u6587\u4ef6\u65f6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u5316\u6027\u80fd<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u578bExcel\u6587\u4ef6\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f18\u5316\u4ee3\u7801\u6765\u63d0\u9ad8\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5faa\u73af\u548c\u8ba1\u7b97\uff0c\u6216\u8005\u4f7f\u7528\u66f4\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0cPython\u4e2d\u914d\u7f6e\u548c\u4f7f\u7528xlrd\u5e93\u6d89\u53ca\u591a\u4e2a\u6b65\u9aa4\uff0c\u5305\u62ec\u5b89\u88c5\u5e93\u3001\u786e\u4fdd\u6587\u4ef6\u683c\u5f0f\u517c\u5bb9\u3001\u4f7f\u7528\u5e93\u6253\u5f00\u6587\u4ef6\u3001\u8bfb\u53d6\u548c\u5904\u7406\u6570\u636e\u3002\u5728\u6574\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u6ce8\u610f\u6587\u4ef6\u683c\u5f0f\u7684\u517c\u5bb9\u6027\u548c\u6570\u636e\u7c7b\u578b\u7684\u5904\u7406\u3002\u5728\u638c\u63e1\u57fa\u672c\u6280\u80fd\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ed3\u5408\u5176\u4ed6\u5e93\u548c\u4f18\u5316\u4ee3\u7801\u6765\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387\u548c\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5xlrd\u5e93\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u5b89\u88c5xlrd\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u3002\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<code>pip install xlrd<\/code>\u3002\u786e\u4fdd\u60a8\u7684Python\u73af\u5883\u5df2\u6b63\u786e\u8bbe\u7f6e\uff0c\u5e76\u4e14pip\u5df2\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\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\u5efa\u8bae\u4f7f\u7528openpyxl\u6216pandas\u5e93\u8fdb\u884c\u5904\u7406\uff0c\u56e0\u4e3axlrd\u4ece\u7248\u672c2.0.0\u5f00\u59cb\u4e0d\u518d\u652f\u6301.xlsx\u6587\u4ef6\u683c\u5f0f\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528xlrd\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u4e2d\u7684\u6570\u636e\uff1f<\/strong><br \/>\u4f7f\u7528xlrd\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u5bfc\u5165xlrd\u5e93\uff0c\u4f7f\u7528<code>xlrd.open_workbook<\/code>\u51fd\u6570\u6253\u5f00Excel\u6587\u4ef6\u3002\u7136\u540e\uff0c\u4f7f\u7528<code>sheet_by_index<\/code>\u6216<code>sheet_by_name<\/code>\u65b9\u6cd5\u9009\u62e9\u5de5\u4f5c\u8868\uff0c\u6700\u540e\u901a\u8fc7<code>cell_value<\/code>\u65b9\u6cd5\u8bfb\u53d6\u5355\u5143\u683c\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">import xlrd\n\nworkbook = xlrd.open_workbook(&#39;example.xls&#39;)\nsheet = workbook.sheet_by_index(0)\ndata = sheet.cell_value(0, 0)  # \u8bfb\u53d6\u7b2c\u4e00\u884c\u7b2c\u4e00\u5217\u6570\u636e\nprint(data)\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u5904\u7406xlrd\u5e93\u4e2d\u7684\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u5728\u4f7f\u7528xlrd\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u8fd4\u56de\u7684\u6570\u636e\u7c7b\u578b\u53d6\u51b3\u4e8e\u5355\u5143\u683c\u7684\u5185\u5bb9\u3002\u53ef\u4ee5\u901a\u8fc7<code>xlrd.XL_CELL_TYPE<\/code>\u6765\u5224\u65ad\u5355\u5143\u683c\u7684\u7c7b\u578b\uff0c\u5982\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u3001\u65e5\u671f\u7b49\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">cell_type = sheet.cell_type(row, col)\nif cell_type == xlrd.XL_CELL_NUMBER:\n    # \u5904\u7406\u6570\u5b57\u7c7b\u578b\nelif cell_type == xlrd.XL_CELL_TEXT:\n    # \u5904\u7406\u6587\u672c\u7c7b\u578b\n<\/code><\/pre>\n<p>\u4e86\u89e3\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u5904\u7406\u548c\u5206\u6790Excel\u4e2d\u7684\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u914d\u7f6exlrd\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5\u5e93\u3001\u5bfc\u5165\u5e93\u3001\u8bfb\u53d6Excel\u6587\u4ef6\u3001\u5904\u7406\u6570\u636e\u7b49\u6b65\u9aa4\u5b9e\u73b0\u3002\u5efa\u8bae\u4f7f\u7528pi [&hellip;]","protected":false},"author":3,"featured_media":930987,"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\/930981"}],"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=930981"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930981\/revisions"}],"predecessor-version":[{"id":930988,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930981\/revisions\/930988"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/930987"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=930981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=930981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=930981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}