Board index » cppbuilder » Save StringGrid to Clipboard

Save StringGrid to Clipboard

Is there a way to save the contents of a Builder 5 StringGrid to the system
clipboard to allow the user to paste the results into Excel?

Thanks for any help
Weisen

 

Re:Save StringGrid to Clipboard


Quote
On Wed, 11 Jul 2001 13:02:31 -0400, "Weisen" <b...@msgerber.com> wrote:

>Is there a way to save the contents of a Builder 5 StringGrid to the system
>clipboard to allow the user to paste the results into Excel?

>Thanks for any help

Hi Weisen

#include <ClipBrd.hpp>

void __fastcall SaveSelectedToClipboard( TStringGrid* StringGrid )
{
    const int StartCol( StringGrid->Selection.Left );
    const int EndCol( StringGrid->Selection.Right );
    const int StartRow( StringGrid->Selection.Top );
    const int EndRow( StringGrid->Selection.Bottom );

    AnsiString Result;

    for ( int Row( StartRow ) ; Row <= EndRow ; ++Row ) {
        if ( Row != StartRow )
            Result += "\r\n";
        for ( int Col( StartCol ) ; Col <= EndCol ; ++Col ) {
            if ( Col != StartCol )
                Result += "\t";
            Result += "\"" + StringGrid->Cells[Col][Row] + "\"";
        }
    }
    Clipboard()->AsText = Result;

Quote
}

HTH

Ciao!

Giuliano

Other Threads