2016-12-06 7 views
0

나는 관련 질문 heretofore가 있고, 내가 사용하는 것입니다 거기에 대답 그 (거의) 작동 :관련 하위 행 (Aspose Cells)이 아닌 관련된 모든 행과 열을 어떻게 색칠 할 수 있습니까?

pt.ShowInCompactForm(); 

을 내가 생성 스프레드 시트에서 5 행에 걸쳐 항목의 블록이 존재를 - 첫 번째 행은 설명이며 그 아래의 네 줄은 해당 항목에 대한 세부 정보가있는 하위 행 (즉, "총 패키지", "총 구매", "평균 가격 합계"및 "총 백분율")입니다. 어떤 경우에는

, 그 지역에 세포를 색상 화 할 필요가 다음과 같은 코드로, 대부분의 경우,이 작업을 수행 할 수 있어요 :

private void ColorizeContractItemBlocks(List<string> contractItemDescs) 
{ 
    int FIRST_DESCRIPTION_ROW = 7; 
    int DESCRIPTION_COL = 0; 
    int ROWS_BETWEEN_DESCRIPTIONS = 5; 
    var pivot = pivotTableSheet.PivotTables[0]; 
    var dataBodyRange = pivot.DataBodyRange; 
    int currentRowBeingExamined = FIRST_DESCRIPTION_ROW; 
    int rowsUsed = dataBodyRange.EndRow; 

    pivot.RefreshData(); 
    pivot.CalculateData(); 

    PivotTable pt = pivotTableSheet.PivotTables[0]; 
    var style = workBook.CreateStyle(); 

    // Loop through PivotTable data, colorizing contract items 
    while (currentRowBeingExamined < rowsUsed) 
    { 
     Cell descriptionCell = pivotTableSheet.Cells[currentRowBeingExamined, DESCRIPTION_COL]; 
     String desc = descriptionCell.Value.ToString(); 

     if (contractItemDescs.Contains(desc)) 
     { 
      style.BackgroundColor = CONTRACT_ITEM_COLOR; 
      style.Pattern = BackgroundType.Solid; 

      CellArea columnRange = pt.ColumnRange; 
      // Using StartColumn-1 instead of StartColumn-1 gives me the "Percentage of Total" data field subrow (but not the others - "Total Packages", "Total Purchases", and "Sum of Average Price") 
      for (int c = columnRange.StartColumn-1; c <= columnRange.EndColumn; c++) 
      { 
       //pt.Format(currentRowBeingExamined-1, c, style); <= Instead of adding the "Description" row, this colors up some unrelated final ("Percentage of Total") data rows 
       pt.Format(currentRowBeingExamined, c, style); 
       pt.Format(currentRowBeingExamined + 1, c, style); 
       pt.Format(currentRowBeingExamined + 2, c, style); 
       pt.Format(currentRowBeingExamined + 3, c, style); 
      } 

     } 
     currentRowBeingExamined = currentRowBeingExamined + ROWS_BETWEEN_DESCRIPTIONS; 
    } 
} 

그러나 그것은 단지 대부분의 경우 "작동 , ""AVOCADOS, HASS 70 CT # 2 "와 같은"설명 "행 또는 0/A 열의 마지막 행을 색칠 할 수 없기 때문에"전체 백분율 "하위 행을 채울 수 있습니다 여기에서 볼 수 :

enter image description here

는 그것은 Descript, 이하 있다고 할 수있다 이온 행은 더 나은 untainted/unpainted 남아 있지만, 나는 아래 subrows 색칠하는 것이 좋을 것이라고 생각하고, 나는 왜 그들이되지 않습니다 이해가 안돼. 나는이 사용하여 착색되는 그 subrows의 ALL을 방지 할 수 있습니다

:

for (int c = columnRange.StartColumn; c <= columnRange.EndColumn; c++) 

을 (즉, "STARTCOLUMN-1"열 0에 아무 것도 방지 할 대신 "STARTCOLUMN"와 루프를 시작, 말을하는 것입니다/A는 색상으로 표시되지 않음). 그러나 한 컬럼 (0/A)에서 시작하면 마지막 서브 라인 만 색이됩니다.

답변