Re: win32com ppt embedded object numbers reverting back to original numbers - SOLVED

2007-07-25 Thread Lance Hoffmeyer
Hey all,

I solved this problem.  Here is the final version of this def for anyone who
someday may be interested:

def attributesbyID(row,base,slideID,spreadsheet):
sh = wb.Worksheets (spreadsheet)
sh.Select()
LIST = xlparams(row, base)
 POWERPOINT SECTION ##
for shape in WB.Slides.FindBySlideID(slideID).Shapes:
if (shape.Type== 7):
for oXLROW,oXLBASE,oXLLASTCOL,oPPTCELL,oPPTHEADERCELL 
in LIST:
oVALUE = sh.Cells(oXLROW,oXLLASTCOL).Value
oHEADER = sh.Cells(base-1,oXLLASTCOL).Value  + 
" (n="  +  str(int(sh.Cells(oXLBASE,oXLLASTCOL).Value))  + ")"
PWB = 
WB.Slides.FindBySlideID(slideID).Shapes(shape.Name)
oGraph = PWB.OLEFormat.Object
#   oGraph = shape.OLEFormat.Object

oGraph.Application.datasheet.Range(oPPTCELL).Value = oVALUE

oGraph.Application.datasheet.Range(oPPTHEADERCELL).Value = oHEADER
oGraph.Application.datasheet.Font.Bold=False
oGraph.Application.Update()
oGraph.Application.Quit()   
del oGraph
-- 
http://mail.python.org/mailman/listinfo/python-list


win32com ppt embedded object numbers reverting back to original numbers

2007-07-19 Thread Lance Hoffmeyer
Hey all,

I have a script that takes numbers from XL and inserts them into an embedded
MSGRAPH dataset in PPT.  The problem is that when I reopen the modified document
that has been saved as a new filename and activate the embedded datasheet the
new numbers that were inserted disappear and the old, original numbers come 
back?


I thought that adding these lines and resetting these variables was supposed to 
prevent
this from happening?

del oGraph
del PWB
del oHEADER
del oVALUE

Anyone had experience with this and know what I need to do to keep the embedded 
datasheet
from reverting back to it's original numbers after modification?

Thanks in advance,

Lance





#
#
# ADD THIS INTO A MODULE IN PPT TO OBTAIN THE PROG ID OF A SLIDE
#Sub test()
#MsgBox "The Slide ID of the current slide is:" & _
#   ActiveWindow.View.Slide.SlideID
#End Sub
#
def attributesbyID(row,base,slideID,spreadsheet):
sh = wb.Worksheets (spreadsheet)
sh.Select()
LIST = xlparams(row, base)
 POWERPOINT SECTION ##
for shape in WB.Slides.FindBySlideID(slideID).Shapes:
if (shape.Type== 7):
for oXLROW,oXLBASE,oXLLASTCOL,oPPTCELL,oPPTHEADERCELL 
in LIST:
oVALUE = sh.Cells(oXLROW,oXLLASTCOL).Value
oHEADER = sh.Cells(base-1,oXLLASTCOL).Value  + 
" (n="  +  str(int(sh.Cells(oXLBASE,oXLLASTCOL).Value))  + ")"
PWB = 
WB.Slides.FindBySlideID(slideID).Shapes(shape.Name)
oGraph = PWB.OLEFormat.Object

oGraph.Application.datasheet.Range(oPPTCELL).Value = oVALUE

oGraph.Application.datasheet.Range(oPPTHEADERCELL).Value = oHEADER
oGraph.Application.datasheet.Font.Bold=False
del oGraph
del PWB
del oHEADER
del oVALUE
###
#
#
#

def xlparams(row, base):
lastcol=LASTCOL
### EXCEL SECTION TO GET NUMBERS #

thelist=((row,base,lastcol,"A13","013"),(row,base,lastcol-1,"A14","014"),(row,base,lastcol-2,"A15","015"),(row,base,lastcol-3,"A16","016"),
  
(row+20,base+20,lastcol,"A9","09"),(row+20,base+20,lastcol-1,"A10","010"),(row+20,base+20,lastcol-2,"A11","011"),(row+20,base+20,lastcol-3,"A12","012"),
  
(row+40,base+40,lastcol,"A5","05"),(row+40,base+40,lastcol-1,"A6","06" ), 
(row+40,base+40,lastcol-2,"A7","07" ), (row+40,base+40,lastcol-3,"A8","08" ),
  
(row+60,base+60,lastcol,"A1","01"),(row+60,base+60,lastcol-1,"A2","02" ), 
(row+60,base+60,lastcol-2,"A3","03" ), (row+60,base+60,lastcol-3,"A4","04" ))
##
return thelist


