[Tutor] Fuctions & instances
Terje Johan Abrahamsen
terjeja@hotmail.com
Wed, 17 Jul 2002 16:14:59 +0000
I am trying to get a program to run itself. But it doesn't seem to work. So
I have to create another program to run the first one. Sometimes it works,
other times it doesn't. So it is not a stable solution. How can I get this
to work correct?
-----
import win32com.client
import win32com.client.dynamic
from win32com.client import Dispatch
class divxl:
xlApp = Dispatch("Excel.Application")
xlBook = xlApp.Workbooks(1)
xlSheet = xlApp.Sheets(1)
xlrad = 1
func = 0 #Funksjon man ønsker 1) legg sammen med samme
policynummer
n = divxl()
def __init__(self):
print "Function numbers"
print " 1) Add rows where there are more than one equals in a
collumn"
print " 2) Remove rows that contain/not contain bold fields"
divxl.func = int(raw_input("Type the function # : "))
noff.starter()
def starter(self):
if divxl.func == 1:
summer()
elif divxl.func == 2:
bold()
def summer(self):
kolonne1 = int(raw_input("Collumn# where the equals are : "))
kolonne2 = int(raw_input("Collumn# where addition should be: "))
xlrad = 1
while divxl.xlSheet.Cells(xlrad + 1, kolonne1).Value != None:
pol1 = divxl.xlSheet.Cells(xlrad, kolonne1).Value
pol2 = divxl.xlSheet.Cells(xlrad + 1, kolonne1).Value
if pol1 == pol2:
divxl.xlSheet.Cells(xlrad, kolonne2).Value =
divxl.xlSheet.Cells(xlrad, kolonne2).Value + divxl.xlSheet.Cells(xlrad + 1,
kolonne2).Value
divxl.xlSheet.Rows(xlrad + kolonne1).Delete()
xlrad = xlrad - 1
xlrad = xlrad + 1
def bold(self):
boldyn = int(raw_input("Remove bold, '1', keep bold, '2' : "))
rad = 1
while divxl.xlSheet.Cells(rad, 1).Value != None:
if boldyn == 1:
if divxl.xlSheet.Cells(rad, 1).Font.Bold == 1:
divxl.xlSheet.Rows(rad).Delete()
if boldyn == 2:
if divxl.xlSheet.Cells(rad, 1).Font.Bold == 0:
divxl.xlSheet.Rows(rad).Delete()
rad = rad + 1
------
The code itself works great. Just does some simple Excel tasks. But, I have
to write n = divxl(), then I have to write n.starter() for it to work. How
can I make it start just by creating the instance n=divxl()? From there it
should start n = starter() automatic? I want the whole thing made by py2exe
so that others also can use it. Thats not an option.
Usually I have made a script like this (for another program) that run the
program I want to run:
----------------
import sys
from time import sleep
import acnodate
from acnodate import *
n = acnodate()
n.start()
while 1:
sleep(0.5)
n.finnxlpolicy()
sleep(0.5)
n.fiex()
sleep(0.5)
n.skriv()
sleep(0.5)
---------------------
But, today that doesn't seem to work. I have no idea why. But I know this is
not an optimal solution...
Thanks,
Terje
_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com