# Excel and XML import

## Availability

This is an Orbeon Forms PE feature.

## What it is

This feature allows you to import data from a source Excel document or XML document.

[\[SINCE Orbeon Forms 2021.1\]](https://doc.orbeon.com/release-notes/orbeon-forms-2021.1)

A new Excel named ranges-based format is supported. Here are the main differences between the two types of Excel imports:

| "Headings" format                         | "Named ranges" format       |
| ----------------------------------------- | --------------------------- |
| multiple form documents at a time (batch) | one form document at a time |
| row and column-based                      | named range based           |
| no repeat support                         | repeat support              |
| fixed layout                              | customizable layout         |

The Named ranges format does not replace the Headings format but complements it.

[\[SINCE Orbeon Forms 2021.1\]](https://doc.orbeon.com/release-notes/orbeon-forms-2021.1)

A new XML format is supported.

## Allowed import formats

[\[SINCE Orbeon Forms 2021.1\]](https://doc.orbeon.com/release-notes/orbeon-forms-2021.1)

You can configure the Import page to support various import formats. These include:

* `excel-headings`: The default Excel import format, where the first row of the Excel file contains the names of the form fields.
* `excel-named-ranges`: The Excel import format where the Excel file uses named ranges to map to form fields.
* `xml-form-structure-and-data`: The XML format where the XML file contains both the form structure and data.

The `excel-headings` format is enabled by default. It is exclusive with the `excel-named-ranges` format, which means that you can use none, or one of these tokens, but not both at the same time.

The default configuration is:

```xml
<property
    as="xs:string"
    name="oxf.fr.import.allowed-formats.*.*" 
    value="excel-headings xml-form-structure-and-data"/>
```

Here is an example of configuration which switches to the `excel-named-ranges` format:

```xml
<property
    as="xs:string"
    name="oxf.fr.import.allowed-formats.*.*" 
    value="excel-named-ranges xml-form-structure-and-data"/>
```

## Import wizard steps

In order to import an Excel file, you follow a process in the Import page as described below.

### Access the Import page

You start the import from the Form Runner Import page, accessible from the [Summary page](https://doc.orbeon.com/form-runner/form-runner-pages/summary-page) when the "Import" button is configured, or directly with the path:

```
/fr/import/$app/$form
```

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-ecc442ec130cb1cd0c3b4f40dc8b005927c38f02%2Fexcel-import-summary.png?alt=media)

You enable the "Import" button on the [Summary page](https://doc.orbeon.com/form-runner/form-runner-pages/summary-page) by adding the `import` token to the `oxf.fr.summary.buttons.*.*` property. Here for the ACME Contact form:

```xml
<property as="xs:string" name="oxf.fr.summary.buttons.acme.contact">
    home review pdf delete duplicate import new
</property>
```

### Select the form version

\[SINCE Orbeon Forms 2018.2]

If form definition versioning is supported, and if the given form definition has more than one version, you can select the form definition version. The dropdown menu shows all published versions for the given form name and application name.

Selecting a version shows the versioning comment, if any, associated with the version, as well as the number of data records available in the database for that version.

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-65b1fe4addbc9e123ef9c2f54b2434d8d57cba7f%2Fexcel-import-version.png?alt=media)

### Upload the file

You navigate to the Upload section and select the Excel 2007 file to upload and import.

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-78d15c32e11957893e9521ec4cfad5638178b87d%2Fexcel-import-select.png?alt=media)

### Validate the data

You navigate to the Validation section. From there, data validation starts automatically, giving you an indication of the progress.

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-915dcb9e51cb40d9b1d171a6181cea7f3fa16cd9%2Fexcel-import-validating.png?alt=media)

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-a0e1965c164cc94fbbe422e95b90bb3e72adbed0%2Fexcel-import-validated.png?alt=media)

With the `excel-named-ranges` and `xml-form-structure-and-data` formats, information about valid and invalid fields shows.

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-ec91d1c5052b7c6999cb18224e2cd70a5520c83e%2Fexcel-import-named-ranges-validation-errors.png?alt=media)

### Import the data

*NOTE: This step only applies to the `excel-headings` format.*

Once validation is terminated, you navigate to the Import section. From there, you can start the data import. When using the Headings format, you have the option to add to existing data for the given form, or remove all existing data first.

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-3c1a545a18ae40b7d27d005fd6a8bf55dd945194%2Fexcel-import-import.png?alt=media)

Import takes place and gives you an indication of the progress.

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-b855a792b5f654e6464453e49890f054431e6b5f%2Fexcel-import-importing.png?alt=media)

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-69f5ffbff761ef3e430cc0bcc2f896384b949a74%2Fexcel-import-imported.png?alt=media)

*NOTE: Only the Excel 2007 `.xlsx` format (Office Open XML) is supported. The older, `.xls` format is not supported.*

### Review the data

*NOTE: This step only applies to the `excel-named-ranges` and `xml-form-structure-and-data` formats.*

Before the data is saved to the database, you can review errors if any and decide to correct them or to perform a new import.

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-bf7deb35166191609a23d10650b1bff217156266%2Fexcel-import-named-ranges-data-review.png?alt=media)

## Form controls mapping

### Excel Headings format

#### Excel file format

A given Excel file contains data for a single Orbeon Forms form.

The spreadsheet must follow this format:

* only the first sheet is considered
* the first row is a special header row, where each cell contains an identifier that matches a control name in the given form
* each subsequent row contains data for a new instance of form data

