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