<h2>发行</h2>
<h3>分析错误</h3>
<blockquote>
<p>line 4, in excel_workbook = xlrd.open_workbook(path)</p>
</blockquote>
<p>您的脚本无法打开工作簿</p>
<blockquote>
<p>AttributeError: 'Book' object has no attribute 'extract_formulas'</p>
</blockquote>
<p>属性错误声明,它没有将<code>extract_formulas</code>作为<a href="https://xlrd.readthedocs.io/en/latest/api.html#xlrd.book.Book" rel="nofollow noreferrer">xlrd's ^{<cd2>} object</a>的属性</p>
<h3>由不支持的文件格式<code>.xlsx</code></h3>
<p>正如<a href="https://stackoverflow.com/a/68656125/5730279">Nathaniel Ford's answer</a>所解释的:</p>
<ul>
<li><em>xlrd</em>(从当前版本2.0.1开始)仅支持旧版Excel文件格式<code>.xls</code></li>
</ul>
<h3>另见</h3>
<ul>
<li><a href="https://stackoverflow.com/questions/65250207/pandas-cannot-open-an-excel-xlsx-file">Pandas cannot open an Excel (.xlsx) file</a></li>
<li><a href="https://stackoverflow.com/questions/55109911/why-is-python-xlrd-errors-when-opening-a-xlsm-instead-of-xls">Why is python xlrd errors when opening a .xlsm instead of .xls</a></li>
</ul>
<h2>替代解决方案</h2>
<p>Stackoverflow的研究给出了:
<a href="https://stackoverflow.com/questions/3239207/how-can-i-open-an-excel-file-in-python">How can I open an Excel file in Python?</a></p>
<p><a href="https://www.python-excel.org/" rel="nofollow noreferrer">Working with Excel Files in Python</a>是一个伟大的资源集合,列出了流行的图书馆</p>
<h3>移植到OpenPyXL</h3>
<p>上面有:<a href="https://openpyxl.readthedocs.io/en/stable/" rel="nofollow noreferrer"><em>openpyxl</em></a></p>
<blockquote>
<p>The recommended package for reading and writing <strong>Excel 2010 files (ie: .xlsx)</strong></p>
</blockquote>
<p>安装后,请使用:</p>
<pre class="lang-sh prettyprint-override"><code>pip install openpyxl
</code></pre>
<p>您的代码可能被移植到此库,如下所示:</p>
<pre class="lang-py prettyprint-override"><code>from openpyxl import load_workbook
path = "C:\\Users\\m.macapanas\\Desktop\\OFCCP_Default_Values.xlsm"
excel_workbook = load_workbook(filename = path)
excel_worksheet = excel_workbook. worksheets[0] # first worksheet
# Read from Excel Worksheet
print("Your Worksheet has " + str(excel_worksheet.ncols) + " columns")
print("Your Worksheet has " + str(excel_worksheet.nrows) + " rows")
for row in excel_worksheet.rows:
for col in excel_worksheet.cols:
print(excel_worksheet.cell(row, col), end='')
print('\t', end='')
print()
</code></pre>