## attribute(ROW NUMBER, BASE ROW NUMBER, SLIDE NUMBER)
attributesbyID(14,12,839,"Attributes(116-144)") # This medication has a 
convenient dosing frequency
-- 
http://mail.python.org/mailman/listinfo/python-list


win32com ppt saveas, not allowing spaces?

2007-07-16 Thread Lance Hoffmeyer
Hey all,

As always, thanks in advance!


I am trying to save a ppt presentation but am having problems regarding spaces 
and am wondering
if I am doing something wrong or whether this is a bug?  Also, is there a way 
around this other
than not using spaces in paths or filenames?  I can create filesnames without 
spaces but don't have
much control over paths.

Lance


WB.SaveAs("C:/temp/00_FINAL." + time.strftime("%Y.%m.%d.(%I.%M.%S%p)", 
time.localtime())  +  ".ppt")

saves the file C:\temp\00_FINAL.2007.07.16.(09.43.50AM).ppt


but

WB.SaveAs("C:/tmp dir/00_FINAL." + time.strftime("%Y.%m.%d.(%I.%M.%S%p)", 
time.localtime())  +  ".ppt")

gives the error:

Traceback (most recent call last):
  File "C:\temp\ppt.py", line 412, in ?
WB.SaveAs("C:/tmp dir/00_FINAL." + time.strftime("%Y.%m.%d.(%I.%M.%S%p)", 
time.localtime())  +  ".ppt")
  File "C:\Program 
Files\Python\lib\site-packages\win32com\gen_py\91493440-5A91-11CF-8700-00AA0060263Bx0x2x8.py",
 line 6827, in SaveAs
return self._oleobj_.InvokeTypes(2036, LCID, 1, (24, 0), ((8, 1), (3, 49), 
(3, 49)),FileName, FileFormat, EmbedTrueTypeFonts)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft 
Office PowerPoint 2003', 'Presentation.SaveAs : The path or file name for 
C://tmp%20dir/00_FINAL.2007.07.16.(09.44.01AM).ppt is invalid. Please check 
that the path and file
name are correct.', '', 0, -2147467259), None)

Tool completed with exit code 1

Also,

WB.SaveAs("C:/temp/00 FINAL." + time.strftime("%Y.%m.%d.(%I.%M.%S%p)", 
time.localtime())  +  ".ppt")

yields:

C:/temp/00%20FINAL.2007.07.16.(09.45.35AM).ppt



Lance
-- 
http://mail.python.org/mailman/listinfo/python-list


newbie question on def, passing param's help

2007-07-13 Thread Lance Hoffmeyer
Hey all,

I have a def that I have been using but I realized that sometimes I need a LIST 
with
5 or 6 brands instead of 4 so I want to put LIST outside of the def but I can't 
wrap
my head around a way to get LIST outside the def while still passing the same 4
parameters in the function.  I'm sure there is probably a simple answer but I 
can't
seem to think of it.

Thanks in advance,

Lance


def attributesbyID(row,base,slideID,spreadsheet):
sh = wb.Worksheets (spreadsheet)
sh.Select()
### EXCEL SECTION TO GET NUMBERS #

LIST=((row,base,lastcol,"A13","013"),(row,base,lastcol-1,"A14","014"),(row,base,lastcol-2,"A15","015"),(row,base,lastcol-3,"A16","016"),
  #brand1
  
(row+20,base+20,lastcol,"A9","09"),(row+20,base+20,lastcol-1,"A10","010"),(row+20,base+20,lastcol-2,"A11","011"),(row+20,base+20,lastcol-3,"A12","012"),#brand2
  
(row+40,base+40,lastcol,"A5","05"),(row+40,base+40,lastcol-1,"A6","06" ), 
(row+40,base+40,lastcol-2,"A7","07" ), (row+40,base+40,lastcol-3,"A8","08" ), 
#brand3
  
(row+60,base+60,lastcol,"A1","01"),(row+60,base+60,lastcol-1,"A2","02" ), 
(row+60,base+60,lastcol-2,"A3","03" ), (row+60,base+60,lastcol-3,"A4","04" )) 
#brand4
##
 POWERPOINT SECTION ##
for shape in WB.Slides.FindBySlideID(slideID).Shapes:
if (shape.Type== 7):
for oROW,oBASE,oCOL,oCELL,oHEADERCELL in LIST:
oVALUE = sh.Cells(oROW,oCOL).Value
oHEADER = sh.Cells(4,oCOL).Value  + " (n="  +  
str(int(sh.Cells(oBASE,oCOL).Value))  + ")"
PWB = 
WB.Slides.FindBySlideID(slideID).Shapes(shape.Name)
oGraph = PWB.OLEFormat.Object
oGraph.Application.datasheet.Range(oCELL).Value 
= oVALUE

