Extra Information
This chapter introduces how to write extra information such as comments, hyperlinks, formulas, etc.
Comments
Overview
Add comments to specific cells through interceptors, suitable for annotations or special reminders.
Code Example
Custom interceptor
@Slf4j
public class CommentWriteHandler implements RowWriteHandler {
@Override
public void afterRowDispose(RowWriteHandlerContext context) {
if (BooleanUtils.isTrue(context.getHead())) {
Sheet sheet = context.getWriteSheetHolder().getSheet();
Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch();
// Create comment in first row, second column
Comment comment = drawingPatriarch.createCellComment(
new XSSFClientAnchor(0, 0, 0, 0, (short) 1, 0, (short) 2, 1));
comment.setString(new XSSFRichTextString("Comments"));
sheet.getRow(0).getCell(1).setCellComment(comment);
}
}
}
Usage
@Test
public void commentWrite() {
String fileName = "commentWrite" + System.currentTimeMillis() + ".xlsx";
FesodSheet.write(fileName, DemoData.class)
.inMemory(Boolean.TRUE) // Comments must enable in-memory mode
.registerWriteHandler(new CommentWriteHandler())
.sheet()
.doWrite(data());
}
Result
The comment is attached to B1 and is only shown when that cell is hovered.
| A | B | C | |
| 1 | String Title | Date TitleComments | Number Title |
| 2 | String0 | 2026-07-31 20:50:23 | 0.56 |
| 3 | String1 | 2026-07-31 20:50:23 | 0.56 |
| ⋮ | … | … | … |
| 11 | String9 | 2026-07-31 20:50:23 | 0.56 |
Hyperlinks
Write extra hyperlink information
POJO Class
@Getter
@Setter
@EqualsAndHashCode
public class WriteCellDemoData {
private WriteCellData<String> hyperlink;
}
Code Example
@Test
public void writeHyperlinkDataWrite() {
String fileName = "writeCellDataWrite" + System.currentTimeMillis() + ".xlsx";
WriteCellDemoData data = new WriteCellDemoData();
// Set hyperlink
WriteCellData cellData = new WriteCellData<>("Click to visit");
HyperlinkData hyperlinkData = new HyperlinkData();
hyperlinkData.setAddress("https://example.com");
hyperlinkData.setHyperlinkType(HyperlinkData.HyperlinkType.URL);
cellData.setHyperlinkData(hyperlinkData);
data.setHyperlink(cellData);
FesodSheet.write(fileName, WriteCellDemoData.class)
.sheet()
.doWrite(Collections.singletonList(data));
}
Result
| A | |
| 1 | hyperlink |
| 2 | Click to visit |
Formulas
Write extra formula information
POJO Class
@Getter
@Setter
@EqualsAndHashCode
public class WriteCellDemoData {
private Integer num1;
private Integer num2;
private WriteCellData<String> formulaData;
}
Code Example
@Test
public void writeFormulaDataWrite() {
String fileName = "writeCellDataWrite" + System.currentTimeMillis() + ".xlsx";
WriteCellDemoData data = new WriteCellDemoData();
data.setNum1(10);
data.setNum2(20);
// Set formula
WriteCellData<String> cellData = new WriteCellData<>();
FormulaData formulaData = new FormulaData();
formulaData.setFormulaValue("SUM(A2:B2)");
// Or
// formulaData.setFormulaValue("=SUM(A2:B2)");
cellData.setFormulaData(formulaData);
data.setFormulaData(cellData);
FesodSheet.write(fileName, WriteCellDemoData.class)
.sheet()
.doWrite(Collections.singletonList(data));
}
Result
| A | B | C | |
| 1 | num1 | num2 | formulaData |
| 2 | 10 | 20 | 30 |
Template-based Writing
Overview
Supports using existing template files and filling data into templates, suitable for standardized output.
Code Example
@Test
public void templateWrite() {
String templateFileName = "path/to/template.xlsx";
String fileName = "templateWrite" + System.currentTimeMillis() + ".xlsx";
FesodSheet.write(fileName, DemoData.class)
.withTemplate(templateFileName)
.sheet()
.doWrite(data());
}
Custom Interceptors
Overview
Implement custom logic (such as adding dropdowns) through interceptor operations.
Code Example
Setting dropdowns
public class DropdownWriteHandler implements SheetWriteHandler {
@Override
public void afterSheetCreate(SheetWriteHandlerContext context) {
DataValidationHelper helper = context.getWriteSheetHolder().getSheet().getDataValidationHelper();
CellRangeAddressList range = new CellRangeAddressList(1, 10, 0, 0); // Dropdown area
DataValidationConstraint constraint = helper.createExplicitListConstraint(new String[] {"Option1", "Option2"});
DataValidation validation = helper.createValidation(constraint, range);
context.getWriteSheetHolder().getSheet().addValidationData(validation);
}
}
Usage
@Test
public void dropdownWrite() {
String fileName = "dropdownWrite" + System.currentTimeMillis() + ".xlsx";
FesodSheet.write(fileName, DemoData.class)
.registerWriteHandler(new DropdownWriteHandler())
.sheet("Dropdown Example")
.doWrite(data());
}
Result
The validation covers A2:A11, so every cell in that range offers the list. Selecting one shows the
dropdown button and its options - drawn open here on A2.
| A | B | C | |
| 1 | String Title | Date Title | Number Title |
| 2 | String0▾Option1Option2 | 2026-07-31 20:50:23 | 0.56 |
| 3 | String1 | 2026-07-31 20:50:23 | 0.56 |
| 4 | String2 | 2026-07-31 20:50:23 | 0.56 |
| ⋮ | … | … | … |
| 11 | String9 | 2026-07-31 20:50:23 | 0.56 |