win32com ppt embedded object numbers reverting back to original numbers

L

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
 
K

kyosohma

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

I've never done this with Python, but it sounds like your inserting a
linked table rather than a copy of the dataset as an Excel worksheet.
Try doing the insert manually to see which way keeps the data the way
you want, then you'll probably gain insight into what you need to do
in Python.

Mike
 
L

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top