本文介绍了关于VC将剪贴板数据导入Excel的问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从其他程序得到一个字符串.然后我将其放入剪贴板.
在字符串中,数据之一使用"\ r \ n"作为分隔符.所以我的问题如下:
我想将字符串导入excel的一列,我的代码:
I get a string from other program. Then I put it into the Clipboard.
In the String one of the data use "\r\n" as separator. So my problem as follows:
I want the string import a column of excel ,my codes :
Sheets sheets = m_wb.GetSheets();
_Worksheet ws = sheets.GetItem(KK_OleVariant(long(nSheetIndex + 1)));
range = ws.GetCells();
range.SetColumnWidth(KK_OleVariant((long)200));
if(OpenClipboard(NULL))
{
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, nBuflen);
if (NULL == hMem)
{
CloseClipboard();
return 0;
}
LPTSTR lpStr = (LPTSTR)GlobalLock(hMem);
memcpy(lpStr, strTxtBuf, nBuflen);
GlobalUnlock(hMem);
HANDLE hData = SetClipboardData(CF_UNICODETEXT,(HANDLE)hMem);
if(NULL == hData)
return 0;
range.Select();
range.PasteSpecial(XLPASTEALL, XLPASTESPECIALOPERATIONNONE,
KK_OleVariant((long)FALSE), KK_OleVariant((long)FALSE));
该程序将在range.PasteSpecial崩溃.
我不知道如何在VC中使用PasteSpecial,
亲爱的朋友们,帮我讨论这个问题.
the program will be crash at range.PasteSpecial.
I don''t know how to use the PasteSpecial in VC,
Dear friends, help me discuss this problem. thanks.
推荐答案
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, nBuflen * sizeof(TCHAR));
...
memcpy(lpStr, strTxtBuf, nBuflen * sizeof(TCHAR));
range.PasteSpecial(XLPASTEALL, XLPASTESPECIALOPERATIONNONE, KK_OleVariant((long)FALSE), KK_OleVariant((long)FALSE));
是对的吗?
is right ?
这篇关于关于VC将剪贴板数据导入Excel的问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!