?
Solved

Microsoft Word Automation, Zope, Plone, External Editor -- Interesting Problem

Posted on 2006-06-21
5
Medium Priority
?
284 Views
Last Modified: 2010-04-16
Basically -- we are using External Editor (0.9.1) loaded from Plone (2.1rc2 - customized) -- which is of course running on top of Zope (2.8.2), on top of Python (2.3.5).  I am looking to modify the client side component of External Editor to change the default behavior of Microsoft Word (2003, SP2) when used with External Editor.  When you hit "Save", I want it to do the equiv of going to "Save As", selecting "Filtered HTML", selecting the proper temporary file name (.../.../.../something.html), and saying "yes" to the warning that it could "lose data" in the conversion.

The goal is that from an end user perspective, they simply click "External Editor" (which automatically loads word), edit the file, click “save” (or control-s) and close the file – the magic happens on the backend.  

Bonus points if you can find a way to reload the page (if still up) in the web browser to instantly reflect the changes made.  

I will give credit for complete solutions, or even just good brainstorming that gets me on the right path to a solution.  Thanks Much!
0
Comment
Question by:rmelton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 29

Accepted Solution

by:
pepr earned 2000 total points
ID: 17017599
I hope that the code from the self-standing simple script can be used anywhere. Store the followint into the file EditDoc.py or whatever, modify the full path to the winword (should probably get it from the registry). I tried the script to be rather brief and simple. You probably want to add more code to solve the things not related to the principle.

The trick is to create the resulting html file before calling winword. It can be empty, but it should containt he doctype, head etc. This way, you can use the simple Save in the Word after editing (no need to Save As). After finishing the Word, the webbrowser is launched with the resulting file. Then winword is called and after the webbrowser refreshed (in a simple way).

EditDoc.py
---------------------------------------------------------------------------------------------
import os
import webbrowser

docTemplate = '''\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>My document title</title>
</head>
<body>
<h1>Top level title</h1>

<p>This is the doc template. Edit it, save it (do not change the name),
and quit the editor.</p>

</body>
</html>
'''


# Get the file name -- here in current directory, for simplicity.
fname = 'output.html'

# If the file does not exist, save the template under name of the future result.
if not os.path.isfile(fname):
    f = file(fname, 'w')
    f.write(docTemplate)
    f.close()

# Get the full path to the extenal editor -- here hard-coded, for simplicity.
editor = 'D:\Program Files\Microsoft Office\OFFICE11\winword.exe'
editorReadable = 'WinWord'

# Execute the editor and wait until finished.
code = os.spawnl(os.P_WAIT, editor, editorReadable, fname)

# Open the browser with the result.
webbrowser.open(fname)

# Reopen the existing file in the editor and wait.
code = os.spawnl(os.P_WAIT, editor, editorReadable, fname)

# Refresh the browser content and raise its windows.
webbrowser.open(fname, new=False, autoraise=True)
---------------------------------------------------------------------------------------------

 
0
 
LVL 29

Expert Comment

by:pepr
ID: 17017628
Ooops, the backslashes in the winword path should be doubled or changed to normal slashes or the string literal should be written as raw.

editor = r'D:\Program Files\Microsoft Office\OFFICE11\winword.exe'
0
 
LVL 29

Expert Comment

by:pepr
ID: 17192025
Does it work for you?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question