Solved

Copying data to clipboard (in Csv format)

Posted on 2002-06-19
4
526 Views
Last Modified: 2013-11-20
Hi,
I'm trying to copy data to clipboard in Csv format.
This is my code:

void CMyDialog1::OnCopy()
{
    COleDataSource* pSource = new COleDataSource();
    UINT aFmt = ::RegisterClipboardFormat(_T("Csv"));
    CSharedFile     sf(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);
    CString text = _T("45,5,4\n2,1,1");
    sf.Write(text, text.GetLength());
    HGLOBAL hMem = sf.Detach();
    if (!hMem)
     return;
    pSource->CacheGlobalData(aFmt, hMem);
    pSource->SetClipboard();
}

Now, when I'm trying to paste to excel, I do not get 6 cells as I expected (with values: 45 5 4 2 1 1).
What I get is only one cell with the value "4" (which is probably the prefix of "45", because when I replace the "45" in the code to "78" I get one cell with "7").

Can someone please help me with this ?

thanks,
Yoav.



0
Comment
Question by:yoavo
4 Comments
 
LVL 4

Accepted Solution

by:
mblat earned 100 total points
ID: 7093299
The following works for me

    source = "123,25,341,50";
     if(OpenClipboard())
     {
          HGLOBAL clipbuffer;
          char * buffer;
          EmptyClipboard();
          clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1);
          buffer = (char*)GlobalLock(clipbuffer);
          strcpy(buffer, LPCSTR(source));
          GlobalUnlock(clipbuffer);
          SetClipboardData(CF_TEXT,clipbuffer);
          CloseClipboard();
     }


One note I am using Excel 2000 and to make it work I had to go to Data->Text To Column then Next and make sure that Comma chosen as seprator.

Hope it helps..
0
 

Author Comment

by:yoavo
ID: 7095019
I found my problem. It was because my application is build with UNICODE...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question