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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Python
 How to Insert OLE into PowerPoint using Python
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

nk.S

Republic of Korea
5 Posts

Posted - 06/19/2024 :  01:22:35 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.")

Edited by - nk.S on 06/19/2024 01:39:19 AM

YimingChen

1607 Posts

Posted - 06/19/2024 :  09:57:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

nk.S

Republic of Korea
5 Posts

Posted - 06/20/2024 :  05:02:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear James

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

It works well!!!

thank U!!!

sng
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000