2009-09-16 3 views

답변

1

나는 많은 시도 끝에 해결책을 스스로 발견했다. 이 솔루션은 이상적이지는 않지만 작동에있어 솔기가 있습니다.

다음
private void CellsChange(Excel.Range Target) 
{ 
    if ((this.Application.Selection as Excel.Range) != null) 
    { 
     Excel.Range selectedRange = thisAddIn.Application.Selection as Excel.Range; 
     if (selectedRange.Rows.Count > 1) 
     { 
      //put your code to handle autofill here 
     } 
    } 
} 
1

내가 determmine 방법을 하나의 세포가 변경된 경우 또는 :

displayWorksheet.Change += new Excel.DocEvents_ChangeEventHandler(CellsChange); 

은 다음과 같이해야 처리 할 수있는 방법

하면 워크 시트 변경 이벤트를 처리해야합니다 셀의 범위를 붙여 넣거나 값을 드래그하여 배수를 지정하십시오.

//Get the currentCell/s changed 
     object missing = System.T 
     string currentCell = Target.get_Address(
     missing, missing, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, missing, missing); 


//Split the currentCell variable this aids the logic in getting cell letter and number 
     char[] delimiter = new char[] {'$'}; 
     string[] CellSplit = currentCell.Split(delimiter); 


//try parse the value in position 1 if this is true then a whole sheet has been pasted and needs to be checked 
     //usually will be false if 1 cell is changed or multiple by dragging 
     Int32 int32Val; 
     bool result; 
     result = Int32.TryParse(CellSplit.GetValue(1).ToString).Replace":", ""),System.Globalization.NumberStyles.Integer, null, out int32Val); 

    //check the length of the array as this will help in determining how the cells have been changed 
     int numCellSplit = CellSplit.Length; 

    //the result is false if a single cell was changed and the length is 3 
     if (CellSplit.Length == 3 && result == false) 
     { 
      \\your code here 
     } 
    //the result is true if the whole sheet has been pasted 
     if (CellSplit.Length == 3 && result == true) 
     { 
      \\your code here 
     } 

    //if the user dragged the data from one cell across others 
     if (CellSplit.Length == 5 && result == false) 
     { 
      //create char arrays to get the Alphabetical letters to use to loop 
      char[] FirstLetter = CellSplit.GetValue(1).ToString().ToCharArray(); 
      char[] SecondLetter = CellSplit.GetValue(3).ToString().ToCharArray(); 

      int Alphaletter = (char)FirstLetter.GetValue(0); 
      int Betaletter = (char)SecondLetter.GetValue(0); 
      //Alphabetical letters have an int value so they can be used to loop through the cells 
      for (int CellCheck = Alphaletter; CellCheck <= Betaletter; CellCheck++) 
      { 
       int LoopStart = int.Parse(CellSplit.GetValue(2).ToString().Replace(":", "")); 
       int LoopEnd = int.Parse(CellSplit.GetValue(4).ToString()); 

       for (; LoopStart <= LoopEnd; LoopStart++) 
       { 

        //your code here       
       } 
      } 

     } 

이것은 세포가 어떻게 바뀌 었는지를 결정하는 어떤 방법으로 도움이된다.

Deezos