oGraph.Application.datasheet.Range(oHEADERCELL).Value = oHEADER

   ###
del oGraph
attributesbyID(14,12,31,"Attributes") # attr1





Here is what I want:


LIST=((row,base,lastcol,"A13","013"),(row,base,lastcol-1,"A14","014"),(row,base,lastcol-2,"A15","015"),(row,base,lastcol-3,"A16","016"),
  #brand1
  
(row+20,base+20,lastcol,"A9","09"),(row+20,base+20,lastcol-1,"A10","010"),(row+20,base+20,lastcol-2,"A11","011"),(row+20,base+20,lastcol-3,"A12","012"),#brand2
  (row+40,base+40,lastcol,"A5","05"),(row+40,base+40,lastcol-1,"A6","06" ), 
(row+40,base+40,lastcol-2,"A7","07" ), (row+40,base+40,lastcol-3,"A8","08" ), 
#brand3
  (row+60,base+60,lastcol,"A1","01"),(row+60,base+60,lastcol-1,"A2","02" ), 
(row+60,base+60,lastcol-2,"A3","03" ), (row+60,base+60,lastcol-3,"A4","04" ), 
#brand4
  (row+80,base+80,lastcol,"A1","01"),(row+80,base+80,lastcol-1,"A2","02" ), 
(row+80,base+80,lastcol-2,"A3","03" ), (row+80,base+80,lastcol-3,"A4","04" )) 
#brand5


def attributesbyID(row,base,slideID,spreadsheet):
sh = wb.Worksheets (spreadsheet)
sh.Select()
##
 POWERPOINT SECTION ##
for shape in WB.Slides.FindBySlideID(slideID).Shapes:
if (shape.Type== 7):
for oROW,oBASE,oCOL,oCELL,oHEADERCELL in LIST:
oVALUE = sh.Cells(oROW,oCOL).Value
oHEADER = sh.Cells(4,oCOL).Value  + " (n="  +  
str(int(sh.Cells(oBASE,oCOL).Value))  + ")"
PWB = 
WB.Slides.FindBySlideID(slideID).Shapes(shape.Name)
oGraph = PWB.OLEFormat.Object
oGraph.Application.datasheet.Range(oCELL).Value 
= oVALUE

oGraph.Application.datasheet.Range(oHEADERCELL).Value = oHEADER

   ###
del oGraph
attributesbyID(14,12,31,"Attributes") # attr1

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32com ppt embedded object - SOLVED

2007-07-11 Thread Lance Hoffmeyer
Basically,
   if I ran (after discovering what the object name I was trying to modify in 
the ppt slide was):

if WB.Slides(29).Shapes("Object 2").Type==7:
PWB = WB.Slides(29).Shapes("Object 2") #Select 
the Graph Object 
oGraph = PWB.OLEFormat.Object
oGraph.Application.datasheet.Range("00").Value = "Fav"

this code worked.


When I ran this:

for shape in WB.Slides(29).Shapes:
if (shape.Type== 7):
print shape.Name
PWB = WB.Slides(29).Shapes(shape)
oGraph = PWB.OLEFormat.Object
oGraph.Application.datasheet.Range("00").Value = "Fav"


I got an error.


I tried "print shape" I received




Putting in PWB = WB.Slides(29).Shapes(shape.Name) instead of PWB = 
WB.Slides(29).Shapes(shape)
allowed this to work.

Also, I discovered I was working with a MSGraph object and not an Excel 
spreadsheet object.

for shape in WB.Slides(29).Shapes:
if (shape.Type== 7):
print shape.Name
PWB = WB.Slides(29).Shapes(shape.Name)
oGraph = PWB.OLEFormat.Object
    oGraph.Application.datasheet.Range("00").Value = "Fav"

Lance






