Skip to content

Commit 1a3dad9

Browse files
committed
Added java docs.
1 parent 9123ac9 commit 1a3dad9

File tree

7 files changed

+258
-5
lines changed

7 files changed

+258
-5
lines changed

src/main/java/model/ExcelCell.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,41 @@
1313
import java.time.LocalDateTime;
1414
import java.util.Date;
1515

16+
/**
17+
* {@code ExcelCell} is the {@code Cell} wrapper class of the Apache POI library
18+
* @author Mirko Benincasa
19+
* @since 0.3.0
20+
*/
1621
@AllArgsConstructor
1722
@Getter
1823
@EqualsAndHashCode
1924
public class ExcelCell {
2025

26+
/**
27+
* This object refers to the Apache POI Library {@code Cell}
28+
*/
2129
private Cell cell;
30+
31+
/**
32+
* The index of the Cell in the Row
33+
*/
2234
private Integer index;
2335

36+
/**
37+
* Returns the Row to which it belongs
38+
* @return A ExcelRow
39+
*/
2440
public ExcelRow getRow() {
2541
Row row = this.cell.getRow();
2642
return new ExcelRow(row, row.getRowNum());
2743
}
2844

45+
/**
46+
* Read the value written inside the Cell
47+
* @param type The class type of the object written to the Cell
48+
* @return The value written in the Cell
49+
* @throws ReadValueException If an error occurs while reading
50+
*/
2951
public Object readValue(Class<?> type) throws ReadValueException {
3052
Object val;
3153
switch (this.cell.getCellType()) {
@@ -63,6 +85,10 @@ public Object readValue(Class<?> type) throws ReadValueException {
6385
return val;
6486
}
6587

88+
/**
89+
* Writes inside the cell
90+
* @param val The value to write in the Cell
91+
*/
6692
public void writeValue(Object val) {
6793
if (val instanceof Integer || val instanceof Long) {
6894
this.formatStyle((short) 1);
@@ -86,6 +112,10 @@ public void writeValue(Object val) {
86112
}
87113
}
88114

115+
/**
116+
* Format text according to the pattern provided
117+
* @param dataFormat The Apache POI library CellStyle dataFormat
118+
*/
89119
public void formatStyle(short dataFormat) {
90120
ExcelWorkbook excelWorkbook = this.getRow().getSheet().getWorkbook();
91121
CellStyle newCellStyle = excelWorkbook.getWorkbook().createCellStyle();

src/main/java/model/ExcelRow.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,30 @@
1111
import java.util.LinkedList;
1212
import java.util.List;
1313

14+
/**
15+
* {@code ExcelRow} is the {@code Row} wrapper class of the Apache POI library
16+
* @author Mirko Benincasa
17+
* @since 0.3.0
18+
*/
1419
@AllArgsConstructor
1520
@Getter
1621
@EqualsAndHashCode
1722
public class ExcelRow {
1823

24+
/**
25+
* This object refers to the Apache POI Library {@code Row}
26+
*/
1927
private Row row;
28+
29+
/**
30+
* The index of the Row in the Sheet
31+
*/
2032
private Integer index;
2133

34+
/**
35+
* The list of Cells related to the Row
36+
* @return A list of Cells
37+
*/
2238
public List<ExcelCell> getCells() {
2339
List<ExcelCell> excelCells = new LinkedList<>();
2440
for (Cell cell : this.row) {
@@ -28,6 +44,10 @@ public List<ExcelCell> getCells() {
2844
return excelCells;
2945
}
3046

47+
/**
48+
* Returns the Sheet to which it belongs
49+
* @return A ExcelSheet
50+
*/
3151
@SneakyThrows
3252
public ExcelSheet getSheet() {
3353
Sheet sheet = this.row.getSheet();
@@ -36,14 +56,28 @@ public ExcelSheet getSheet() {
3656
return new ExcelSheet(sheet, excelWorkbook.getSheet(sheetName).getIndex(), sheetName);
3757
}
3858

59+
/**
60+
* Create a new Cell in the Row
61+
* @param index The index in the Row
62+
* @return A Cell
63+
*/
3964
public ExcelCell createCell(Integer index) {
4065
return new ExcelCell(this.row.createCell(index), index);
4166
}
4267

68+
/**
69+
* Retrieves the index of the last Cell
70+
* @return The index of the last Cell
71+
*/
4372
public Integer getLastColumnIndex() {
4473
return this.row.getLastCellNum() - 1;
4574
}
4675

76+
/**
77+
* Counts how many Cells are compiled
78+
* @param alsoEmpty {@code true} if you want to count Cells empty
79+
* @return The number of Cells compiled
80+
*/
4781
public Integer countAllColumns(Boolean alsoEmpty) {
4882
Integer count = this.getLastColumnIndex() + 1;
4983
if (alsoEmpty)

src/main/java/model/ExcelSheet.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,48 @@
1212
import java.util.LinkedList;
1313
import java.util.List;
1414

15+
/**
16+
* {@code ExcelSheet} is the {@code Sheet} wrapper class of the Apache POI library
17+
* @author Mirko Benincasa
18+
* @since 0.3.0
19+
*/
1520
@AllArgsConstructor
1621
@Getter
1722
@EqualsAndHashCode
1823
public class ExcelSheet {
1924

25+
/**
26+
* This object refers to the Apache POI Library {@code Sheet}
27+
*/
2028
private Sheet sheet;
29+
30+
/**
31+
* The index of the Sheet in the Workbook
32+
*/
2133
private Integer index;
34+
35+
/**
36+
* The name of the Sheet
37+
*/
2238
private String name;
2339

40+
/**
41+
* Create a new Sheet
42+
* @param excelWorkbook The Workbook where to create the Sheet
43+
* @return A ExcelSheet
44+
* @throws SheetAlreadyExistsException If a Sheet with that name already exists
45+
*/
2446
public static ExcelSheet create(ExcelWorkbook excelWorkbook) throws SheetAlreadyExistsException {
2547
return create(excelWorkbook, null);
2648
}
2749

50+
/**
51+
* Create a new Sheet
52+
* @param excelWorkbook The Workbook where to create the Sheet
53+
* @param sheetName The name of the sheet
54+
* @return A ExcelSheet
55+
* @throws SheetAlreadyExistsException If a Sheet with that name already exists
56+
*/
2857
public static ExcelSheet create(ExcelWorkbook excelWorkbook, String sheetName) throws SheetAlreadyExistsException {
2958
Workbook workbook = excelWorkbook.getWorkbook();
3059
Sheet sheet;
@@ -38,10 +67,18 @@ public static ExcelSheet create(ExcelWorkbook excelWorkbook, String sheetName) t
3867
return new ExcelSheet(sheet, workbook.getSheetIndex(sheet), sheet.getSheetName());
3968
}
4069

70+
/**
71+
* Returns the Workbook to which it belongs
72+
* @return A ExcelWorkbook
73+
*/
4174
public ExcelWorkbook getWorkbook() {
4275
return new ExcelWorkbook(this.getSheet().getWorkbook());
4376
}
4477

78+
/**
79+
* The list of Rows related to the Sheet
80+
* @return A list of Rows
81+
*/
4582
public List<ExcelRow> getRows() {
4683
List<ExcelRow> excelRows = new LinkedList<>();
4784
for (Row row : this.sheet) {
@@ -51,14 +88,28 @@ public List<ExcelRow> getRows() {
5188
return excelRows;
5289
}
5390

91+
/**
92+
* Create a new Row in the Sheet
93+
* @param index The index in the Sheet
94+
* @return A Row
95+
*/
5496
public ExcelRow createRow(Integer index) {
5597
return new ExcelRow(this.sheet.createRow(index), index);
5698
}
5799

100+
/**
101+
* Retrieves the index of the last Row
102+
* @return The index of the last Row
103+
*/
58104
public Integer getLastRowIndex() {
59105
return this.sheet.getLastRowNum();
60106
}
61107

108+
/**
109+
* Counts how many Rows are compiled
110+
* @param alsoEmpty {@code true} if you want to count Rows that have all empty Cells
111+
* @return The number of Rows compiled
112+
*/
62113
public Integer countAllRows(Boolean alsoEmpty) {
63114
Integer count = this.getLastRowIndex() + 1;
64115
if (alsoEmpty)

0 commit comments

Comments
 (0)