Let's continue to take a look at this useful module to make use of Excel with the help of python. I think it is good to know how to use it in all those boring works where you have a lot of data to input and you don't want to use directly Excel, because you want to spend less time on it and have more results, useful results. So let's dive a little bit in the xlsxwriter module.
All the documentation has been taken from:
http://xlsxwriter.readthedocs.io/
Let's imagine we have this datasheet:
John 7
Jim 8
Jack 6
Let's code:
# import the module import xlsxwriter # Create the file and add a sheet xfile = xlsxwriter.Workbook("Grades.xlsx") sheet = xfile.add_worksheet() # Create a tuple with some data in lists items grades = (["John",7],["Jim",8],["Jack",6]) # Let's start from row 0 and column 0 row = 0 col = 0 # Let's iterate the data with a loop cycle for name,grade in grades: sheet.write(row,col,name) sheet.write(row,col+1,grade) row += 1 # Let's make the total sheet.write(row, 0, 'Total') sheet.write(row,1,'=Sum(B1:B3)') row += 1 #Let's calculate the media sheet.write(row, 0, 'Media') sheet.write(row,1,'=MEDIA(B1:B3)') xfile.close()
Comments
Post a Comment