Lance Hoffmeyer wrote:
> Hey all,
> 
> I am trying to create some python code to edit embedded ppt slides and need 
> some help.
> 
> import win32com.client
> from win32com.client import constants
> import re
> import codecs,win32com.client
> import time
> import datetime
> import win32com.client.dynamic
> ##
>  VARIOUS VARIABLES TO SET 
> path = "C:\temp/"
> ##
> ##
> 
> 
> PPT=win32com.client.Dispatch("PowerPoint.Application")
> WB=PPT.Presentations.Open(path + "File.ppt")
> PPT.Visible=1
> PPTSLIDE= 29
> 
> for Z in WB.Slides(29).Shapes:
>   if (Z.Type== 7):
>   ZZ=Z.OLEFormat.Object
>   WSHEET = ZZ.Worksheets(1)
>   WSHEET.Range("A1").Value = .50
>   WSHEET.Range("A1").NumberFormat="0%"
> 
> Gives error:
> 
> Traceback (most recent call last):
>   File "P:\Burke\TRACKERS\Ortho-McNeil\04 2007, 04-10 WAVE 
> 4\Automation\Document1.py", line 23, in ?
> WSHEET = ZZ.Worksheets(1)
>   File "C:\Program 
> Files\Python\lib\site-packages\win32com\client\dynamic.py", line 489, in 
> __getattr__
> raise AttributeError, "%s.%s" % (self._username_, attr)
> AttributeError: .Worksheets
> 
> Tool completed with exit code 1
> 
> 
> 
> Why is ZZ unknown and how to I correct this?
> 
> 
> 
> 
> Thanks in advance,
> 
> Lance
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


win32com ppt embedded object

2007-07-10 Thread Lance Hoffmeyer
Hey all,

I am trying to create some python code to edit embedded ppt slides and need 
some help.

import win32com.client
from win32com.client import constants
import re
import codecs,win32com.client
import time
import datetime
import win32com.client.dynamic
##
 VARIOUS VARIABLES TO SET 
path = "C:\temp/"
##
##


PPT=win32com.client.Dispatch("PowerPoint.Application")
WB=PPT.Presentations.Open(path + "File.ppt")
PPT.Visible=1
PPTSLIDE= 29

for Z in WB.Slides(29).Shapes:
if (Z.Type== 7):
ZZ=Z.OLEFormat.Object
WSHEET = ZZ.Worksheets(1)
WSHEET.Range("A1").Value = .50
WSHEET.Range("A1").NumberFormat="0%"

Gives error:

Traceback (most recent call last):
  File "P:\Burke\TRACKERS\Ortho-McNeil\04 2007, 04-10 WAVE 
4\Automation\Document1.py", line 23, in ?
WSHEET = ZZ.Worksheets(1)
  File "C:\Program Files\Python\lib\site-packages\win32com\client\dynamic.py", 
line 489, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: .Worksheets

Tool completed with exit code 1



Why is ZZ unknown and how to I correct this?




Thanks in advance,

Lance


-- 
http://mail.python.org/mailman/listinfo/python-list


excel column autofit

2007-06-12 Thread Lance Hoffmeyer
Hey all,

Wondering why the syntax won't autofit Column A?
I am not getting any errors.

Also, is there a way of reducing the number of
syntax lines?  Basically, I am wondering if there
is an easier way to copy and paste?

Thanks in Advance.

Lance

# ADD ROW LABELS
sh = wb.Worksheets ("Total")
sh.Select()
sh.Range(sh.Cells(2,1),  sh.Cells(20,1)).Select()
sh.Range(sh.Cells(2,1),  sh.Cells(20,1)).Copy()
sh = wb.Worksheets ("Current Total")
sh.Select()
sh.Range(sh.Cells(2,1),sh.Cells(20,1)).Select()
sh.Paste()
sh.Columns("A:A").EntireColumn.AutoFit
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie help looping/reducing code

2007-02-19 Thread Lance Hoffmeyer
Hey all,


Can someone help me reduce this code?  It sure seems
like there ought to be a way to loop this or combine
things so that there is only 1 or 3 lines to this
instead of 6.  I've been scratching my head over this
for a while though I can't come up with anything.
Just as a note, I need even_odd_round left alone because
it is not always used.  I just included for clarity.

As always, thanks in advance,

Lance

T2B = even_odd_round(float(str(T2B)))   
VS  = even_odd_round(float(str(VS)))
SS  = even_odd_round(float(str(SS)))
sh.Cells(21,lastcol+1).Value = float(str(T2B))/100
sh.Cells(22,lastcol+1).Value = float(str(VS))/100
sh.Cells(23,lastcol+1).Value = float(str(SS))/100



def even_odd_round(num):
if(round(num,2) + .5 == int(round(num,2)) + 1):
if num > .5:
 if(int(num) % 2):
num = round(num,2) + .1 #an odd number
 else:
num = round(num,2) - .1 #an even number
else:
   num = 1
rounded_num = int(round(num,0))
return rounded_num
-- 
http://mail.python.org/mailman/listinfo/python-list


help with looping, re.search, multiple indexing

2007-02-16 Thread Lance Hoffmeyer
Hey all,

How do I add another index inside a re.search?

I want to add
for j in [96,97,98,99]
BASE = re.search ...
sh.Cells97...
for i 

so that the Table 96 within the re.search(s) becomes Table 96, Table 97, Table 
98, Table 99
but don't know how to add a second index within the re.search since I already 
have %char
in match = re.search ... " %char, neuro ...


