Solved

Copying data to clipboard (in Csv format)

Posted on 2002-06-19
4
536 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 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