2016-11-29 6 views
0

내가 정렬 할 수 있습니다이 코드를 사용하여 선택한 값으로 내 표시되는 결과를 (내림차순)선택한 범위를 숨기고 표시된 결과를 정렬하려면 어떻게합니까 (Aspose 셀)? 이것은 내가 (표시 총 구매 실제로 적어도 대부분의에서 도시)를 참조하십시오 것입니다</p> <pre><code>PivotField field = pivotTable.RowFields[0]; field.IsAutoSort = true; field.IsAscendSort = false; field.AutoSortField = 1; </code></pre> <p>:

enter image description here

private void HideItemsWithFewerThan1PercentOfSales() 
{ 
    int FIRST_TOTAL_PRICE_ROW = 8; 
    int ROWS_BETWEEN_PERCENTAGES = 4; 
    var pivot = pivotTableSheet.PivotTables[0]; 
    var dataBodyRange = pivot.DataBodyRange; 
    int currentRowBeingExamined = FIRST_TOTAL_PRICE_ROW; 
    int rowsUsed = dataBodyRange.EndRow; 

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

    // Get grand total of purchases for all items and months, and calculate what 1% of that is 
    Cell totalTotalPurchasesCell = pivotTableSheet.Cells[rowsUsed - 2, _grandTotalsColumnPivotTable + 1]; 
    double totalTotalPurchases = Convert.ToDouble(totalTotalPurchasesCell.Value); 
    var onePercentOfTotalPurchases = totalTotalPurchases/100; 

    // Loop through PivotTable data, hiding where percentage < 0.01 (1%) 
    while (currentRowBeingExamined < rowsUsed) 
    { 
     Cell priceCell = pivotTableSheet.Cells[currentRowBeingExamined, _grandTotalsColumnPivotTable + 1]; 
     String priceStr = priceCell.Value.ToString(); 
     Double price = Convert.ToDouble(priceStr); 
     if (price < onePercentOfTotalPurchases) 
     { 
      pivotTableSheet.Cells.HideRows(currentRowBeingExamined - 1, ROWS_BETWEEN_PERCENTAGES); 
     } 
     currentRowBeingExamined = currentRowBeingExamined + ROWS_BETWEEN_PERCENTAGES; 
    } 
} 
:

또는 난 단지 설명을 표시 할 수 있습니다 값이 코드 적어도 1 % 누구의 "비율 전체의"범위 그래서 같은

... :

enter image description here

...하지만 그들 모두가 동시에 동작하지 않습니다. 그래서 나는 percntage의 1 % 미만으로 Descriptions를 숨길 수 있습니다. 또는 Total Purchases를 내림차순으로 정렬 할 수는 있지만, 동시에 두 가지를 모두 수행 할 수는 없습니다. 내 코드는 다음과 같이 모두가 달성하려고 : HideItemsWithFewerThan1PercentOfSales()가 호출 될 때 그것은 정렬 순서가 존중되지 않는 것처럼

. . . 
pivotTable.AddFieldToArea(PivotFieldType.Row, DESCRIPTION_COLUMN); 
pivotTable.RowHeaderCaption = "Description"; 

// Dragging the second field to the column area. 
pivotTable.AddFieldToArea(PivotFieldType.Column, MONTHYR_COLUMN); 
pivotTable.ColumnHeaderCaption = "Months"; 

// Dragging the third field to the data area. 
pivotTable.AddFieldToArea(PivotFieldType.Data, TOTALQTY_COLUMN); 
pivotTable.DataFields[0].DisplayName = "Total Packages"; 

pivotTable.AddFieldToArea(PivotFieldType.Data, TOTALPRICE_COLUMN); 
pivotTable.DataFields[1].DisplayName = "Total Purchases"; 
. . . 

// Sort by "Total Purchases" descending 
PivotField field = pivotTable.RowFields[0]; 
field.IsAutoSort = true; 
field.IsAscendSort = false; 
field.AutoSortField = 1; // This is the "Total Purchases" field 

pivotTable.PivotTableStyleType = PivotTableStyleType.PivotTableStyleLight16; 

pivotTable.RefreshDataFlag = true; 
pivotTable.RefreshData(); 
pivotTable.CalculateData(); 
pivotTable.RefreshDataFlag = false; 

List<String> contractItemDescs = GetContractItemDescriptions(); 
ColorizeContractItemBlocks(contractItemDescs); 
HideItemsWithFewerThan1PercentOfSales(); 
FreezePanePivotTable(HEADER_ROW, 2); 
FormatPivotTableNumbers(); 
ConfigureForPrinting(pivotTableSheet.Cells.Rows.Count); 

- 방법은 "인식"하는 행 번호를 행 번호에 따라되지 않습니다 정렬이 확립되었습니다.

정렬 및 숨기기를 모두 작동 시키려면 어떻게해야합니까?

참고 : HideItemsWithFewerThan1PercentOfSales(); 정렬 코드 이전에는 코드가 작동하지 않습니다 - 잘못된 것을 보여 주거나 숨 깁니다.

답변

1

Aspose.Cells 포럼의 thread에있는 답장을 확인하십시오.

참고 : 내가 Aspose에서 개발자 전도사로 일하고 있어요