Writing to an Excel spreadsheet

后端 未结 12 1866
不知归路
不知归路 2020-11-22 04:39

I am new to Python. I need to write some data from my program to a spreadsheet. I\'ve searched online and there seem to be many packages available (xlwt, XlsXcessive, openpy

12条回答
  •  不思量自难忘°
    2020-11-22 05:32

    import xlwt
    
    def output(filename, sheet, list1, list2, x, y, z):
        book = xlwt.Workbook()
        sh = book.add_sheet(sheet)
    
        variables = [x, y, z]
        x_desc = 'Display'
        y_desc = 'Dominance'
        z_desc = 'Test'
        desc = [x_desc, y_desc, z_desc]
    
        col1_name = 'Stimulus Time'
        col2_name = 'Reaction Time'
    
        #You may need to group the variables together
        #for n, (v_desc, v) in enumerate(zip(desc, variables)):
        for n, v_desc, v in enumerate(zip(desc, variables)):
            sh.write(n, 0, v_desc)
            sh.write(n, 1, v)
    
        n+=1
    
        sh.write(n, 0, col1_name)
        sh.write(n, 1, col2_name)
    
        for m, e1 in enumerate(list1, n+1):
            sh.write(m, 0, e1)
    
        for m, e2 in enumerate(list2, n+1):
            sh.write(m, 1, e2)
    
        book.save(filename)
    

    for more explanation: https://github.com/python-excel

提交回复
热议问题