WIN32OLE doesn't seem to support UTF-8.

  • Thread starter Bret Pettichord
  • Start date
B

Bret Pettichord

Has anyone been able to use WIN32OLE with international characters?

I would like to access international text from Excel and Explorer using
WIN32OLE. But whenever i do this in Ruby, i get "????????". (This code
works fine for English).

data = $sheet.cells(1, 'b').value
$sheet.cells(2, 'b').value = data

I'm pretty sure this is a Ruby problem, because the equivalent script in
VBA works fine.

Set From = Worksheets("Sheet1").Cells(1, "b")
Set Target = Worksheets("Sheet1").Cells(2, "b")
Target.Value = From.Value

I've been testing this with UTF-8 encoded Japanese text, although i am
hoping to find a general solution (not specific to any code-page).

When i looked through the Ruby code (win32ole.c) and it seems that string
return values are being passed through this function:

static LPWSTR
ole_mb2wc(pm, len)
char *pm;
int len;
{
int size;
LPWSTR pw;
size = MultiByteToWideChar(CP_ACP, 0, pm, len, NULL, 0);
pw = SysAllocStringLen(NULL, size - 1);
MultiByteToWideChar(CP_ACP, 0, pm, len, pw, size);
return pw;
}

"The MultiByteToWideChar function maps a character string to a
wide-character (Unicode) string. The character string mapped by this
function is not necessarily from a multibyte character."

I don't really understand what is happening here. It seems to me that both
the input and output strings have to have their encoding specified here.
Here ANSI is hard-coded (CP_ACP) but i don't know if this is for input or
output.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_17si.asp

I'd appreciate any insight into this matter that you might have. I've spent
a couple days reading up on UTF-8 and Unicode, but don't really have any
experience with these things.

I am using 1.8.2-15

Bret


_____________________
Bret Pettichord
www.pettichord.com
 
N

nobu.nokada

Hi,

At Thu, 8 Sep 2005 14:03:06 +0900,
Bret Pettichord wrote in [ruby-talk:155298]:
I'd appreciate any insight into this matter that you might have. I've spent
a couple days reading up on UTF-8 and Unicode, but don't really have any
experience with these things.

There is WIN32OLE.codepage attribute in CVS, so it will be
available in 1.8.3.
 
B

Bret Pettichord

At said:
There is WIN32OLE.codepage attribute in CVS, so it will be
available in 1.8.3.

Nobu,

AWESOME! I just downloaded 1.8.3, ran my test file with the new code_page
attribute, and verified that it works as expected. Very good news.

You should know that the Watir users have been really happy with the
WIN32OLE library.

On a separate note, I have a developer who's created a DLL for me that
converts a window handle to a pointer to an IHTMLDocument2 object. I've
wrapped this in WIN32API, but that isn't quite good enough. What i want in
Ruby is the ability to create a wrapper that returns a WIN32OLE object,
rather than just a string with a pointer address in it. Do you know of any
way to convert the pointer to a WIN32OLE object?

Bret


_____________________
Bret Pettichord
www.pettichord.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top