In message "Re: win32ole and excel"
on 02/08/06, MikkelFJ <mikkelfj-anti-spam / bigfoot.com> writes:
> > Unfortunately, WIN32OLE can not handle VARIANT type argument
> > correctly.
>
> Will that be fixed?
I am not sure but I hope to fix.
> I haven't tried the following, but a prerelease of OCam'Ole has just been
> released a few days ago. There might be some useful VARIANT code in the C
> interface.
>
> http://tech.motion-twin.com/
I do not know OCaml, but it seems to me that you need to specify VT_XXX
type directly. (This is because I read excel1.ml only, so I had mistaken.)
And this seems same as _invoke approach of Ruby.
> As you can see in the script, VT_BSTR did the job.
This information might help me. Thank you.
I'll investigate more.
> So this is great in the sense that it now works, but it isn't very
> practical as a lot of COM components do use the VARIANT type.
Win32OLE sometimes works fine.
For example,
Workbooks.SaveAs of Excel VBA has VARIANT type argument.
require 'win32ole'
excel = WIN32OLE.new('Excel.Application')
excel.visible = true
book = excel.workbooks.add
save_as_info = book.ole_method_help('SaveAs')
save_as_info.params.each do |param|
print param.ole_type + " " + param.name
print " [IN]" if param.input?
print " [OPTIONAL]" if param.optional?
print "\n"
end
# book.SaveAs
# book.SaveAs('file1.xls')
# book.SaveAs('file1.txt', -4158)
The result is
VARIANT Filename [IN] [OPTIONAL]
VARIANT FileFormat [IN] [OPTIONAL]
VARIANT Password [IN] [OPTIONAL]
VARIANT WriteResPassword [IN] [OPTIONAL]
VARIANT ReadOnlyRecommended [IN] [OPTIONAL]
VARIANT CreateBackup [IN] [OPTIONAL]
XlSaveAsAccessMode AccessMode [IN] [OPTIONAL]
VARIANT ConflictResolution [IN] [OPTIONAL]
VARIANT AddToMru [IN] [OPTIONAL]
VARIANT TextCodepage [IN] [OPTIONAL]
VARIANT TextVisualLayout [IN] [OPTIONAL]
and
book.SaveAs
book.SaveAs('file1.xls')
book.SaveAs('file1.txt', -4158)
works fine.
But sometimes, you must use _invoke and specify VT_XXX type directly.
Regards,
Masaki Suketa