Q&A

  • 엑셀에서 도형을 그리고 그려진 도형들을 선택하고 그룹을 만들면 아래와 같은 코드(메크로)로 만들어 집니다.
엑셀에서 도형을 그리고 그려진 도형들을 선택하고 그룹을 만들면  아래와 같은 코드(메크로)로 만들어 집니다.
     ActiveSheet.Shapes.Range(Array("Rectangle 1", "Rectangle 3", "Rectangle 4")).Select
    Selection.ShapeRange.Group.Select




위 부분을 Delphi로 변경하는 방법 아시면 알려 주시면 감사하겠습니다.
1  COMMENTS
  • Profile
    이현남 2004.06.24 02:39
    oSh.Shapes.Range[VarArrayOf([2, 3, 4])].Group;
    또는
    oSh.Shapes.Range[VarArrayOf(['Text box 1','Textbox 2','Text box 3'])].Group;
    또는 아래 소스를 참조하시기 바랍니다.

    procedure TfrmTact2Excel.drawTactRemark;


    var
      sSql : String;
      iLeft, iTop, lastCol : LongInt;
    //  shapeArr : Array of variant;
      idx : Integer ;
      oShape : variant;
      arrV : Variant;
    //   arrStrList : TStringList;

    begin
      sSql := ' select tactno, tactnm, txtcolor, backcolor ' +
             '   from TCTLISTT ' +
             '  order by ord ';

      lastCol := oSh.Cells.Item[FORM_DRAWINFO_ROW, FORM_DRAWINFO_COL].Value;

      oSh.Range[oSh.Cells.Item[1, lastCol + 1], oSh.Cells.Item[1, lastCol + 1]].ColumnWidth := 26;
      iTop := oSh.Range[oSh.Cells.Item[FORM_ST_ROW + FORM_MILESTONE_REF_ROW, 1], oSh.Cells.Item[FORM_ST_ROW + FORM_MILESTONE_REF_ROW, 1]].Top;
      iLeft := oSh.Range[oSh.Cells.Item[1, lastCol + 1], oSh.Cells.Item[1, lastCol + 1]].Left;

      oShape := oSh.Shapes.AddTextbox(msoTextOrientationHorizontal, iLeft, iTop, TACT_WIDTH + DESC_WIDTH, TACT_HEIGHT);
      oShape.AlternativeText := 'Tact_Remark';
      oShape.TextFrame.Characters.Text := '범  례';
      oShape.TextFrame.HorizontalAlignment := xlCenter;
      oShape.TextFrame.VerticalAlignment := xlCenter;
      oShape.TextFrame.AutoSize := False;
      oShape.TextFrame.Characters.Font.Size := TACT_FONT_SIZE;
      oShape.TextFrame.Characters.Font.Bold := True;
      oShape.Fill.ForeColor.RGB := RGB(255, 255, 100);
      oShape.Fill.Solid;
      oShape.Placement := xlMove;

      AdoGetQuery (gPjtDB, sSql, gTempEvd);

      arrV := VarArrayCreate([0,gTempEvd.RecordCount*2],varVariant);
      arrV[0] := oSh.Shapes.Item(oSh.Shapes.Count).Name;

      idx := 1;

      gTempEvd.First;

      while not gTempEvd.Eof do
      begin
        iTop := iTop + TACT_HEIGHT;
        oShape := oSh.Shapes.AddTextbox(msoTextOrientationHorizontal, iLeft, iTop, TACT_WIDTH, TACT_HEIGHT);
        oShape.AlternativeText := 'Tact_Remark';
        oShape.TextFrame.Characters.Text := gTempEvd.FieldByName('tactno').AsString;
        oShape.TextFrame.HorizontalAlignment := xlCenter;
        oShape.TextFrame.VerticalAlignment := xlCenter;
        oShape.TextFrame.AutoSize := False;
        oShape.TextFrame.Characters.Font.Size := TACT_FONT_SIZE;
        oShape.TextFrame.Characters.Font.Bold := True;

        oShape.Fill.ForeColor.RGB := StrToInt('$'+gTempEvd.FieldByName('backcolor').AsString);
        oShape.TextFrame.Characters.Font.Color := TColor(StrToInt('$'+gTempEvd.FieldByName('txtcolor').AsString));

        oShape.Fill.Solid;
        oShape.Placement := xlMove;

        arrV[idx] :=  oSh.Shapes.Item(oSh.Shapes.Count).Name;

        oShape := oSh.Shapes.AddTextbox(msoTextOrientationHorizontal, iLeft + TACT_WIDTH, iTop, DESC_WIDTH, TACT_HEIGHT);
        oShape.AlternativeText := 'Tact_Remark';
        oShape.TextFrame.Characters.Text := gTempEvd.FieldByName('tactnm').AsString;
        oShape.TextFrame.HorizontalAlignment := xlCenter;
        oShape.TextFrame.VerticalAlignment := xlCenter;
        oShape.TextFrame.AutoSize := False;
        oShape.TextFrame.Characters.Font.Size := TACT_FONT_SIZE;
        oShape.TextFrame.Characters.Font.Bold := false;
        oShape.Fill.ForeColor.RGB := RGB(255, 255, 255);
        oShape.Fill.Solid;
        oShape.Placement := xlMove;


        arrV[idx+1] :=  oSh.Shapes.Item(oSh.Shapes.Count).Name;
        idx := idx + 2;
        gTempEvd.Next;

      end;

      gTempEvd.Close;


    //  oSh.Shapes.Range[VarArrayOf([2, 3, 4])].Group;
      oSh.Shapes.Range[arrV].Group;

    End;