Solved

Copying data to clipboard (in Csv format)

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countEvens challenge 2 112
twoTwo  challenge 35 108
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 887
Problem to Office 1 18
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

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