我录了宏,他是用worksheet.paste来完成的.但里面的两个参数我不知如何设置?请高手指点.

解决方案 »

  1.   

    看看这个是否能解决你的问题:
    http://www.codeguru.com/cpp/data/mfc_database/microsoftexcel/comments.php/c11745/?thread=9903
      

  2.   

    //复制一片区域,然后粘贴,再进行扩展走向设定,Paste 1:复制部分向右移动,2:复制部分向下移动,3:整体向下,4:整体向右
    void COperatorExcel::CopyArray(CString copy_begin,CString copy_end,int PasteType)
    {
    //先插入.....再复制,后粘贴...... int nRow1,nRow2;
    int nCol1,nCol2; this->GetIntCoordinate(copy_begin,nCol1,nRow1); //获得相关的坐标
    this->GetIntCoordinate(copy_end,nCol2,nRow2); this->range = this->sheet.get_Range(COleVariant(copy_begin),COleVariant(copy_end));
    range.Select(); VARIANT var_insert;
    var_insert.vt = VT_I4;
    var_insert.intVal = PasteType;
    range.Insert(var_insert,covOptional); //插入,插入后复制,求插入后的坐标

    int nRow3,nCol3;
    int nRow4,nCol4;
    if(PasteType == 1 || PasteType == 4) //向右插入的时候坐标变化
    {
    int nCols = nCol1 - nCol2;
    if(nCols <0)
    nCols *=-1;

    nRow3 = nRow1;
    nRow4 = nRow2; nCol3 = nCol1 + nCols +1;
    nCol4 = nCol2 + nCols +1; }
    else if(PasteType == 2 || PasteType == 3)
    {
    int nRows = nRow1 - nRow2;
    if(nRows < 0)
    nRows *= -1; nCol3 = nCol1;
    nCol4 = nCol2; nRow3 = nRow1 + nRows +1;
    nRow4 = nRow2 + nRows +1;
    } //新得的坐标转换
    CString newX1,newX2; this->GetStringCoordinate(newX1,nCol3,nRow3);
    this->GetStringCoordinate(newX2,nCol4,nRow4); //插入过后就是复制过来粘贴在新的位置上了。 
    range = this->sheet.get_Range(COleVariant(newX1),COleVariant(newX2));
    range.Select(); range.Copy(covOptional); //复制 range = this->sheet.get_Range(COleVariant(copy_begin),COleVariant(copy_end));
    range.Select(); VARIANT var_paste;
    var_paste.vt = VT_DISPATCH;
    var_paste.pdispVal = range.DetachDispatch(); sheet.Paste(var_paste,covOptional);
    this->m_ExcelApplication.put_CutCopyMode(false); //设置粘贴模式.....不可复制模式}
    Excel内单元格内容复制的格式,应该改改就可以用了吧~:)
      

  3.   

    谢谢二位的回复,第一个类不全,没法用.第二个有个covOptional找不到这个变量.
      

  4.   

    http://www.codeproject.com/com/ComExcelImages.asp
      

  5.   

    //读剪贴板
    char * buffer;
    HWND p=FindWindow("OpusApp",NULL);
    if (p!=NULL&&::OpenClipboard(p) )
    {
       HANDLE hData = GetClipboardData(CF_TEXT);
       buffer = (char*)GlobalLock(hData);
       /*******************************************/
       /*   buffer就是从剪贴板中读出来的内容      */
       /*   在这里对buffer进行操作                */
       /*******************************************/
       GlobalUnlock(hData);
       CloseClipboard();
    }//写剪贴板
    char * buffer;
    HGLOBAL hMem;
    HWND p=FindWindow("OpusApp",NULL);
    if(p!=NULL&&::OpenClipboard(p))
    {
       hMem=::GlobalAlloc(GMEM_SHARE,50);
       buffer=(char *)::GlobalLock(hMem);
       /*******************************************/
       /*   buffer就是要往剪贴板里写的内容        */
       /*   在这里对buffer进行操作                */
       /*   strcpy(buffer,"ReadClipboard");       */
       /*******************************************/
       ::SetClipboardData(CF_TEXT,hMem);
       ::GlobalUnlock(hMem);
       ::CloseClipboard();
    }
    ::GlobalFree(hMem);//清空剪贴板
    HWND p=FindWindow("OpusApp",NULL);
    if(p!=NULL&&::OpenClipboard(p))
    {
       ::EmptyClipboard();
       ::CloseClipboard();
    }
      

  6.   

    下载代码,看看这一段:void CExcelImagesDlg::InsertPictures ()
    {
    POSITION pos;
    CWorksheets sheets;
    CWorksheet sheet;
    CRange range;
    CPicture pic;
    CPictures pics;
    CBorder border; // eliminate old pictures
    sheet = m_book.get_ActiveSheet();
    pics = sheet.Pictures(m_covOptional);
    pics.Cut(); // get pointer to the first image
    pos = m_editImageNames.GetStartPosition (); // insert first picture and put a border on it
    range = sheet.get_Range(COleVariant("A1"), COleVariant("A1"));
    range.Select ();
    pic = pics.Insert (m_editImageNames.GetNextPathName(pos), m_covOptional);
    border = pic.get_Border ();
    border.put_Weight(COleVariant(xlBorderWeightThin)); // get cell height
    VARIANT var = range.get_Height ();
    double d = var.dblVal; // get picture height (in cell units)
    double w = pic.get_Width ();
    double h = pic.get_Height (); // in row height units
    int cells = (int) (h/d);
    cells += ((h/d - cells) > 0); // insert remaining pictures
    CString cell;
    int row = cells + 1;
    while (pos)
    {
    cell.Format ("A%d", row);
    range = sheet.get_Range(COleVariant(cell), COleVariant(cell));
    range.Select();
    pic = pics.Insert (m_editImageNames.GetNextPathName(pos), m_covOptional);
    border = pic.get_Border ();
    border.put_Weight(COleVariant(xlBorderWeightThin)); // get picture height (in cell units)
    w = pic.get_Width ();
    h = pic.get_Height (); // in row height units
    cells = (int) (h/d);
    cells += ((h/d - cells) > 0); // set next insertion row
    row += cells;
    } // jump to the top of the sheet
    range = sheet.get_Range(COleVariant("A1"), COleVariant("A1"));
    range.Show ();
    }
      

  7.   

    完整的项目在这里:
    http://www.codeguru.com/cpp/data/mfc_database/microsoftexcel/article.php/c11745/
    http://www.codeguru.com/dbfiles/get_file/XLAutomationDemo_2.zip?id=11745&lbl=XLAUTOMATIONDEMO_2_ZIP&ds=20060425
      

  8.   

    wsMysheet.Paste(vtMissing,vtMissing);我用默认参数可以传过图像去.
    多谢各位.我再看看你们提供的.
      

  9.   

    在头部定义下COleVariant
          covTrue((short)TRUE),
          covFalse((short)FALSE),
          covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);