Creating an Excel file or a spreadsheet
Spredsheet displays multiple cells usually in a two-dimensional matrix or grid consisting of rows and columns. A spreadsheet is used to simulates a paper accounting worksheet. We have so many reporting soft wares that will simply create spreadsheets. But the problem is, these reporting software s may not support on all systems and also take lot of CPU time. Then arise an idea to use some method to create spreadsheet from my python code.
Here is the simple code introduction for create the spreadsheet
- “import xlwt” package functionality to create sheet in your Py file.
- We can define the title, header, number, date, and normal style using xlwt.easyxf(). For example title style is given below
new_style = xlwt.easyxf(‘font:height 230; align: wrap No;border: top thick;border: bottom thick;’)
- We can define as many styles we want. We can also define how the border should appear.
- we can define the workbook. Workbook is actually what we view in our spreadsheet. To define workbook,
wbk = xlwt.Workbook()
sheet = wbk.add_sheet(‘New_sheet’, cell_overwrite_ok=True) - for write in to the sheet
sheet.write(4, 4, ‘Spellbound Soft Solution’,font_size) - To change the width and height of a cell,
sheet.col(1).width = 500*12
sheet.row(5).height = 70*5
Now move on to the code
step 1 :- for save the xls report create one class and one default get function in py file.
Step 2 :- for save the file in xml code is given below.
Note :- the output of above code is, when we click on the button of report one wizard will pop up to download the report
step 3 :- for xls report make one simple form view and add one button in to that form…
step 3 :- for the function of that button and create the xls report function given below which again code in to the py file
step4 :- at the end of the function give the return value to the function given below
step 5 :- final output of report is given below