Please help with script...

Robert Oelschlaeger roelsch at
Tue Jun 4 07:53:24 CEST 2002

"Topy" <hobiewon at> wrote in message
news:adheqc$nhn$1 at
> Hey all,
> I'm having trouble with a problem I have with this python program.  It's
> kind of long, so if anyone has the patience, I would gladly appreciate
> time(the programming is fairly simple I think.)  Anyway, the problem I
> to do is this :

> It's not much, but I'm not sure where to go from here...can anyone help?
> Thanks so much!
> Topy

This might get you started; the worksheet is left open for you to examine
and save via the File menu -- Bob

# vim:ts=4:sw=4:et

def main():
    ProductID = int(raw_input("Please enter the ProductID: "))
    OrderQty = int(raw_input("Please enter the cutoff order quantity: "))
#   CSV = open('a:/sales.txt', 'r')
    CSV = open('sales.txt', 'r')

    import win32com.client
    xl = win32com.client.Dispatch('Excel.Application')

    # start at the top of the worksheet

    # report selection parameters and skip a line
    xl.Range("A1:B1").Value = ("ProductID:", ProductID)
    xl.Range("A2:B2").Value = ("OrderQty:", OrderQty)

    # fill in the column headers
    xl.ActiveCell.Range("A1:E1").Value = ("OrderID", "OrderDate",
"RegionID", "ProductID", "OrderQty")

    # process each line in the CSV file
    for line in CSV.readlines():
        # remove trailing \n
        line = line.rstrip()

        # get the raw data as strings
        inOrderID, inOrderDate, inRegionId, inProductId, inOrderQty =

        # is this item one that is interesting?
        if int(inProductId) == ProductID:
            if int(inOrderQty) >= OrderQty:
                # write the input data to the output file
                xl.ActiveCell.Range("A1:E1").Value = (inOrderID,
inOrderDate, inRegionId, inProductId, inOrderQty)
                # and activate the next line

if __name__ == "__main__":

More information about the Python-list mailing list