Import Data from Microsoft Access Database ResultSet Object to the Worksheet

Possible Usage Scenarios

Aspose.Cells can import data to worksheets from ResultSet object which can be created from any database. However, this article specifically creates a ResultSet object from Microsoft Access Database. Since the code is the same for all types of databases, so you can use it in general.

UCanAccess - Required to Connect to Microsoft Access Database

Please download UCanAccess. It includes the following JAR files. Add all of them in the classpath.

  • ucanaccess-4.0.1.jar
  • commons-lang-2.6.jar
  • commons-logging-1.1.1.jar
  • hsqldb.jar
  • jackcess-2.1.6.jar

For more help, please visit this Stack Overflow link.

Sample Microsoft Access 2016 Database File used inside Sample Code

The following sample Microsoft Access 2016 Database File was used inside the sample code. You can use any database file or create your own.

The following screenshot shows the database file when opened in Microsoft Access 2016.

todo:image_alt_text

Import Data from Microsoft Access Database ResultSet Object to the Worksheet.

The following sample code executes SQL query from Microsoft Access Database and creates a ResultSet object. Then it imports data from ResultSet object into worksheet using Worksheet.getCells().importResultSet() method. The first time, it uses row and column indices and then it uses cell name to import data into the worksheet. Finally, it saves the workbook as an Output Excel File. The screenshot shows the effect of the sample code on the output Excel file for a reference.

todo:image_alt_text

Sample Code