Skip to content

Commit

Permalink
Add example for namedHeaderMandatory to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Apr 30, 2020
1 parent f01af05 commit f11e08c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,39 @@ This is the excel file we want to parse:
The object corresponding to the first row of the excel sheet then has a map with `{ENCODING=mp3, BITRATE=256}`
and the one for the second row has `{ENCODING=flac, BITRATE=1500}`.

=== Example 9

Poiji 2.6.0 introduced the Option `namedHeaderMandatory`. If set to true, Poiji will check that all field annotated with `@ExcelCellName` must have a corresponding column in the Excel sheet. If any column is missing a `HeaderMissingException` will be thrown.

[source,java]
----
public class MusicTrack {
@ExcelCellName("ID")
private String employeeId;
@ExcelCellName("AUTHOR")
private String author;
}
----

This is the excel file we want to parse:

|===
|ID | Artist

|123923
|Joe Doe

|56437
|Jane Doe
|===

In the default setting of Poiji (`namedHeaderMandatory=false`), the author field will be null for both objects.
With `namedHeaderMandatory=true`, a `HeaderMissingException` will be thrown.


== Try with JShell

Since we have a new pedagogic tool, Java 9 REPL, you can try Poiji in JShell. Clone the repo and follow the steps below. JShell should open up a new jshell session once loading the startup scripts and the specified jars that must be in the classpath. You must first import and create related packages and classes before using Poiji. We are able to use directly Poiji and Employee classes because they are already imported from `jshell/snippets` with `try-with-jshell.sh`.
Expand Down

0 comments on commit f11e08c

Please sign in to comment.