You didn't implement this part of the solution:
"""
> I am new to the Python Pyexcelerator.
Good. You won't miss it. Flick it and get xlwt from
http://pypi.python.org/pypi/xlwt. Then
g/pyExcelerator/s//xlwt/
in your source code and you're off. Benefits: it's maintained, it's
fixed a bug or two, it's faster, it's being enhanced, and it's not
called eXceLWriTe so you don't need 3 attempts to get your import
statements spelled right :-)
"""
Why not?
> I am reading a Excel file using following :
> book = pyExcelerator.parse_xls (iTestCaseName)
Don't do that. pyExcelerator is abandonware; it hasn't been maintained
for a long time. Use xlwt (a maintained fork of pyExcelerator) instead
for writing files. The parse_xls facility was deprecated so severely
that it has been removed from xlwt. Use xlrd for reading xls files.
http://pypi.python.org/pypi/xlrd
http://pypi.python.org/pypi/xlwt
> data = book[0][1]
>
> and reading the required cell value using following :
> Testdata = ((data[(6, 4)]))
Why have you wrapped that in (( )) ??
>
> the problem is when the cell is blank PyExcelrator gives and
> KeyError (6,4)
> is there any way to read the blank cell?
It's blank. That means there's no data in it. What do you expect to find
there?
The best you can do is
try:
value = data[(6, 4)]
except KeyError:
# do something else here
HTH,
John
"functionality" is not the word I would use in that context :-)
Follow the bouncing ball and sing along with me """The parse_xls
facility was deprecated so severely that it has been removed from xlwt.
Use xlrd for reading xls files.""" and you'll be a lot better off.
Cheers,
John
import xlrd
import sys
import os
import fnmatch
import shutil
## Save the path to the output result exel files.
OutputPath = 'D:\Profiles\systest\My Documents\Downloads\\'
## Get the list of files in the download directory.
dir_list = os.listdir( OutputPath )
## Find all the .xls test result files.
for fileName in dir_list:
if fnmatch.fnmatch( fileName, 'outreport*.xls' ):
## Append the path name to the results file.
extendedFileName = OutputPath+fileName
print extendedFileName
## Open the excel document.
excelBook = xlrd.open_workbook( extendedFileName )
for sheetName in excelBook.sheet_names():
sheet = excelBook.sheet_by_name( sheetName )
print sheetName
if ( sheetName == 'Log' ):
row = 1
col = 2
moreData = 1
while( moreData ):
try:
print sheet.cell_value( row, col )
row += 1
except IndexError:
moreData = 0
break
if ( sheetName == 'Trend' ):
row = 1
col = 2
print sheet.cell_value( row, col )
If you haven't already, please check out
<http://www.python-excel.org/>. In particular, have a look at the
tutorial (python-excel.pdf, and don't be deterred by the need to click
another link to get to the actual PDF). There you will find lots of
examples, including how to use empty_cell.
My other comment is: If your data is in contiguous rows (that is,
once you see one blank cell, you can be sure there is no more data in
subsequent rows) then you could just as well (and should) use nrows.
John Y.