본문 바로가기
개발/Visual C++

Excel Automation Shape Grouping 방법

by belitino 2013. 9. 3.

출처: http://forums.codeguru.com/showthread.php?214676-Select-shapes-with-Excel-automation

 

Excel Automation으로 Shape들을 Grouping 하는 방법입니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
CApplication app;
 
// Start Excel and get an Application object.
   if(!app.CreateDispatch(TEXT("Excel.Application")))
   {
      AfxMessageBox(TEXT("Couldn't start Excel and get Application object."));
      return;
   }
    
    CWorkbooks books;
    CWorkbook book;
    CWorksheets sheets;
    CWorksheet sheet;
    CRange range;
    CFont0 font;
 
    books = app.get_Workbooks();
   book = books.Add (covOptional);
 
 
   //Get the first sheet.
   sheets =book.get_Sheets();  
   sheet = sheets.get_Item(COleVariant((short)1));   
 
 
   // Add Shapes
   CShapes    Shapes;
   CShape    Shape;
 
   Shapes = sheet.get_Shapes();
   
   Shape = Shapes.AddShape(21, 10, 10, 100,100 );
   Shape.put_Name(_T("aaa"));
   Shape = Shapes.AddShape(22, 30, 30, 100,100 );
   Shape.put_Name(_T("bbb"));
   Shape = Shapes.AddShape(23, 50, 50, 100,100 );
   Shape.put_Name(_T("ccc"));
 
   Shape = Shapes.Item(COleVariant(TEXT("aaa")));
   Shape.Select(covFalse);
   Shape = Shapes.Item(COleVariant(TEXT("bbb")));
   Shape.Select(covFalse);
   Shape = Shapes.Item(COleVariant(TEXT("ccc")));
   Shape.Select(covFalse);
   
   CShapeRange    ShapeRange ;
   ShapeRange = app.get_Selection();
   ShapeRange.Group();