Update Excel QueryTable using Java

This quick guide explains the process for working with an Excel query table using Java. It will provide the details to set the IDE, a list of steps, and a sample code for editing the QueryTable connection using Java. You will learn to customize the QueryTable in an Excel file and also change the external connections using the exposed API calls.

Steps to Update Excel QueryTable using Java

  1. Set the IDE to use Aspose.Cells for Java for working with QueryTable
  2. Load the source Excel file, access the target sheet, and check the existence of the query tables
  3. Access the first query table and print the query table data
  4. Check the external connection in the query table and display its features
  5. Change the parameters of the query table and external connection
  6. Save the updated Excel file
  7. Load the file again and verify the changed parameters in the query table and external connections

These steps summarize the process to update external data connection using Java in an Excel file. Load the Excel file, access the target sheet, get the collection of the query tables, and display the data of the first query table. Customize the QueryTable and external connection in it and save the Workbook.

Code to Edit Excel External Data Connection using Java

This code has demonstrated how to work with the Excel QueryTable. If you want to observe the behavior of how data is displayed after refresh, you may use the getAutoReformat() and getFillAdjacentFormulas() methods. The setPreserveFormatting() and setAdjustColumnWidth() methods should be used in combination, as these preserve formatting while auto-adjusting columns can produce conflicting results.

This article has guided us on how to work with the QueryTable and external connection in it. To create subtotal in an Excel file, refer to the article Creating subtotals in Excel using Java.