VAR=[]
BASE = re.search("Table 96.*?BASE.*?\d(.*?)\n", neuro, re.S 
).group(1).split()[1]
sh.Cells(7,lastcol+1).Value = BASE

for i, char in enumerate(["RECEIVED E", "PARTICIPATED"]):
match = re.search(r"Table 96.*?%s.*?\n.*?\d(.*?)\n.*?" %char ,  neuro, 
re.S )
if match:
VAR = match.group(1).split()[1]
else:
VAR = 0
if VAR=="-": VAR = 0
VAR = even_odd_round(float(str(VAR)))   
VAR = float(str(VAR))/100
sh.Cells(i+8,lastcol+1).Value = VAR
sh.Cells(10,lastcol+1).Value= sh.Cells(9,lastcol+1).Value
sh.Cells(9,lastcol+1).Value = sh.Cells(8,lastcol+1).Value - 
sh.Cells(10,lastcol+1).Value



VAR=[]
BASE = re.search("Table 97.*?BASE.*?\d(.*?)\n", neuro, re.S 
).group(1).split()[1]
sh.Cells(11,lastcol+1).Value = BASE
for i, char in enumerate(["RECEIVED E", "PARTICIPATED"]):
match = re.search(r"Table 97.*?%s.*?\n.*?\d(.*?)\n.*?" %char , neuro, 
re.S )
if match:
VAR = match.group(1).split()[1]
else:
VAR = 0
if VAR=="-": VAR = 0
VAR = even_odd_round(float(str(VAR)))   
VAR = float(str(VAR))/100
sh.Cells(i+12,lastcol+1).Value = VAR

sh.Cells(14,lastcol+1).Value= sh.Cells(13,lastcol+1).Value
sh.Cells(13,lastcol+1).Value = sh.Cells(12,lastcol+1).Value - 
sh.Cells(14,lastcol+1).Value



-- 
http://mail.python.org/mailman/listinfo/python-list


re.search making no match == 0

2007-02-15 Thread Lance Hoffmeyer
Hey all,

I have a search:

VAR = re.search("PROVEN.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*?" , pcpT9, re.S 
).group(1)  #.split()[1]

that does not match (sometimes it will and sometimes it will not match)

Traceback (most recent call last):
  File "P:\Burke\TRACKERS\Ortho-McNeil\Automation\Wave3\test.py", line 53, in ?
VAR = re.search("PROVEN.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*?" , pcpT9, re.S 
).group(1)  #.split()[1]
AttributeError: 'NoneType' object has no attribute 'group'


Is there a way in python to make this "non" match equal a value (say, "0")?

This one line is actually a series of searches

