gpt4 book ai didi

python - 属性错误 : 'int' object has no attribute '_get_xf_index'

转载 作者:太空宇宙 更新时间:2023-11-04 11:09:09 27 4
gpt4 key购买 nike

从数组写入时出现错误“AttributeError: 'int' object has no attribute '_get_xf_index'”

尝试了很多来自 Google 的推荐,但似乎没有什么适合我。

import xlsxwriter

# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('Report.xlsx')
worksheet = workbook.add_worksheet()

# Add a bold format to use to highlight cells.
bold = workbook.add_format({'bold': 1})

# Adjust the column width.
worksheet.set_column(15, 15, 15, 15)

# Write some data headers.
worksheet.write('A1', 'Name', bold)
worksheet.write('B1', 'Description', bold)
worksheet.write('C1', 'Products', bold)
worksheet.write('D1', 'Author', bold)

# Some data we want to write to the worksheet.
data = (
['Test-1', 'Confirms that API can be called with valid parameters.', 'x, y, x', 'Sam'],
['Test-2', 'Confirms that API can be called with valid parameters.', 'x, y, x', 'Sam'],
['Test-3', 'Confirms that API can be called with valid parameters.', 'x, y, x', 'Sam'],
['Test-4', 'Confirms that API can be called with valid parameters.', 'x, y, x', 'Sam'],
)

# Start from the first cell below the headers.
row = 1
col = 0

for name, description, products, author in data:
worksheet.write_string (row, col, name)
worksheet.write_string (row, col + 1, description)
worksheet.write_string (row, col + 2, products)
worksheet.write_string (row, col + 3, author)
row += 1

workbook.close()

错误信息:-

Traceback (most recent call last):
File "D:\VCI_TESTSUITES\rt-testsuite-working\rt-testsuite-tests\Data\Tests\ProcessingPrograms\XMLReportGenerator - Copy.py", line 38, in <module>
workbook.close()
File "C:\Users\iqs1sba\AppData\Local\Programs\Python\Python37\lib\site-packages\xlsxwriter-1.2.2-py3.7.egg\xlsxwriter\workbook.py", line 311, in close
File "C:\Users\iqs1sba\AppData\Local\Programs\Python\Python37\lib\site-packages\xlsxwriter-1.2.2-py3.7.egg\xlsxwriter\workbook.py", line 674, in _store_workbook
File "C:\Users\iqs1sba\AppData\Local\Programs\Python\Python37\lib\site-packages\xlsxwriter-1.2.2-py3.7.egg\xlsxwriter\packager.py", line 135, in _create_package
File "C:\Users\iqs1sba\AppData\Local\Programs\Python\Python37\lib\site-packages\xlsxwriter-1.2.2-py3.7.egg\xlsxwriter\packager.py", line 190, in _write_worksheet_files
File "C:\Users\iqs1sba\AppData\Local\Programs\Python\Python37\lib\site-packages\xlsxwriter-1.2.2-py3.7.egg\xlsxwriter\worksheet.py", line 3772, in _assemble_xml_file
File "C:\Users\iqs1sba\AppData\Local\Programs\Python\Python37\lib\site-packages\xlsxwriter-1.2.2-py3.7.egg\xlsxwriter\worksheet.py", line 5209, in _write_cols
File "C:\Users\iqs1sba\AppData\Local\Programs\Python\Python37\lib\site-packages\xlsxwriter-1.2.2-py3.7.egg\xlsxwriter\worksheet.py", line 5224, in _write_col_info
AttributeError: 'int' object has no attribute '_get_xf_index'

最佳答案

问题出在 set_column 方法中。你用错误的语法调用它。它是 set_column(self, first_col, last_col, width=None, cell_format=None, options=None)

在你的情况下,那将是

worksheet.set_column(0, 3, 15)

关于python - 属性错误 : 'int' object has no attribute '_get_xf_index' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58719629/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com