Ok, here we are for our daily python code.
Today we want to see how easy is to use python to manipulate excel files with this module called xlsxwriter.
How do I install it?
go in the command line and write
pip install xlsxwriter and you're done.
Now, let's go to the code
import xlsxwriter as xw # CREATE THE FILE book = xw.Workbook("file.xlsx") # ADD A SHEET sheet = book.add_worksheet() # Widen the column A sheet.set_column("A:A", 20) # Bold format to highlight the cells bold = book.add_format({'bold': True}) # WRITE sheet.write("A1","Hello") sheet.write("A2","World",bold) # Numbers with row-column notation sheet.write(5,1,123) sheet.write(5,0,5000) # Insert Image sheet.insert_image("B5","01.png")
Ok, we import the module, then we create the file and a sheet, we widen a column and write some text, then some number and... even a picture that you have in the same folder (or you write the dir, not only the name...). Simple as that.
Comments
Post a Comment