Separate result in different worksheets

Asked

Viewed 203 times

3

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

For example, I have the test.xls file that contains a spreadsheet and all the information. All the values of this spreadsheet will go through 3 conditions, and these conditions separate them in Name, Age and Sex. In other words, all values in my spreadsheet will be separated into 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 Gender and each result will fit your particular 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 your particular spreadsheet. I know about the library xlwt, but I am having difficulty on how to separate the results in spreadsheets.

1 answer

3


The command you’re looking for is add_sheet.

This code creates a file with three sheets and writes to each one. 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 of that question of Stackoverflow in English.

  • Hi, that’s exactly what I want to do. However, the results are not fixed values. First I read the values and then I need to write, that’s exactly what you gave me. Worksheets are created, but values are not passed on to worksheets. For example, I read my entire column Name, Age and Sex, and they are listed in the terminal, it is perfect, now when I do what you gave me, only the spreadsheets are created, each with the name we define, but without the values.

  • I did it! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.