Solved

Copying data to clipboard (in Csv format)

Posted on 2002-06-19
4
535 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
[X]
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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

740 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