need package: win32com.client
from http://sourceforge.net/project/showfiles.php?group_id=78018&package_id=79063&release_id=449591
by Holibut, 2007.04.19
'''
import win32com.client
class ExcelProcessor:
_fileName='';
#_workBook
def __init__(self, asFilename =''):
if len(asFilename)> 0:
self.openFile(asFilename)
def openFile(self, asFilename=''):
self._excelApp = win32com.client.Dispatch("Excel.Application")
if self._excelApp.Visible != 1 :
self._excelApp.Visible=1
#if the file is already opened, then use it.
if self._excelApp.Workbooks.count == 0:
print "not opened yet"
self._workbook = self._excelApp.Workbooks.Open (asFilename)
else:
self._workbook = self._excelApp.Workbooks[0]
def getData(self, aiSheetIndex = 1, aiRowFrom = 1, aiRowTo = 1, aiColumnFrom = 1, aiColumnTo = 1):
self._sheet = self._workbook.worksheets(aiSheetIndex)
loData = []
for liRow in range(aiRowFrom, aiRowTo):
loRow = []
for liColumn in range(aiColumnFrom, aiColumnTo):
loRow.append(self._sheet.cells(liRow, liColumn).text)
loData.append(loRow)
#
return loData