2009-07-15 9 views
0

내가C#을 AddChart 엑셀

Excel.Worksheet ws = 
      (Excel.Worksheet) Globals.ThisAddIn.GetActiveWorksheet(); 
Excel.Shape chart = 
      (Excel.Shape) ws.Shapes.AddChart(Type.Missing,100,100,100,100); 

를 다음과 같이이 가능 지금의 위의 차트에서 사각형을 가정 해 봅시다 추가하려면 C#에서 엑셀 차트를 추가하고 하이 예를 들어, 그래서 때

chart.Add(msoRectangle,100,100,100,100); // smth of this kind 

같은 차트를 끌면 차트 개체 (예 : 직사각형 위)가 차트와 함께 이동하고 편집 할 수 없게 할 수 있습니까? 고마워요!

+0

사각형이 무엇을 의미하며 Excel에서 바로이 작업을 수행 할 수 있습니까? –

+0

신경 쓰지 마, 내가 무슨 뜻인지 알아 –

답변

0

Chart.Shapes 컬렉션 컬렉션으로 이동하여 새로운 직사각형 셰이프를 추가해야합니다. VSTO에는 많은 문서가 없으므로 놀아야 만합니다. 그냥 차트를 보호 할 수있는 경우 그 읽기 only..I에 대한 지금

Excel.Shape rectangle = (Excel.Shape)chart.Chart.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 5, 5, 50, 50); 

는 잘 모르겠지만, 당신은 물론 차트에있는 전체 워크 시트를 보호 할 수 있습니다.

시트를 비밀번호로 보호하는 방법은 다음과 같습니다. 이는 완전한 보호입니다.

// 
this.ProtectWorkSheet(ws); 

//helper method 
private void ProtectWorkSheet(Excel.Worksheet workSheet) 
     { 
      //protect sheet 
      workSheet.Protect("yourpassword", true, true, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 
     } 
+0

Stan! –