2016-11-29 1 views
0

Je peux trier (décroissant) mes résultats affichés par une valeur sélectionnée en utilisant ce code:Comment masquer les plages sélectionnées ET trier les résultats affichés (Aspose Cells)?

PivotField field = pivotTable.RowFields[0]; 
field.IsAutoSort = true; 
field.IsAscendSort = false; 
field.AutoSortField = 1; 

C'est ce que je vois (Total des achats affichés sont en effet montrés du plus au moins):

enter image description here

Ou, je ne peux afficher description de plages dont le "pourcentage du total" valeur est d'au moins 1% avec ce code:

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; 
    } 
} 

... comme ceci:

enter image description here

... mais je ne peux pas les deux à travailler en même temps. Donc, je peux soit masquer les descriptions avec moins de 1% de la percntage OU je peux trier par nombre total d'achats décroissant, mais je ne suis pas capable d'accomplir les deux en même temps. Mon code pour essayer d'accomplir à la fois est la suivante:

. . . 
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); 

Il est comme si l'ordre de tri n'est pas respectée lors de l'appel HideItemsWithFewerThan1PercentOfSales() - les numéros de ligne cette méthode « voit » ne sont pas les numéros de ligne selon le tri qui a été établi.

Comment puis-je faire fonctionner à la fois le tri et la dissimulation?

REMARQUE: Appel de HideItemsWithFewerThan1PercentOfSales(); avant le code de tri ne fonctionne pas - il montre encore/cache certaines des mauvaises choses.

Répondre

1

Veuillez vérifier la réponse dans ce thread dans le forum Aspose.Cells.

Note: Je travaille comme évangéliste Developer à Aspose