In your form, you create controls with names that match the names in the first row (header row) of the Excel document.

Here is an example spreadsheet for the sample Orbeon Contact form:

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEkBiSDvlXs3VWiO0Zu%2F-LEkBmMpnaxnftLGDglW%2F-LEkC92GJ29bKBQ6XKj9%2Fexcel-import-sheet.png?generation=1528743372740842\&alt=media)

*NOTE: Only characters allowed in XML names are allowed as control names in Form Builder. In case your Excel header row requires names with non-XML characters (Form Builder will tell you the name is not allowed), simply replace them by "*" in Form Builder.\_

#### Limitations

The import functionality with the `excel-headings` format does not support importing data into repeated grids.

### Excel Named ranges format

For more about the format, see [Excel and XML Export](https://doc.orbeon.com/form-runner/features/excel-xml-export).

You don’t have to export a form to Excel to import data: as long as you have a spreadsheet that includes the appropriate named ranges (see above), you can use it for importing. This means that you can reuse existing spreadsheets with a few additions, and keep a spreadsheet layout that users are familiar with.

### XML Form Structure and Data format

For more about the format, see [Excel and XML Export](https://doc.orbeon.com/form-runner/features/excel-xml-export).

When you import, the only part that matters is the `<form-data>` section of the XML document. The rest of the XML file is ignored.

## Handling dates and times

\[SINCE Orbeon Forms 2019.2]

Cells that contain values formatted as date/time, date, or time in the Excel spreadsheet are automatically converted to their respective ISO formats before being stored as form data.

## Other configurations

### Allowing invalid data

\[SINCE Orbeon Forms 2017.2]

*NOTE: This property only applies to the `excel-headings` format.*

By default, invalid data rows are skipped during import.

You can enable the optional import of invalid data with the following property:

```xml
<property
    as="xs:boolean"
    name="oxf.fr.import.allow-invalid-documents.*.*"
    value="true"/>
```

By default, it is set to `false` and the user is not provided with an option to skip invalid data.

When set to `true`, the user is provided with an option to skip invalid data at the time of import:

![](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LEkBiSDvlXs3VWiO0Zu%2Fuploads%2Fgit-blob-a0e8414f55a9b98fdc7d7a4b35c6a4375bf5e093%2Fexcel-import-validate-allow-invalid.png?alt=media)

### Restricting to the latest version

\[SINCE Orbeon Forms 2018.2]

The user can select which form definition version to import to.

You can disable the ability for the user to do so, and always automatically select the latest form definition version, with the following property:

```xml
<property
    as="xs:boolean"
    name="oxf.fr.import.restrict-to-latest-version.*.*"
    value="true"/>
```

### Start Over button

[\[SINCE Orbeon Forms 2020.1\]](https://doc.orbeon.com/release-notes/orbeon-forms-2020.1)

By default, the "Start Over" button is not shown on the Import page. You can enable it with the following property:

```xml
<property 
    as="xs:boolean"
    name="oxf.fr.import.show-start-over-button.*.*"
    value="true"/>
```

### Showing the application and form names

[\[SINCE Orbeon Forms 2021.1\]](https://doc.orbeon.com/release-notes/orbeon-forms-2021.1)

By default, the import page shows the application and form names. You can hide them with the following property:

```xml
<property 
    as="xs:boolean"
    name="oxf.fr.import.show-app-form-names.*.*"
    value="false"/>
```

### Forwarding parameters to the data review page

[\[SINCE Orbeon Forms 2021.1\]](https://doc.orbeon.com/release-notes/orbeon-forms-2021.1)

*NOTE: This property only applies to the `excel-named-ranges` and `xml-form-structure-and-data` formats.*

This property allows you to forward specific URL parameters that were passed to the Import page to the data review page. By default, no parameters are forwarded. This example shows how to forward the `foo` and `bar` parameters:

```xml
<property 
    as="xs:string"
    name="oxf.fr.import.forward-parameters.*.*"
    value="foo bar"/>
```

### Passing a document id to the data review page

[\[SINCE Orbeon Forms 2021.1\]](https://doc.orbeon.com/release-notes/orbeon-forms-2021.1)

*NOTE: This property only applies to the `excel-named-ranges` and `xml-form-structure-and-data` formats.*

You can pass a document id to the import page. This is useful if you want to propagate a document id to the data review page to update or merge with an existing document in the database. This example shows how to pass the `document-id` parameter:

```
/fr/import/orbeon/contact?document-id=123
```

### Customizing the buttons in the buttons bar

[\[SINCE Orbeon Forms 2021.1\]](https://doc.orbeon.com/release-notes/orbeon-forms-2021.1)

This property allows you to configure the buttons at the bottom of the Import page. They are, by default:

```xml
<property 
    as="xs:string"
    name="oxf.fr.import.buttons.*.*"
    value="home summary close"/>
```

If, for example you don't want the `summary` button, then set the property to:

```xml
<property 
    as="xs:string"
    name="oxf.fr.import.buttons.*.*"
    value="home close"/>
```

## See also

* [Excel and XML Export](https://doc.orbeon.com/form-runner/features/excel-xml-export)
* [Form definitions and form data Zip Export](https://doc.orbeon.com/form-runner/features/exporting-form-definitions-and-form-data)
* [Service calls](https://doc.orbeon.com/form-runner/link-embed/linking)
