help with excel

Clayton Hablinski chablinski at internetwork.net
Tue Oct 12 10:59:31 EDT 2004


I am pretty new to python (which you will see by the code I am about to paste in here), and I am needing help with a script that will gather a cell's contents and use that information to create new data in a new cell. I need this done for an entire column. I can do it with one cell at a time, but what is the point in doing that? 

The part I am having trouble with is being able to increment rows. And now with my script that I have it just runs in some loop that brings my machine to the ground.

Here is what I have:

#RBOC-NonRBOC rates
#RBOC is .0029 and nRBOC is .0042
from win32com.client import Dispatch
xlApp = Dispatch ("Excel.Application")
def getCell(sheet, row ,col):
    "Get value of one cell"
    sheet = xlApp.ActiveWorkbook.ActiveSheet
    return sheet.Cells(row, col).Value
def setCellNonRBOC(sheet, row, col):
    "set value of one cell"
    sheet = xlApp.ActiveWorkbook.ActiveSheet
    sheet.Cells(row, col).Value = ".0042"
def setCellRBOC(sheet, row, col):
    "set value of one cell"
    sheet = xlApp.ActiveWorkbook.ActiveSheet
    sheet.Cells(row, col).Value = ".0029"
Range = xlApp.ActiveWorkbook.ActiveSheet.Range("B2:B5")
sheet = xlApp.ActiveWorkbook.ActiveSheet
row = 2
while len(Range.Value) > 0:
    getCell(sheet, row, 2)
    if sheet.Cells.Value == 'Non-RBOC':
        setCellNonRBOC(sheet, row, 8)
        row = row + 1
    elif sheet.Cells.Value == 'RBOC':
        setCellRBOC(sheet, row, 8)
        row = row + 1

The script needs to analyze cell B2 through cell B51290 (the entire range). And then for each cell it analyzes put either ".0029" or ".0042" in column 8.

Help me please!!!

Clayton 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041012/4e1d369c/attachment.html>


More information about the Python-list mailing list