我正在编写一个脚本,将多个表写入单个Excel工作表。我使用python 2.6和xlsxwriter来完成任务,但我无法创建表,也没有出现错误。只需将列名添加到Excel工作表中。这是我用来创建表的代码
import xlsxwriter
report = xlsxwriter.Workbook('example_report.xlsx')
sheet = report.add_worksheet()
row_count = 0
column_count = 0
table_headers = [
{'header': 'Product'},
{'header': 'Quarter 1'},
{'header': 'Quarter 2'},
{'header': 'Quarter 3'},
{'header': 'Quarter 4'},
]
excel_write_data = [
['Apples', 10000, 5000, 8000, 6000]
]
table_row_count = row_count+len(excel_write_data)
table_column_count = column_count+len(table_headers)
sheet.add_table(
row_count, column_count,
table_row_count, table_column_count,
{
'data': excel_write_data,
'columns': table_headers
}
)
workbook.close()
提前致谢!
答案 0 :(得分:1)
它应该按预期工作。以下是您添加到完整程序中的代码:
self.window?.rootViewController
这是输出:
我想说你应该打印并调试你提供给import xlsxwriter
workbook = xlsxwriter.Workbook('tables.xlsx')
worksheet = workbook.add_worksheet()
row_count = 0
column_count = 0
table_headers = [
{'header': 'Product'},
{'header': 'Quarter 1'},
{'header': 'Quarter 2'},
{'header': 'Quarter 3'},
{'header': 'Quarter 4'},
]
excel_write_data = [
['Apples', 10000, 5000, 8000, 6000],
]
table_row_count = row_count + len(excel_write_data)
table_column_count = column_count + len(table_headers)
worksheet.add_table(row_count, column_count,
table_row_count, table_column_count,
{'data': excel_write_data,
'columns': table_headers})
workbook.close()
的范围。