Exporting data to MS Excel workbook

  1. In the Projects view, click the model’s Database item.
  2. In the Properties view, expand the Export section.
  3. Before doing the export, you need to set it up. If you have not done this yet, click the Export settings. label.
  4. You will see the Export settings dialog. Using the Browse. button, select the MS Excel file where you want to write the information. The button switches the path between absolute and relative. The path to the file will be displayed in the Export to field of the DB properties’ Export section.
  5. Below, in the Select tables you want to export list, select the check boxes for the database tables you want to export to MS Excel workbook.
  6. We have finished defining the export settings. Click the OK button.
  7. If you want to perform the data export, in the Database properties, click the label Export tables to Excel.
  8. If you want data to be exported every time when the model execution is finished or terminated by the user, select the check box Export tables at the end of model execution.

If the selected MS Excel file is currently opened, you will see the error message. Close the MS Excel application, and repeat the export scenario.

If the export was successful, you can open the MS Excel file, and see that AnyLogic added new worksheet(s), one per each exported database table, and wrote the data there.

To export data from the model’s database into an external Excel file programmatically

You can command AnyLogic to export data from its internal database to an external Excel file, using any of the available code fields, for example, a function body or agent action.

    Use the Database class constructor to specify the location of the Excel file you need, for example:

Database myFile = new Database( this , "A DB from Excel", "D:\Files\myDBFile.xls")
ModelDatabase modelDB = getEngine().getModelDatabase();

modelDB.exportToExternalDB("Database table for exporting", myFile.getConnection(), "Sheet 1", false , false );

For more information regarding this function, as well as the other internal database functions, see the following reference: Database functions.