[Pythonmac-SIG] Appscript and Excel
has
hengist.podd at virgin.net
Wed Apr 21 07:33:18 EDT 2004
Daniel Lord wrote:
>from appscript import *
>ws = app('Microsoft Excel').Workbooks[1].Worksheets[1]
>ws.Range['R1C1'].Formula.Set('Test_From_Python_Appscript',)
>
>THE RESULT:
>
> Error: -1708
> Generic error message: 'the AppleEvent was not handled by
>any handler'
Welcome to the brain-damage that is Excel scripting.
The problem here is that Excel's 'Set' command («event XCELsetd») is
different to the core 'set' command («event coresetd») that your
AppleScript is using. (Turn on AEDebug and friends in the shell to
see.)
I doubt there's any good reason why Excel should define a
non-standard 'Set' command in the first place, and it seems
particularly stupid to do so and then not bother to install an Apple
event handler to handle it.
The best solution would be to fix Excel's aete resource. Start by
filing a bug report on it, though I'm also assuming you don't want to
wait till MS get around to releasing a formal patch. If you're
feeling brave, you could hack the app directly with a ResEdit-style
tool. Alternatively, there's an as-yet undocumented system for
working around aete problems by exporting and compiling aete data
into a Python module where it can be hacked manually. This module can
then be imported into your script and passed to appscript via the
app() function's 'terms' argument:
from appscript import *
from customterminology import Excel_10_1_0
excel = app('Microsoft Excel', terms=Excel_10_1_0.appTerminology)
formulaRef = excel.Workbooks[1].Worksheets[1].Range['R1C1'].Formula
print formulaRef.get()
formulaRef.set('Test_From_Python_Appscript')
I'm still trying to decide on the best formal policy for dealing with
buggy aetes (appscript is much less forgiving of bad aetes than
AppleScript), and while this particular system works I really don't
like it much - it's complicated, clumsy, and hard for users to
follow, why I've not been quick to publicise it or release the full
resources to use it. However, I'm going to write it up for the 0.5.0
release which should be out in another week or so, with the proviso
that it's being made public purely for discussion purposes and is
subject to change or removal at any time.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
More information about the Pythonmac-SIG
mailing list