CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Location
    Cincinnati, Ohio, USA
    Posts
    28

    Excel Copy/Paste: Uregent

    I have some data which I'm showing in my UI (Sort of Grid ctrl). I would like to copy it into clip board and make it available to paste in an XLS. Can any one help me in this regard!! I would be grateful if any one can..

    Thanks
    Sunil


  2. #2
    Guest

    Re: Excel Copy/Paste: Uregent

    Don't know if this helps or not, but I display a graph chart on screen and allow the user to invoke Word and paste in a copy of the chart.

    _Application wd;
    Documents docs;
    _Document doc;
    VARIANT args1;
    VARIANT args2;
    VARIANT iconindex;
    VARIANT link;
    VARIANT placement;
    VARIANT displayasicon;
    VARIANT datatype;
    VARIANT iconfilename;
    VARIANT iconlabel;
    VARIANT direction;
    Range8 rng;
    long lRet = -1;

    VariantInit(&args1);
    VariantInit(&args2);

    VariantInit(&iconindex);
    VariantInit(&link);
    VariantInit(&placement);
    VariantInit(&displayasicon);
    VariantInit(&datatype);
    VariantInit(&iconfilename);
    VariantInit(&iconlabel);
    VariantInit(&direction);

    args1.vt = VT_ERROR;
    args2.vt = VT_ERROR;
    args1.scode = DISP_E_PARAMNOTFOUND;
    args2.scode = DISP_E_PARAMNOTFOUND;
    //args1 = VT_NULL;
    //args2 = VT_NULL);
    LPDISPATCH lpDisp;
    COleException e;

    BeginWaitCursor();

    wd.CreateDispatch("Word.Application.8", &e);
    wd.SetVisible(FALSE);
    lpDisp = wd.GetDocuments();
    docs.AttachDispatch(lpDisp);
    lRet = docs.GetCount();

    lpDisp = docs.Add(&args1, &args2);
    doc.AttachDispatch(lpDisp);
    lpDisp = doc.GetContent();
    rng.AttachDispatch(lpDisp);

    LPDISPATCH font;
    font = rng.GetFont();

    CString text = "\t\tCOMPARISON GRAPH Created: ";
    CString time_string = CTime::GetCurrentTime().Format("%B %d, %Y");

    text += time_string;
    text += "\n";

    rng.SetText(text);

    m_chart.EditCopy();

    V_VT(&direction) = VT_I4;
    V_I4(&direction) = 0;

    rng.Collapse(&direction);

    V_VT(&iconindex) = VT_I4;
    V_I4(&iconindex) = 0;

    V_VT(&link) = VT_BOOL;
    V_BOOL(&link) = FALSE;

    V_VT(&placement) = VT_I4;
    V_I4(&placement) = 0;

    V_VT(&displayasicon) = VT_BOOL;
    V_BOOL(&displayasicon) = FALSE;

    V_VT(&datatype) = VT_I4;
    V_I4(&datatype) = 3;

    BSTR bstr;
    bstr = SysAllocString(OLESTR("test"));

    V_VT(&iconfilename) = VT_BSTR;
    V_BSTR(&iconfilename ) = bstr;

    V_VT(&iconlabel) = VT_BSTR;
    V_BSTR(&iconlabel ) = bstr;

    rng.PasteSpecial(&iconindex,
    &link,
    &placement,
    &displayasicon,
    &datatype,
    &iconfilename,
    &iconlabel);

    text = "\n\t\t\t\t\tGraph Values\n";

    rng.InsertAfter(text);

    wd.SetVisible(TRUE);

    rng.ReleaseDispatch();
    doc.ReleaseDispatch();
    docs.ReleaseDispatch();
    wd.ReleaseDispatch();




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured