The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Python
 How to Insert OLE into PowerPoint using Python

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
nk.S Posted - 06/19/2024 : 01:22:35 AM
Origin Ver. and Service Release (Select Help-->About Origin): origin2023
Operating System: windows

Hello. I am using Origin opju files by copying and pasting them into PowerPoint (graph with data included: ctrl + J), so that I can double-click the graphs in PowerPoint to edit the Origin graph and data as needed. I am trying to automate this process using Python, but the OLE insertion is not working (error: invalid request). I would appreciate it if you could help me with how to do this with the code below.

---------------------------

import win32com.client as win32
import originpro as op

# Open the Origin project file
op.open("your_project.opju")

# Get a list of all graph windows
graphs = op.find_pages("G")

if graphs:
# Activate the first graph window
graph = graphs[0]
graph.activate()

# Copy the graph
op.copy_page(graph.name)

# Start the PowerPoint application
ppt_app = win32.Dispatch("PowerPoint.Application")
ppt_app.Visible = True

# Create a new presentation
ppt = ppt_app.Presentations.Add()
slide = ppt.Slides.Add(1, 1) # 1: ppLayoutText

# Insert the Origin graph as an OLE object
shape = slide.Shapes.AddOLEObject(
Left=100, Top=100,
Width=500, Height=400,
ClassName="Origin.Application",
FileName="your_project.opju",
DisplayAsIcon=False
)

# Save the slide
ppt.SaveAs("output_presentation.pptx")

# Close PowerPoint (optional)
# ppt_app.Quit()
else:
print("No graph pages found in the project.")
2   L A T E S T    R E P L I E S    (Newest First)
nk.S Posted - 06/20/2024 : 05:02:34 AM
Dear James

Thank U !!!!!!!!!!!

It works well!!!

thank U!!!

sng
YimingChen Posted - 06/19/2024 : 09:57:00 AM
Please try the sample code:

import os
import originpro as op
import win32com.client as win32

op.set_show(True)

## Create an Origin Graph 
wks = op.new_sheet()
wks.from_file(os.path.join(op.path('e'), 'Samples', 'Graphing', 'Group.dat'))
graph = op.new_graph(template='scatter')
gl=graph[0]
plot = gl.add_plot(f'{wks.lt_range()}!(?,1:end)')
gl.rescale()

## Copy the graph as OLE object into clipboard
op.lt_exec(f'clipboard {graph.name}')

## Paste the OLE object to PPT slide
ppt_app = win32.Dispatch("PowerPoint.Application")
ppt_app.Visible = True
ppt = ppt_app.Presentations.Add()
slide = ppt.Slides.Add(1, 1) 
shapes = slide.Shapes
shapes.PasteSpecial(DataType=10) 


James

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000