[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Copying data to clipboard (in Csv format)

Posted on 2002-06-19
Medium Priority
Last Modified: 2013-11-20
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"));
    CString text = _T("45,5,4\n2,1,1");
    sf.Write(text, text.GetLength());
    HGLOBAL hMem = sf.Detach();
    if (!hMem)
    pSource->CacheGlobalData(aFmt, hMem);

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 ?


Question by:yoavo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

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

    source = "123,25,341,50";
          HGLOBAL clipbuffer;
          char * buffer;
          clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1);
          buffer = (char*)GlobalLock(clipbuffer);
          strcpy(buffer, LPCSTR(source));

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..

Author Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

649 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