Class XlsCommentAreaBuilder
- All Implemented Interfaces:
AreaBuilder,CommandMappings
XlsArea from Excel comments in the Excel template
Command syntax
A command is specified in a cell comment like the following
jx:COMMAND_NAME(attr1="value1" attr2="value2" ... attrN="valueN" lastCell="LAST_CELL" areas=["AREA_REF1", "AREA_REF2", ... , "AREA_REFN"])where
- COMMAND_NAME - the name of the command
- attr1, attr2, ... attrN, value1, value2, ... , valueN - command attributes and their values
- lastCell, LAST_CELL - attribute name and cell reference value specifying the last cell where this command is placed in the parent area. The first cell is defined by the cell where the comment is defined. If there is no "areas" attribute defined it also defines the single area for this command to operate on.
- AREA_REF1, AREA_REF2, ... , AREA_REFN - additional area references for this command (if supported by the command) 'areas' attribute is optional and only needed for commands which work with more than one area. If there is only a single area for the command it is usually enough to define just lastCell attribute
Multiple commands can be specified in a single cell comment separated by new lines. In this case the area of the first command will contain the second command and so on.
This class defines the following pre-defined mappings between the command names and Command classes:
"jx:each" -EachCommand"jx:if" -IfCommand"jx:area" -AreaCommand- for defining the top areas "jx:grid" -GridCommand"jx:updateCell" -UpdateCellCommand
Custom command classes mapping can be added using addCommandMapping(String commandName, Class clazz) method
Command examples
jx:if(condition="employee.payment <= 2000", lastCell="F9", areas=["A9:F9","A30:F30"])
Here we define IfCommand with a condition expression 'employee.payment <= 2000' and first area (if-area) "A9:F9"
and second area (else-area) "A30:F30". The command is added to the parent area covering a range from the cell where
the comment is placed and to the cell defined in lastCell attribute "F9".
jx:each(items="department.staff", var="employee", lastCell="F9")
Here we define EachCommand with items attribute set to 'department.staff' and var attribute set to 'employee'.
The command area is defined from the cell where the comment is defined and till the lastCell "F9"
jx:area(lastCell="G26")
Specifies the top area range with AreaCommand starting from the cell where the comment is defined and in
the cell defined in lastCell("G26").
Note: Clearing comments from the cells appears to have some issues in POI so should be used with caution. The easiest approach will be just removing the template sheet.
- Author:
- Leonid Vysochyn
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAreaListener(AreaListener areaListener, AreaRef areaRef, List<Area> areas) Method for adding an AreaListener to an area given by an AreaRefvoidaddCommandMapping(String commandName, Class<? extends Command> commandClass) protected List<CommandData>buildCommands(Transformer transformer, CellData cellData, String text) getCommandClass(String commandName) static booleanisCommandString(String str) voidremoveCommandMapping(String commandName) Methods inherited from class org.jxls.builder.xls.AbstractAreaBuilder
build, processCommandData, processCommands
-
Field Details
-
COMMAND_PREFIX
- See Also:
-
LINE_SEPARATOR
- See Also:
-
MULTI_LINE_SQL_FEATURE
public static boolean MULTI_LINE_SQL_FEATUREFeature toggle for the multi-line SQL feature (#79)
-
-
Constructor Details
-
XlsCommentAreaBuilder
public XlsCommentAreaBuilder()
-
-
Method Details
-
addCommandMapping
- Specified by:
addCommandMappingin interfaceCommandMappings
-
removeCommandMapping
- Specified by:
removeCommandMappingin interfaceCommandMappings
-
getCommandClass
- Specified by:
getCommandClassin interfaceCommandMappings
-
buildCommands
- Specified by:
buildCommandsin classAbstractAreaBuilder
-
isCommandString
-
addAreaListener
Method for adding an AreaListener to an area given by an AreaRef- Parameters:
areaListener- to be added AreaListenerareaRef- area where the AreaListener has to be addedareas- all areas to search for
-