So, I am trying to automate Excel from C++ and OLE, using the Autowrap
function provided by Microsoft in their automation examples.
I have gotten as far as that I can read a string value from a cell in the spreadsheet. However, it seems like for some values, something is wrong with the string, like it's not null terminated. Here is my code:
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, range, L"Value", 0);
wprintf(L"%s, len: %d\n", result.bstrVal, SysStringLen(result.bstrVal));
wprintf(L"abc %s\n", SysAllocString(L"def"));
The output is:
John Doe á, 11
abc def
Whereas, in the Excel file when displayed in Excel, it shows like:
John Doe
(Can the code page of the Excel document somehow be an issue? It's an xlsx
file.)