2017-01-27 9 views

답변

1

IShape를. Select (...)은 모양을 선택하는 데 필요한 올바른 API입니다. "replace"매개 변수에 false이 전달 된 것을 확인합니다. 즉, 이미 선택된 다른 모양 (즉, 은 2 이상)에이 새 모양을 추가하는 것을 의미합니다. 현재 모양 선택을 바꾸려면 대신 true을 전달해야합니다.

다음은 시트에서 하나 이상의 셰이프를 선택하고 일부 Console.WriteLine (...)을 사용하여이 동작을 확인하는 샘플 코드이지만 SpreadsheetGear의 WorkbookView UI에서 이러한 동작을 볼 때이 동작을 확인했습니다. 제어 :

// Create a workbook and a couple shapes on the active worksheet. 
IWorkbook workbook = Factory.GetWorkbook(); 
IWorksheet worksheet = workbook.ActiveWorksheet; 
IShape shape1 = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, 5, 5, 50, 50); 
IShape shape2 = worksheet.Shapes.AddShape(AutoShapeType.Oval, 75, 57, 50, 50); 

// Ensure no shapes are selected. 
IShapeRange shapeSelection = worksheet.WindowInfo.ShapeSelection; 
Console.WriteLine($"ShapeSelection is null? {shapeSelection == null}"); 
// OUTPUT: ShapeSelection is null? True 

// Select shape1 ("Rectangle 1") 
shape1.Select(true); 
shapeSelection = worksheet.WindowInfo.ShapeSelection; 
Console.WriteLine($"ShapeSelection: Count={shapeSelection.Count}, Name[0]={shapeSelection[0].Name}"); 
// OUTPUT: ShapeSelection: Count=1, Name[0]=Rectangle 1 

// Select shape2 ("Oval 2") 
shape2.Select(true); 
shapeSelection = worksheet.WindowInfo.ShapeSelection; 
Console.WriteLine($"ShapeSelection: Count={shapeSelection.Count}, Name[0]={shapeSelection[0].Name}"); 
// OUTPUT: ShapeSelection: Count=1, Name[0]=Oval 2 

// Select both shapes (false passed into IShape.Select(...)) 
shape1.Select(false); 
shapeSelection = worksheet.WindowInfo.ShapeSelection; 
Console.WriteLine($"ShapeSelection: Count={shapeSelection.Count}, Name[0]={shapeSelection[0].Name}, Name[1]={shapeSelection[1].Name}"); 
// OUTPUT: ShapeSelection: Count=2, Name[0]=Oval 2, Name[1]=Rectangle 1