AttributeError:'int'对象没有属性'_get_xf_index'

问题描述 投票:0回答:1

从数组写入时发生错误“ AttributeError:'int'对象没有属性'_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'
python xlsxwriter
1个回答
0
投票

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

就您而言,应该是

worksheet.set_column(0, 3, 15)
© www.soinside.com 2019 - 2024. All rights reserved.