Separate result in different worksheets

3

I have a problem in which I have to get all my information (information from each cell of the worksheet), make them go through a condition and for each condition result write to a new worksheet of a new file.

For example, I have the test.xls file that contains a spreadsheet and all the information. All values in this worksheet will be subject to 3 conditions, and these conditions will separate them into Name, Age and Sex. In other words, all values in my spreadsheet will be separated in Name, Age and Sex. The big question is, create a new file with 3 spreadsheets and each one will have the name Name, Age and Sex and each result will go to your specific worksheet.

My code is ready, it brings all the result I want in the terminal, however I do not know where to start to separate each result of each condition for its given worksheet. I know the xlwt library, but I'm having a hard time separating the results in the spreadsheets.

    
asked by anonymous 03.09.2014 / 15:31

1 answer

3

The command you are looking for is add_sheet .

This code creates a file with three spreadsheets and writes to each file. It should be adaptable to your case:

import xlwt

book = xlwt.Workbook(encoding="utf-8")

sheet1 = book.add_sheet("Nome")
sheet2 = book.add_sheet("Idade")
sheet3 = book.add_sheet("Sexo")

sheet1.write(0, 0, "Celula 1 da Planilha 1")
sheet2.write(0, 0, "Celula 1 da Planilha 2")
sheet3.write(0, 0, "Celula 1 da planilha 3")

book.save("trial.xls")

Adapted this question from StackOverflow in English.

    
09.09.2014 / 23:57