Sapi-NT can format API responses in Excel spreadsheet format (XLS), which is compatible with spreadsheet applications such as Microsoft Excel and OpenOffice Calc. This document describes how to configure a Sapi-NT application to produce API responses in XLS format.
To enable XLS format, you must first add the following dependency to the pom.xml file of your Sapi-NT Maven project.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
</dependency>
Then, edit your ApplicationRunner class (the class annotated with @SpringBootApplication)
to call ConfigProperties.enableXLS() in the run method:
override fun run(args: ApplicationArguments?) {
log.info("API at ${api.apiProperties.baseURI} - ${api.apiProperties.comment}")
ConfigProperties.enableXLS()
log.info("XLS format enabled.")
}
API responses in XLS format produce the same columns and rows as the CSV format,
which is determined by the requested view definition
(or the default view if the request does not specify a view).
The csv.map and cav.flatPaths properties apply to both CSV and XLS responses.
To configure a view, you must edit either the view spec file or the endpoint spec file containing the embedded view.
When the XLS format is configured, API consumers can request XLS responses with the usual content negotiation methods, specifying either the name or media type as follows:
| Name | Media Type |
|---|---|
| xls | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |