简体   繁体   English

使用 xlsxwriter 将 python 循环结果导出到 Excel 中的相应列

[英]Export python loop results to corresponding columns in Excel using xlsxwriter

I have a loop which retrieves two lists of values from some json.我有一个循环,它从一些 json 中检索两个值列表。 I would like to export each one of the values list (1000 results each one) with its header to Exscel.我想将每个值列表(每个 1000 个结果)及其 header 导出到 Exscel。 All values are available when I'm printing the results, but Excel sheet contains only header and a single row.当我打印结果时,所有值都可用,但 Excel 表仅包含 header 和单行。 Perhaps, I'm missing some loop to add.也许,我错过了一些要添加的循环。 Any help is appreciated任何帮助表示赞赏

list = x.json() 
    
workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()

for item in list:
    item1 = value1['valueID1']
    item2 = value2['valueID2']

    data = {"item1": [item1],"item2": [item2]}

    col_num = 0
    for key, value in data.items():
        worksheet.write(0, col_num, key)
        worksheet.write_column(1, col_num, value)
        col_num += 1
    workbook.close()

You need to increment the row value as well.您还需要增加行值。

list = x.json() 
    
workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()

for item in list:
    item1 = value1['valueID1']
    item2 = value2['valueID2']

    data = {"item1": [item1],"item2": [item2]}

    col_num = 0
    row_num = 0

    for key, value in data.items():
        worksheet.write(row_num , col_num, key)
        worksheet.write_column(row_num , col_num, value)
        col_num += 1
    row_num=row_num+1
workbook.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 For循环使用XlsxWriter和Python Excel - For loop using XlsxWriter with Python Excel 如何在python中使用xlsxwriter冻结excel文件中的行和列 - how to freeze a row and a columns in an excel file using xlsxwriter in python 在 python 中使用.write_formula (xlsxwriter) 将 excel 中的 2 列相乘 - Multiplying 2 columns in excel using .write_formula (xlsxwriter) in python 使用 xlsxwriter 将 dataframe 导出到 excel 文件 - Export dataframe to excel file using xlsxwriter 无法使用 xlsxwriter 库将数据导出到 Excel - Not able to export data into Excel using xlsxwriter library 如何使用xlsxwriter for python将数据导出到xlsx - How to export data to xlsx using xlsxwriter for python 循环遍历文件夹中的文件以查找正则表达式并发送到Excel时没有结果 - 使用Python 3.6和Xlsxwriter - No results when looping through files in folder to find regex and sending to Excel - Using Python 3.6 and Xlsxwriter Python Tkinter Xlsxwriter尝试将用户输入导出到Excel文件 - Python tkinter xlsxwriter trying to export user input to excel file python xlsxwriter 将数据框和绘图导出到一个 Excel 中的不同选项卡 - python xlsxwriter export dataframe and plotly graphs to different tabs in one excel Python使用XlsxWriter将多个矩阵写入excel - Python write multiple matrix into excel using XlsxWriter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM