I am using aspose-cells-17.9 java version. I am trying to create a pivot table from the raw data sample shown below.
Affiliate ImpressionClicks
abc 1000 2000
and so on.
If i try to create pivot table with the following code
PivotTable pivotTable = pivotTables.get(index);
// Unshowing grand totals for rows.
pivotTable.setRowGrand(true);
// Dragging the first field to the row area.
pivotTable.addFieldToArea(PivotFieldType.ROW, 0);
// Dragging the second field to the column area.
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 1);
// Dragging the third field to the data area.
pivotTable.addFieldToArea(PivotFieldType.DATA, 2);
I am getting the following output as selected values.
But what I am expecting is as follows
Any help would be appreciated.
Please see the following sample code, its comments and screenshot. As you can see in screenshot, the output Excel file has the pivot table as per your needs. Please remember Σ-values field is represented by PivotTable.getDataField() and this is the change I have made in your code.
Java
PivotTable pivotTable = pivotTables.get(index);
// Unshowing grand totals for rows.
pivotTable.setRowGrand(true);
// Dragging the first field to the row area.
pivotTable.addFieldToArea(PivotFieldType.ROW, 0);
// Dragging the second field to the data area.
pivotTable.addFieldToArea(PivotFieldType.DATA, 1);
// Dragging the third field to the data area.
pivotTable.addFieldToArea(PivotFieldType.DATA, 2);
// Dragging the Σ-values field to the column area.
pivotTable.addFieldToArea(PivotFieldType.COLUMN, pivotTable.getDataField());
Screenshot
Note: I am working as Developer Evangelist at Aspose
Related
I have two columns:
ID country
1 spain
1 france
1 sweeden
2 mexico
how to concat all the countries with ID 1 and send them to another column like this
ID2 country2
1 spainfrancesweeden
How to do this with an excel formula instead of a VBA code.
I tried this:
=CONCATENATE(VLOOKUP(A18; Hoja2!A19:Hoja2!B24; 2; 1); " ";VLOOKUP(A18; Hoja2!A19:Hoja2!B24; 2; 0))
But it only gets two results (but there are 3)
Layout of sheet:
Do convert your data to table and insert pivot table, on the screen of create pivot table check the option add this data to the data model, now go to pivot table fields and right click on the table name and click on add measure. There would be a window opened in the name of Measure in which you put the measure name and value description as per your choice. Now come to formula area which would start with = sign there you type below formula concatenatex(table1,table1[country],","). Now one additional function would had created in the area of pivot table fields. Now you can drag id into rows and drag the created function into Values. It would show the desired result as follows.,
Row Lables|Joincountry
1 |Spain,France,Sweedan
2 |Mexico
Hope this is order and would help you.
!
[result]1
Using Excel 2013, I would like to apply a Top 10 Filter to a pivot and also apply a filter to an additional values field. Is this possible?
I would like to filter off all 1's from Sum of Individual Claims Column, but still have the top 10 by average of % of claims (minus the claim volumes that were only 1).
Table 1 with 1's in Sum of Individual Claims Column
The resulting table should look like this.
I found a workaround to use multiple filters in a pivot table, by using a helper column in the source data. Here is a step by step approach you can adjust for your needs.
Step 1: Add Helper Columns to the data source with a new heading and any constant value in every row. (You need one helper column per extra filter. If you want to use 2 filters, you need one helper column)
Step 2: Add the Helpercolumn attributes to your row-fields of the pivot table.
Step 3: Choose the tabular layout where all row attributes are in one row.
Step 4: Now you can apply different filters, one for each attribute in the row-field. In your case: the top 10 filter for the "Heading 1" and an unequal filter to "Help 1". This will yield the same result as if you use multiple filters for the "Heading 1".
Step 5: If you now apply this to VBA, the code could look like this:
Dim pvt As PivotTable
Set pvt = ActiveSheet.PivotTables("PivotTable1")
ActiveSheet.PivotTables("PivotTable1").AllowMultipleFilters = True
With pvt.PivotFields("Heading 1")
.ClearAllFilters
.PivotFilters. _
Add2 Type:=xlTopCount, DataField:=ActiveSheet.PivotTables("PivotTable1"). _
PivotFields("Average of Heading 2"), Value1:=10
End With
With pvt.PivotFields("Help 1")
.ClearAllFilters
.PivotFilters.Add2 _
Type:=xlValueDoesNotEqual, DataField:=ActiveSheet.PivotTables("PivotTable1" _
).PivotFields("Sum of Heading 3"), Value1:=1
End With
If you need to apply multiple value filters to the same field in a pivot table, the easiest way to do that is as follows:
Add a column with identical values to the Source Data and add an index to its name. E.g. I had Hospital column and created its clone named Hospital 2
Change the Source Data to make sure the new column is included.
Refresh your pivot.
Put the new column clone (i.e. Hospital 2 in our case) into ROWS window of the PivotTable Fields tab.
Make sure that all fields in Columns window in PivotTable Fields tab have the following settings:enter image description here
Now you can apply 2 different value filters to the old and new identical columns!!!
If you don't need to see the newly added clone column, just hide it.
That's it!!!
Add Individuals Claims to the Filters pane in the Pivot Fields Area.
A filter will appear in your above your Pivot table. Add unselect the value 1.
Now go to the Row Labels dropdown button and select Value Filters, then Top N...:
In the highlighted in red option select your Average of % of Claims measure.
I've exported a DevExpress grid in Excel. I want to be able to apply Excel filters on exported Excel sheet. Right now, the Excel export only allows me to apply filters on values between dark grey rows (rows that already have sums in them). See pics.
(Could this be because of the cell merge that happened in the formatting?)
I'm using a the following method to export:
Using link As New PrintableComponentLink(New PrintingSystem())
Dim options As New XlsxExportOptionsEx
options.ExportType = DevExpress.Export.ExportType.DataAware
options.TextExportMode = TextExportMode.Value 'Should set to Value to be able to have the numbers displayed as numbers instead of text.
options.AllowCellMerge = DefaultBoolean.False
link.Component = gcInvisibleDetail
link.CreateDocument(link.PrintingSystem)
link.ExportToXlsx(tbRepertoire.Text & "\Charges.xlsx", options)
End Using
The filter Cannot be apply to whole columns because there is a small indents on the top and at the bottom within the group footer row 7,9,15 and 17 in your example, empty rows in Excel emulate these indents.
These rows are added to support the WYSIWYG principe of the grid export.
You can review this topic:
Problem with XtraGrid Group Footer rending when exporting to excel
I am trying to add conditional formatting on my pivot table created from Epplus bu i am not able to do it.
I can add the column colors on regular excel sheet by
using (var range = Pws.Cells[1,1,5,5])
{
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
range.Style.Fill.BackgroundColor.SetColor(colorValue);
}
But when i add the code on pivot table sheet and try to open it it gives a pop up message like "Do you want to replace the content of the destination cell in PivotTable?"
I think its adding the color on top of the pivot table value. Its my guess because i can see the value of pivot table when i dont add the color formatting.
Any one had this issue and is there any work around?
I'm using cfspreadsheet to generate an Excel spreadsheet using ColdFusion. I insert a header row, and then use spreadsheetAddRows to dump a query into the sheet. The problem is that the columns are often not wide enough. I know I can use SpreadsheetSetColumnWidth to adjust each column individually, but is there any way that I can just apply an auto-width to the entire sheet? I don't know the max width of each column, and I don't want to apply it to each column individually. Excel has an auto-width feature for columns — is there any way to trigger it from the ColdFusion code? (Or even better: Can I add on to the auto-width — set each column to the max width + 2 or something?)
Last I checked there was not a documented CF function. However you can use POI's autoSizeColumn(columnIndex) method to auto size each column. Just note POI uses base zero for sheet and column indexes.
<cfscript>
// create a workbook and add a long value
wb = SpreadSheetNew();
spreadSheetSetCellValue(wb, repeatString("x", 200), 1, 1);
// get the first sheet
sheet = wb.getWorkBook().getSheetAt( javacast("int", 0) );
// resize first column ie "A"
sheet.autoSizeColumn( javacast("int", 0) );
spreadSheetWrite( wb, "c:/test.xls", true );
</cfscript>