We can create excel files in python using XlsxWriter module. For creating an Excel line chart The first step is to install the XlsxWriter module.
There are several ways to do this.
A tarball of the latest code can be downloaded from GitHub as follows:
There are several ways to do this.
Using PIP
The pip installer is the preferred method for installing Python modules from PyPI, the Python Package Index:$ sudo pip install XlsxWriter
Note
Windows users can omit
sudo at the start of the command.Using Easy_Install
Ifpip doesn't work you can try
easy_install:$ sudo easy_install XlsxWriter
Installing from a tarball
If you download a tarball of the latest version of XlsxWriter you can install it as follows (change the version number to suit):$ tar -zxvf XlsxWriter-1.2.3.tar.gz $ cd XlsxWriter-1.2.3 $ sudo python setup.py install
$ curl -O -L http://github.com/jmcnamara/XlsxWriter/archive/master.tar.gz $ tar zxvf master.tar.gz $ cd XlsxWriter-master/ $ sudo python setup.py install
Running a sample program
If the installation went correctly you can create a small sample program like
the following to verify that the module works correctly:
import xlsxwriter workbook = xlsxwriter.Workbook('hello.xlsx') worksheet = workbook.add_worksheet() worksheet.write('A1', 'Hello world') workbook.close()Save this to a file called
hello.py and run it as follows:$ python hello.pyThis will output a file called
hello.xlsx which should look something like
the following:
Comments
Post a Comment