DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Related

  • Android Cloud Apps with Azure
  • Build Quicker With Zipper: Building a Ping Pong Ranking App Using TypeScript Functions
  • How to Build a URL Shortener Web App With Flask Framework
  • The 12 Biggest Android App Development Trends in 2023

Trending

  • Build a Multilingual Chatbot With FastAPI and Google Cloud Translation
  • Microservices Design Patterns for Highly Resilient Architecture
  • Unifying SecOps and Observability for Enhanced Cloud Security in Azure
  • PHP Opcode: Improve Application Performance Without Changing Your Code
  1. DZone
  2. Data Engineering
  3. Databases
  4. Customize the Appearance of Pivot Table Reports inside Android Apps

Customize the Appearance of Pivot Table Reports inside Android Apps

By 
David Zondray user avatar
David Zondray
·
Feb. 19, 14 · Code Snippet
Likes (0)
Comment
Save
Tweet
Share
2.4K Views

Join the DZone community and get the full member experience.

Join For Free
This technical tip shows how developers can customize the Appearance of Pivot Table Reports  inside their Android applications using Aspose.Cells for Android. Previously we have shown how to create a simple pivot table. This article further goes and discusses how to customize the appearance of a pivot table by setting its properties like Setting the AutoFormat and PivotTableStyle Types, Setting Format Options, Setting Row Column and Page Fields Format, Modify a Pivot Table Quick Style and Clearing PivotFields etc.
//Setting the AutoFormat and PivotTableStyle Type

//Setting the PivotTable report is automatically formatted for Excel 2003 formats
pivotTable.setAutoFormat(true);
//Setting the PivotTable atuoformat type.
pivotTable.setAutoFormatType(PivotTableAutoFormatType.CLASSIC);

//Setting the PivotTable's Styles for Excel 2007/2010 formats e.g XLSX.
pivotTable.setPivotTableStyleType(PivotTableStyleType.PIVOT_TABLE_STYLE_LIGHT_1);

//Setting Format Options

//The code sample that follows illustrates how to set a number of pivot table formatting options, including adding grand totals for rows and columns.

//Dragging the third field to the data area.
 pivotTable.addFieldToArea(PivotFieldType.DATA,2);

//Show grand totals for rows.
 pivotTable.setRowGrand(true);

//Show grand totals for columns.
pivotTable.setColumnGrand(true);

//Display a custom string in cells that contain null values.
pivotTable.setDisplayNullString(true);
pivotTable.setNullString("null");

//Setting the layout
pivotTable.setPageFieldOrder(PrintOrderType.DOWN_THEN_OVER);

//Setting Row, Column, and Page Fields Format

//The code example that follows shows how to access row fields, access a particular row, set subtotals, apply automatic sorting, and using the autoShow option.

//Accessing the row fields.
PivotFieldCollection pivotFields = pivotTable.getRowFields();

//Accessing the first row field in the row fields.
PivotField pivotField = pivotFields.get(0);

//Setting Subtotals.
pivotField.setSubtotals(PivotFieldSubtotalType.SUM,true);
pivotField.setSubtotals(PivotFieldSubtotalType.COUNT,true);

//Setting autosort options.
//Setting the field auto sort.
pivotField.setAutoSort(true);

//Setting the field auto sort ascend.
pivotField.setAscendSort(true);

//Setting the field auto sort using the field itself.
pivotField.setAutoSortField(-1);

//Setting autoShow options.
//Setting the field auto show.
pivotField.setAutoShow(true);

//Setting the field auto show ascend.
pivotField.setAscendShow(false);

//Setting the auto show using field(data field).
pivotField.setAutoShowField(0);

//The following lines of code illustrate how to format data fields.

//Accessing the data fields.
PivotFieldCollection pivotFields = pivotTable.getDataFields();

//Accessing the first data field in the data fields.
PivotField pivotField = pivotFields.get(0);

//Setting data display format
pivotField.setDataDisplayFormat(PivotFieldDataDisplayFormat.PERCENTAGE_OF);

//Setting the base field.
pivotField.setBaseField(1);

//Setting the base item.
pivotField.setBaseItem(PivotItemPosition.NEXT);

//Setting number format
pivotField.setNumber(10);

//Modify a Pivot Table Quick Style

//The code examples that follow show how to modify the quick style applied to a pivot table.

File sdDir = Environment.getExternalStorageDirectory();
String sdPath = sdDir.getCanonicalPath();

//Open the template file containing the pivot table.
Workbook wb = new Workbook(sdPath + "/Template.xlsx");

//Add pivot table style
Style style1 = wb.createStyle();
com.aspose.cells.Font font1 = style1.getFont();
font1.setColor(Color.getRed());
Style style2 = wb.createStyle();
com.aspose.cells.Font font2 = style2.getFont();
font2.setColor( Color.getBlue());
int i = wb.getWorksheets().getTableStyles().addPivotTableStyle("tt");

//Get and Set the table style for different categories
TableStyle ts = wb.getWorksheets().getTableStyles().get(i);
int index = ts.getTableStyleElements().add(TableStyleElementType.FIRST_COLUMN);
TableStyleElement e = ts.getTableStyleElements().get(index);
e.setElementStyle(style1);
index = ts.getTableStyleElements().add(TableStyleElementType.GRAND_TOTAL_ROW);
e = ts.getTableStyleElements().get(index);
e.setElementStyle(style2);

//Set Pivot Table style name
PivotTable pt = wb.getWorksheets().get(0).getPivotTables().get(0);
pt.setPivotTableStyleName ("tt");

//Save the file.
wb.save(sdPath + "/OutputFile.xlsx");

//Clearing PivotFields

//PivotFieldCollection has a method named clear() for the task. When you want to clear all the PivotFields in the areas e.g., page, column, row or data, you can use it.
The code sample below shows how to clear all the PivotFields in data area.

File sdDir = Environment.getExternalStorageDirectory();
String sdPath = sdDir.getCanonicalPath();

//Open the template file containing the pivot table.
Workbook workbook = new Workbook(sdPath + "/PivotTable.xlsx");

//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);

//Get the pivot tables in the sheet
PivotTableCollection pivotTables = sheet.getPivotTables();

//Get the first PivotTable
PivotTable pivotTable = pivotTables.get(0);

//Clear all the data fields
pivotTable.getDataFields().clear();

//Add new data field
pivotTable.addFieldToArea(PivotFieldType.DATA, "Betrag Netto FW");

//Set the refresh data flag on
pivotTable.setRefreshDataFlag(false);

//Refresh and calculate the pivot table data
pivotTable.refreshData();
pivotTable.calculateData();

//Save the Excel file
workbook.save(sdPath + "/out1.xlsx");
Database Pivot table Android (robot) app

Opinions expressed by DZone contributors are their own.

Related

  • Android Cloud Apps with Azure
  • Build Quicker With Zipper: Building a Ping Pong Ranking App Using TypeScript Functions
  • How to Build a URL Shortener Web App With Flask Framework
  • The 12 Biggest Android App Development Trends in 2023

Partner Resources


Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: