India

ZestyBeanz Technologies Pvt Ltd 4th Floor, Nila, Technopark Thiruvananthapuram,
India – 695581
Phone: +91 471 4063254
Fax : +91 471 2700171

   .

ZestyBeanz Technologies Pvt Ltd
61/3236, Manikkath Cross Road
Ravipuram, Kochi, India - 682016
Phone: +91 484 4063254

  UAE

Zesty Labs
Office # 2003, Millennium Plaza Building
Sheikh Zayed Rd, Dubai, UAE
Phone: +971 4333 2222​
Mobile: +971-52-7553466

  Germany​

ZestyBeanz Technologies GmbH
Reuterstraße 1
90408 Nürnberg
Fon: +49 911 4801 444
Fax: +49 911 4801 445

Creating an Excel file or a spreadsheet using Python's xlutils (xlwt) module

Contact Form


omalbastin's picture

Creating an Excel file or a spreadsheet using Python's xlutils (xlwt) module

A spreadsheet is used to simulates a paper accounting worksheet. It displays multiple cells usually in a two-dimensional matrix or grid consisting of rows and columns. We have so many reporting software s 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. Then I found about the module xlutils in python.

XLUTILS module contain packages for reading from(xlrd) and writing to(xlwt) excel files. Since I only need the package to write to excel file I'm installing the xlwt package.

 

Installation

We can install any python package to our repository using pip, pip is an easy way to install python packages.

To install pip

omal@zbeanz:~$sudo apt-get install python-pip

After installing pip you can install python packages by

omal@zbeanz:~$sudo pip install xlwt

This will install xlwt package to python modules

 Now in our python code,to import the package functionality to the our program.

We can define the title, header, number, date, and normal style using xlwt.easyxf(). For example title style is given below

We can define as many styles we want. We can also define how the border should appear. For example,

After defining the styles we can now define the workbook. Workbook is actually what we view in our spreadsheet. To define workbook,

A spreadsheet may contain more than one sheet, so to add sheets,

Now we can start adding data to the sheet we have created.  To write data to the 'sheet1' use the reference ws and ws.write(row, column, 'Value or text',style). For example:

To change the width and height of a cell,

 We can add complete data to the spreadsheet by writing and changing the height and width according to our need. After completing this we can save the workbook to a buffer. So First define the buffer and then save the workbook to the  buffer. This doesn't complete the process.

Now we have to encode the data in the buffer and write it to a file say 'test.xls'. To encode the data in the buffer import base64 module. Now open the file test.xls to view our excel file we have created.

I have not mentioned the last few steps (from encoding) so that you can try it out and create the excel file.

essay help online's picture

A customer may need excel

A customer may need excel reports and html reports. RML reports cant be used for creating excel

Omal Bastin's picture

Hi, I know that a customer

Hi,
I know that a customer may need an excel report, html report and pdf reports. There are many methods to create those reports. Here I'm just explained about how we can create a excel report using only the python language. Thank you

Surendar's picture

will this method can generate

will this method can generate excel report in both tree and form view?

omalbastin's picture

sure. You can generate

sure. You can generate reports from tree and form view. please check this blog. http://zbeanztech.com/blog/advanced-printscreen-openerp-7

Surendar's picture

Yes I tried this too.. but it

Yes I tried this too.. but it also generate those excel reports in tree view only. not in form view

Surendar's picture

Yes.. I tried this too

Yes.. I tried this too already. but this also generate those reports in tree view only