使用VC2005(unicode程序) ,用自动化方式读取Excel中日文字符串。
。
for(int i = 1; i < nRowCnt; i++)
{
strRangePos.Format(L"F%d", i);
range = m_sheet.get_Range(COleVariant(strRangePos),COleVariant(strRangePos));
val = range.get_Text();
strRangeVal = val.bstrVal;
AfxMessageBox(strRangeVal); 能正常显示。但我将strRangeTimeout 写入文件中就显示乱码了。
FILE *fpLog;
fpLog = _wfopen(szPath,L"w");
if(!fpLog)
{
AfxMessageBox(L"failed");
fclose(fpLog);
return;
}
... fwprintf(fpLog,L"index=%d, Pos=%s,cID=%s,timeout=%s\n",id,
(wchar_t*)(LPCTSTR)strPos,
(wchar_t*)(LPCTSTR)strId,
(wchar_t*)(LPCTSTR)strRangeVal); ...
我用fwrite试了也不行,写进去也是乱码。
请路过的朋友指教,谢谢了
。
for(int i = 1; i < nRowCnt; i++)
{
strRangePos.Format(L"F%d", i);
range = m_sheet.get_Range(COleVariant(strRangePos),COleVariant(strRangePos));
val = range.get_Text();
strRangeVal = val.bstrVal;
AfxMessageBox(strRangeVal); 能正常显示。但我将strRangeTimeout 写入文件中就显示乱码了。
FILE *fpLog;
fpLog = _wfopen(szPath,L"w");
if(!fpLog)
{
AfxMessageBox(L"failed");
fclose(fpLog);
return;
}
... fwprintf(fpLog,L"index=%d, Pos=%s,cID=%s,timeout=%s\n",id,
(wchar_t*)(LPCTSTR)strPos,
(wchar_t*)(LPCTSTR)strId,
(wchar_t*)(LPCTSTR)strRangeVal); ...
我用fwrite试了也不行,写进去也是乱码。
请路过的朋友指教,谢谢了
Unicode文件:格式就是前两个字节是0xFF,0xFE ,后面是Unicode格式的字符串。 你确认是不是乱码,可以再读出来看看,但如果你想在文档中正常显示Unicode,就在在文件头中加入两个字节是0xFF,0xFE