0%

EasyExcel钩子

EasyExcel钩子

EasyExcel中提供了几个接口来进行钩子操作

workbook钩子

workbook创建前后的钩子方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public interface WorkbookWriteHandler extends WriteHandler {

/**
* Called before create the workbook
*
* @param context
*/
default void beforeWorkbookCreate(WorkbookWriteHandlerContext context) {
beforeWorkbookCreate();
}

/**
* Called before create the workbook
*/
default void beforeWorkbookCreate() {}

/**
* Called after the workbook is created
*
* @param context
*/
default void afterWorkbookCreate(WorkbookWriteHandlerContext context) {
afterWorkbookCreate(context.getWriteWorkbookHolder());
}

/**
* Called after the workbook is created
*
* @param writeWorkbookHolder
*/
default void afterWorkbookCreate(WriteWorkbookHolder writeWorkbookHolder) {}

/**
* Called after all operations on the workbook have been completed
*
* @param context
*/
default void afterWorkbookDispose(WorkbookWriteHandlerContext context) {
afterWorkbookDispose(context.getWriteWorkbookHolder());
}

/**
* Called after all operations on the workbook have been completed
*
* @param writeWorkbookHolder
*/
default void afterWorkbookDispose(WriteWorkbookHolder writeWorkbookHolder) {}
}

sheet钩子

sheet创建前后的钩子方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public interface SheetWriteHandler extends WriteHandler {

/**
* Called before create the sheet
*
* @param context
*/
default void beforeSheetCreate(SheetWriteHandlerContext context) {
beforeSheetCreate(context.getWriteWorkbookHolder(), context.getWriteSheetHolder());
}

/**
* Called before create the sheet
*
* @param writeWorkbookHolder
* @param writeSheetHolder
*/
default void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {}

/**
* Called after the sheet is created
*
* @param context
*/
default void afterSheetCreate(SheetWriteHandlerContext context) {
afterSheetCreate(context.getWriteWorkbookHolder(), context.getWriteSheetHolder());
}

/**
* Called after the sheet is created
*
* @param writeWorkbookHolder
* @param writeSheetHolder
*/
default void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {}
}

row钩子

Row创建前后的钩子方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
public interface RowWriteHandler extends WriteHandler {

/**
* Called before create the row
*
* @param context
*/
default void beforeRowCreate(RowWriteHandlerContext context) {
beforeRowCreate(context.getWriteSheetHolder(), context.getWriteTableHolder(), context.getRowIndex(),
context.getRelativeRowIndex(), context.getHead());
}

/**
* Called before create the row
*
* @param writeSheetHolder
* @param writeTableHolder Nullable.It is null without using table writes.
* @param rowIndex
* @param relativeRowIndex Nullable.It is null in the case of fill data.
* @param isHead Nullable.It is null in the case of fill data.
*/
default void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer rowIndex,
Integer relativeRowIndex, Boolean isHead) {}

/**
* Called after the row is created
*
* @param context
*/
default void afterRowCreate(RowWriteHandlerContext context) {
afterRowCreate(context.getWriteSheetHolder(), context.getWriteTableHolder(), context.getRow(),
context.getRelativeRowIndex(), context.getHead());
}

/**
* Called after the row is created
*
* @param writeSheetHolder
* @param writeTableHolder Nullable.It is null without using table writes.
* @param row
* @param relativeRowIndex Nullable.It is null in the case of fill data.
* @param isHead Nullable.It is null in the case of fill data.
*/
default void afterRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
Integer relativeRowIndex, Boolean isHead) {}

/**
* Called after all operations on the row have been completed.
* In the case of the fill , may be called many times.
*
* @param context
*/
default void afterRowDispose(RowWriteHandlerContext context) {
afterRowDispose(context.getWriteSheetHolder(), context.getWriteTableHolder(), context.getRow(),
context.getRelativeRowIndex(), context.getHead());
}

/**
* Called after all operations on the row have been completed.
* In the case of the fill , may be called many times.
*
* @param writeSheetHolder
* @param writeTableHolder Nullable.It is null without using table writes.
* @param row
* @param relativeRowIndex Nullable.It is null in the case of fill data.
* @param isHead Nullable.It is null in the case of fill data.
*/
default void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
Integer relativeRowIndex, Boolean isHead) {}
}

cell钩子

cell创建前后的钩子方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
public interface CellWriteHandler extends WriteHandler {

/**
* Called before create the cell
*
* @param context
*/
default void beforeCellCreate(CellWriteHandlerContext context) {
beforeCellCreate(context.getWriteSheetHolder(), context.getWriteTableHolder(), context.getRow(),
context.getHeadData(), context.getColumnIndex(), context.getRelativeRowIndex(), context.getHead());
}

/**
* Called before create the cell
*
* @param writeSheetHolder
* @param writeTableHolder Nullable.It is null without using table writes.
* @param row
* @param head Nullable.It is null in the case of fill data and without head.
* @param columnIndex
* @param relativeRowIndex Nullable.It is null in the case of fill data.
* @param isHead It will always be false when fill data.
*/
default void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {}

/**
* Called after the cell is created
*
* @param context
*/
default void afterCellCreate(CellWriteHandlerContext context) {
afterCellCreate(context.getWriteSheetHolder(), context.getWriteTableHolder(), context.getCell(),
context.getHeadData(), context.getRelativeRowIndex(), context.getHead());
}

/**
* Called after the cell is created
*
* @param writeSheetHolder
* @param writeTableHolder Nullable.It is null without using table writes.
* @param cell
* @param head Nullable.It is null in the case of fill data and without head.
* @param relativeRowIndex Nullable.It is null in the case of fill data.
* @param isHead It will always be false when fill data.
*/
default void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell,
Head head, Integer relativeRowIndex, Boolean isHead) {}

/**
* Called after the cell data is converted
*
* @param context
*/
default void afterCellDataConverted(CellWriteHandlerContext context) {
WriteCellData<?> writeCellData = CollectionUtils.isNotEmpty(context.getCellDataList()) ? context
.getCellDataList().get(0) : null;
afterCellDataConverted(context.getWriteSheetHolder(), context.getWriteTableHolder(), writeCellData,
context.getCell(), context.getHeadData(), context.getRelativeRowIndex(), context.getHead());
}

/**
* Called after the cell data is converted
*
* @param writeSheetHolder
* @param writeTableHolder Nullable.It is null without using table writes.
* @param cell
* @param head Nullable.It is null in the case of fill data and without head.
* @param cellData Nullable.It is null in the case of add header.
* @param relativeRowIndex Nullable.It is null in the case of fill data.
* @param isHead It will always be false when fill data.
*/
default void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {}

/**
* Called after all operations on the cell have been completed
*
* @param context
*/
default void afterCellDispose(CellWriteHandlerContext context) {
afterCellDispose(context.getWriteSheetHolder(), context.getWriteTableHolder(), context.getCellDataList(),
context.getCell(), context.getHeadData(), context.getRelativeRowIndex(), context.getHead());
}

/**
* Called after all operations on the cell have been completed
*
* @param writeSheetHolder
* @param writeTableHolder Nullable.It is null without using table writes.
* @param cell
* @param head Nullable.It is null in the case of fill data and without head.
* @param cellDataList Nullable.It is null in the case of add header.There may be several when fill the data.
* @param relativeRowIndex Nullable.It is null in the case of fill data.
* @param isHead It will always be false when fill data.
*/
default void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {}
}

欢迎关注我的其它发布渠道