Reasons = ["EFFICACY","EFFECTIVE","WORKS 
QUICKLY","PROVEN","SAFETY","LITTLE","WELL","  BETTER","SAMPLES"] # Reasons(29)
VAR = [re.search(r"%s.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*?" % i, pcpT9, re.S 
).group(1) for i in Reasons ]  #.split()[1]

and one of the items in the array may or may not be present.

Lance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: excel find last column

2007-02-09 Thread Lance Hoffmeyer
I ran makepy.py and loaded Microsoft Excel Object Library 11.0
I have imported:

import win32com.client
from win32com.client import constants
import re
import codecs,win32com.client
import time
import datetime
import win32com.client.dynamic


using this expression

lastcol = sh.UsedRange.Find("*", "A1", 
win32com.client.constant.SearchOrder=xlByColumns, 
win32com.client.constants.SearchDirection=xlPrevious).Column

I get error:

, line 245
lastcol = sh.UsedRange.Find("*", "A1", 
win32com.client.constant.SearchOrder=xlByColumns, 
win32com.client.constants.SearchDirection=xlPrevious).Column
SyntaxError: keyword can't be an expression

Tool completed with exit code 1


Guess I am getting closer to the solution? LOL
Sorry for being ignorant but I am a newbie and I don't understand all this 
python/excel stuff.

Lance







[EMAIL PROTECTED] wrote:
>> I get the error that xlPrevious is not defined.
>>
> 
> If you are using pythonwin, run the COM Makepy utility on Microsoft
> Excel Object Library. Then you have access to the defined constants as
> follows.
> 
 import win32com.client
 win32com.client.constants.xlPrevious
> 2
> 
> Hope this helps.
> 
> Paul
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


excel find last column

2007-02-08 Thread Lance Hoffmeyer
Hi all,

I am trying to find the last used column in an excel sheet using win32com:

lastcol = sh.UsedRange.Columns.Count

works, but only if there is no formatting.  I want to allow formatting in  the 
columns.

I would rather use the code below because formatted cells are irrelevant.
using:

lastcol = sh.UsedRange.Find("*",xlPrevious,xlByColumns).Column

I get the error that xlPrevious is not defined.



I am using Activestate PythonWin 2.3.5.  makepy.py cannot be located.
Is makepy.py needed?  If so, where do I find it and how do I install
it?  Seems like I ran into this problem before but I cannot remember
how I solved it?


Lance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: excel centering columns

2006-05-17 Thread Lance Hoffmeyer
Once I imported the EXCEL 10.0 library using
'makepy utility' everything worked fine.

And, yes, my typing mistake.  Should have been
'constants' and not 'constant'

Lance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: excel centering columns

2006-05-17 Thread Lance Hoffmeyer
I did read the error message.  I did not understand why 'constant' was
not defined.  In perl I did not have to run anything like 'makepy' to
get constants to work.  And no, I don't want to go back to perl.  Python
appears to integrate with packages more readily than perl does.

I was unaware of 'makepy' until you mentioned it.  Spent 3 hours searching
the web and google groups under python excel column | 'centering columns' to
find a solution.  Never saw anything mentioned about 'makepy'.

Thanks.  I will do some searches on 'makepy'.

Lance






John Machin wrote:
>> from win32com.client import constants
>> sh2.Columns(lastcol).HorizontalAlignment = constant.xlCenter
>> NameError: name 'constant' is not defined
> 
> 1. So why not try reading the error message and fixing the problem
> instead of thrashing about madly?
> 
> 2. You have run makepy on your Excel library, haven't you?
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


excel centering columns

2006-05-17 Thread Lance Hoffmeyer
Hey all,

Having problems centering a column
Can someone explain how to center a column using python?



import win32com.client
import re
import codecs
import win32com.client.dynamic
import time
import datetime
from win32com.client.dynamic import Dispatch
from win32com.client import constants


t2 = win32com.client.Dispatch("Excel.Application")
t2.Visible=1
wb = t2.Workbooks.Open (path + xltrack)
sh2 = wb.Worksheets (sheet)
lastcol = sh2.UsedRange.Columns.Count


sh2.Columns(lastcol).HorizontalAlignment = xlCenter
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'xlCenter' is not defined


sh2.Columns(lastcol).HorizontalAlignment = constant.xlCenter

Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'constant' is not defined


sh2.Columns(lastcol).HorizontalAlignment = -4108

Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 455, 
in __getattr__
return self._ApplyTypes_(*args)
  File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 446, 
in _ApplyTypes_
return self._get_good_object_(
com_error: (-2146827864, 'OLE error 0x800a01a8', None, None)

-- 
http://mail.python.org/mailman/listinfo/python-list


help with a function

2006-05-16 Thread Lance Hoffmeyer
Hey all,

I'm new to python.  I keep getting an error when running this.
I'm sure there is an easy fix but I can't figure it out.
What am I doing wrong?  How do I fix it?

def even_odd_round(num):
if(round(num,2) + .5 == int(round(num,2)) + 1):
 if(int(num,0) % 2):#an odd number  
rounded_num = round(num,2) + .1
 else:  #an even number
rounded_num = round(num,2) - .1
rounded_num = int(rounded_num)
return rounded_num

even_odd_round(5.5)

Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 3, in even_odd_round
TypeError: int() can't convert non-string with explicit base
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


arrays, even, roundup, odd round down ?

2006-05-16 Thread Lance Hoffmeyer
So, I have using the following to grab numbers from MS Word.  I discovered that 
that there is a "special"
rule being used for rounding.

If a ??.5 is even the number is to rounded down (20.5 = 20)
if a ??.5 is odd the number is to rounded up (21.5 = 22)

Brands = ["B1","B2"]
A1 = []
A1 = [ re.search(r"(?m)(?s)\r%s.*?SECOND.*?(?:(\d{1,3}\.\d)\s+){2}" % i, 
target_table).group(1)  for i in Brands ]
A1 = [int(float(str(x))+0.5) for x in A1 ]
print A1


Any solutions for this line with the above conditions?
Just as a note, any other number ??.3,??.7 follows the normal pattern
of rounding (21.3 = 21, 20.3 = 20, 21.7 = 22, 20.7 = 21)

A1 = [int(float(str(x))+0.5) for x in A1 ]

Lance


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Lance Hoffmeyer
The array comes out as unicode.  This is probably because I am grabbing the 
numbers
from a Word Doc using regex's.

So, before rounding I perform the following:
# Convert to String
Topamax = [str(x) for x in Topamax]
# Convert to floating
Topamax = [float(x) for x in Topamax]
# Finally, round the number
Topamax= [(x+0.5) for x in Topamax]

Is there a shorter way?

Lance



Lance Hoffmeyer wrote:
> Is there an easy way to round numbers in an array?
> 
> I have
> Test = [1.1,2.2,3.7]
> 
> and want to round so the values are
> 
> print Test  [1,2,4]
> 
> 
> Lance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round numbers in an array without importing Numeric or Math?

2006-05-16 Thread Lance Hoffmeyer
May have a complicating issue with the array?  Have
the numbers have been interpreted as strings?  I have
been pulling them from a Word doc using regex's

print Test
[u'9.0', u'58.6', u'97.8', u'10.0', u'9.6', u'28.1']


Lance


Alexander Schmolck wrote:
> Lance Hoffmeyer <[EMAIL PROTECTED]> writes:
> 
>> Is there an easy way to round numbers in an array?
>>
>> I have
>> Test = [1.1,2.2,3.7]
>>
>> and want to round so the values are
>>
>> print Test  [1,2,4]
> 
> [int(x+0.5) for x in Test]
> 
> 'as
-- 
http://mail.python.org/mailman/listinfo/python-list


round numbers in an array without importing Numeric or Math?

2006-05-16 Thread Lance Hoffmeyer
Is there an easy way to round numbers in an array?

I have
Test = [1.1,2.2,3.7]

and want to round so the values are

print Test  [1,2,4]


Lance
-- 
http://mail.python.org/mailman/listinfo/python-list


regex help

2006-05-16 Thread Lance Hoffmeyer
I have the following table and I am trying to match percentage the 2nd column 
on the 2nd Tiger line (9.0).

I have tried both of the following.  I expected both to match but neither did?  
Is there a modifier
I am missing?  What changes do I need to make these match?  I need to keep the 
structure of the regex
the same.

TIGER.append(re.search("TIGER\s{10}.*?(?:(\d{1,3}\.\d)\s+){2}", 
target_table).group(1))
TIGER.append(re.search("^TIGER.*?(?:(\d{1,3}\.\d)\s+){2}", 
target_table).group(1))


BASE - TOTAL TIGER 268   268173 95   101 -   10157 -
5778 276   268   19276230 21

DOG 7979 44 3531 -3117 -
1725 124795524 75  1
  29.5  29.5   25.4   36.8  30.7 -  30.7  29.8 -  
29.8  32.1  50.0  31.6  29.5  28.6  31.6   32.64.8

CAT 4646 28 1820 -20 7 -
 714 -14463214 39  4
  17.2  17.2   16.2   18.9  19.8 -  19.8  12.3 -  
12.3  17.9 -  18.4  17.2  16.7  18.4   17.0   19.0

LAMB3232 23  910 -10 8 -
 812 -12322012 28  1
  11.9  11.9   13.39.5   9.9 -   9.9  14.0 -  
14.0  15.4 -  15.8  11.9  10.4  15.8   12.24.8

TRIPOD  3232 23  9 9 - 9 9 -
 911 110322210 28  3
  11.9  11.9   13.39.5   8.9 -   8.9  15.8 -  
15.8  14.1  50.0  13.2  11.9  11.5  13.2   12.2   14.3

TIGER   2424 16  8 5 - 510 -
10 7 - 72417 7 18  2
   9.0   9.09.28.4   5.0 -   5.0  17.5 -  
17.5   9.0 -   9.2   9.0   8.9   9.27.89.5
-- 
http://mail.python.org/mailman/listinfo/python-list


using target words from arrays in regex, pythons version of perls 'map'

2006-05-15 Thread Lance Hoffmeyer
Hey all, in perl I was able to use the same regular expression multiple times 
changing one part of it
via a previously defined array and put the results into a new array

IN PERL:

my @targets = ('OVERALL RATING',
   'CLOTHING', '
ITEMS',
   'ACCESSORIES',
   'SHOES',
   'FINE JEWELRY');

my @JA13 = map {
$file2 =~/$_.*?(?:(\d{1,3}\.\d)\s+){3}/s;
} @targets;



So, in python instead of

match2 = re.search('OVEWRALL RATING.*?(?:(\d{1,3}\.\d)\s+){3} ', file2);m01 = 
match2.group(1) ;print m01
match2 = re.search('CLOTHING.*?(?:(\d{1,3}\.\d)\s+){3} ', file2);   m02 = 
match2.group(1) ;print m02
match2 = re.search('ITEMS.*?(?:(\d{1,3}\.\d)\s+){3} ', file2);  m03 = 
match2.group(1) ;print m03
match2 = re.search('ACCESSORIES.*?(?:(\d{1,3}\.\d)\s+){3} ', file2);m04 = 
match2.group(1) ;print m04
match2 = re.search('SHOES.*?(?:(\d{1,3}\.\d)\s+){3} ', file2);  m05 = 
match2.group(1) ;print m05
match2 = re.search('FINE JEWELRY.*?(?:(\d{1,3}\.\d)\s+){3} ', file2);   m06 = 
match2.group(1) ;print m06


I would have something similar to perl above:


targets = ['OVERALL RATING',
   'CLOTHING', ITEMS',
   'ACCESSORIES',
   'SHOES',
   'FINE JEWELRY']

PROPOSED CODE:

match2 = re.search(targets[i].*?(?:(\d{1,3}\.\d)\s+){3} ', file2);m[i] = 
match2.group(1)




Lance
-- 
http://mail.python.org/mailman/listinfo/python-list


regular expression error ?

2006-05-15 Thread Lance Hoffmeyer
why isn't re.search recognizing "file"?  I can print the contents of "file".


import win32com.client
import re

D=MSWord.Documents.Open('C:/test/Test.doc')
file=D.Content
print file

match = re.search('(Table ?)', file)
if match:
   print "Table Number is: ", match.group(1)


Traceback (most recent call last):
  File "test.py", line 21, in ?
match = re.search('(Table ?)', file)
  File "C:\Python24\Lib\sre.py", line 134, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or buffer
-- 
http://mail.python.org/mailman/listinfo/python-list


help with perl2python regular expressions

2006-05-15 Thread Lance Hoffmeyer
Hey all,

I am trying to convert some old perl scripts I have to python.
Here is a snippit of the regex I used in perl.  I am trying to
figure out the equivalent code in python.  Can someone help?

my $file =$Word->ActiveDocument->Content->Text;
$file =~ /TABLE\s+1.*?JCP.*?MEAN.*?(?:(\d{1,3}\.\d\d)\s+){1}/s;
my $P05A008 = $1;

Lance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: script to search ebay?

2005-01-26 Thread Lance Hoffmeyer
Thanks for the script.  I haven't been on ebay for a while.
Wasn't aware of the Favorite searches.  Favorite Search is
probably the way to go.  Thanks for the info.

Lance


On Tue, 25 Jan 2005 22:57:54 -0800, Kamilche wrote:

> This script works. But why not make a 'Favorite Search' in ebay, and
> have it send you daily email for a year?
> 
> --Kamilche
> 
> |import urllib
> |import smtplib
> |
> |def main():
> |# Perform the search
> |results = SearchEbay(['So long and thanks for all the fish',
> | 'NOMATCHFOUND',
> | 'Python Programming'])
> |
> |# Email the results
> |Email('[EMAIL PROTECTED]',
> |  '[EMAIL PROTECTED]',
> |  'eBay Search Results',
> |  results)
> |
> |def SearchEbay(searchstrings):
> |' Search eBay for the desired items'
> |searchURL = "http://search.ebay.com/%s";
> |results = ""
> |s = "eBay Search Results:\n"
> |print s,
> |results += s
> |for i in range(len(searchstrings)):
> |
> |# Build the search URL
> |search = searchstrings[i].replace(' ', '-')
> |s = searchURL % search + " : "
> |print s,
> |results += s
> |
> |# Download the URL
> |url = urllib.urlopen(searchURL % search)
> |data = url.read()
> |url.close()
> |
> |# Write the URL to a file for debugging
> |fd = open('ebay %d.html' % i, 'w')
> |fd.write(data)
> |fd.close()
> |
> |# Search for the number of items found
> |c = data.find('items found for')
> |if c >= 0:
> |start = data.rfind('', 0, c) + 3
> |stop  = data.find('', start + 1)
> |cnt   = data[start:stop]
> |else:
> |cnt = '0'
> |s = "%s items found.\n" % cnt
> |print s,
> |results += s
> |
> |return results
> |
> |def Email(fromaddr, toaddr, subject, msg):
> |' Send email'
> |msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s" % \
> |   (fromaddr, toaddr, subject, msg))
> |server = smtplib.SMTP('your.smtp.server.here')
> |server.set_debuglevel(1)
> |server.sendmail(fromaddr, toaddr, msg)
> |server.quit()
> |
> |main()

-- 
http://mail.python.org/mailman/listinfo/python-list


script to search ebay?

2005-01-25 Thread Lance Hoffmeyer
Hi all,

Anyone know where I can find a python script to search ebay?  I
have been looking around but haven't found anything.  I know
there must be one somewhere so I am probably just looking in the
wrong places.  Optimally,  I would like the script to search ebay 
and then send an email out with the results.

Lance
-- 
http://mail.python.org/mailman/listinfo/python-list