options) {
return;
}
this.sheetProtectionOptions = options;
- this.passwordHash = hashPassword(password);
+ this.passwordHash = LegacyProtectionHash.hashPassword(password);
}
/**
* Protects the sheet from viewing by hiding it and locking
@@ -578,29 +582,6 @@ public void removeAutoFilter() {
autoFilterRange = null;
}
- /**
- * Hash the password.
- * @param password The password to hash.
- * @return The password hash as a hex string (2 bytes)
- */
- private static String hashPassword(String password) {
- byte[] passwordCharacters = password.getBytes();
- int hash = 0;
- if (passwordCharacters.length > 0) {
- int charIndex = passwordCharacters.length;
- while (charIndex-- > 0) {
- hash = ((hash >> 14) & 0x01) | ((hash << 1) & 0x7fff);
- hash ^= passwordCharacters[charIndex];
- }
- // also hash with charcount
- hash = ((hash >> 14) & 0x01) | ((hash << 1) & 0x7fff);
- hash ^= passwordCharacters.length;
- hash ^= (0x8000 | ('N' << 8) | 'K');
- }
-
- return Integer.toHexString(hash & 0xffff);
- }
-
/**
* Specify the width for the given column. Will autoSize by default.
*
@@ -933,6 +914,27 @@ public void finish() throws IOException {
int index = workbook.getIndex(this);
writer.append("");
+ writeSheetProtection();
+ writeAutoFilter();
+ writeMergedCells();
+ writeConditionalFormattings();
+ writeShading();
+ writeDataValidations();
+ writeHyperlinks();
+ writePageMargins();
+ writePageSetup();
+ writeHeaderFooter();
+ writeDrawingReferences(index);
+ writeTableParts();
+ writer.append("");
+ workbook.endFile();
+
+ writeRelatedParts(index);
+ rows.clear();
+ finished = true;
+ }
+
+ private void writeSheetProtection() throws IOException {
if (passwordHash != null) {
writer.append("");
}
+ }
+
+ private void writeAutoFilter() throws IOException {
if (autoFilterRange != null) {
writer.append("").append("");
}
+ }
+
+ private void writeMergedCells() throws IOException {
if (!mergedRanges.isEmpty()) {
writer.append("");
for (Range r : mergedRanges) {
@@ -954,6 +962,9 @@ public void finish() throws IOException {
}
writer.append("");
}
+ }
+
+ private void writeConditionalFormattings() throws IOException {
if (!conditionalFormattings.isEmpty()) {
int priority = 1;
for (ConditionalFormatting v: conditionalFormattings) {
@@ -961,12 +972,18 @@ public void finish() throws IOException {
v.write(writer);
}
}
+ }
+
+ private void writeShading() throws IOException {
for (AlternateShading a : alternateShadingRanges) {
a.write(writer);
}
for (Shading s : shadingRanges) {
s.write(writer);
}
+ }
+
+ private void writeDataValidations() throws IOException {
if (!dataValidations.isEmpty()) {
writer.append("");
for (DataValidation v: dataValidations) {
@@ -974,6 +991,9 @@ public void finish() throws IOException {
}
writer.append("");
}
+ }
+
+ private void writeHyperlinks() throws IOException {
if (!hyperlinkRanges.isEmpty()) {
writer.append("");
for (Map.Entry hr : hyperlinkRanges.entrySet()) {
@@ -991,6 +1011,9 @@ public void finish() throws IOException {
}
writer.append("");
}
+ }
+
+ private void writePageMargins() throws IOException {
/* set page margins for the print setup (see in print preview) */
String margins = "";
writer.append(margins);
+ }
+ private void writePageSetup() throws IOException {
/* set page orientation for the print setup */
writer.append("");
+ }
+ private void writeHeaderFooter() throws IOException {
/* write to header and footer */
writer.append("");
writer.append("");
@@ -1024,8 +1051,9 @@ public void finish() throws IOException {
footerEntry.write(writer);
}
writer.append("");
+ }
-
+ private void writeDrawingReferences(int index) throws IOException {
// Drawing references
if (!pictures.isEmpty() || !comments.isEmpty()) {
if (!pictures.isEmpty()) {
@@ -1043,6 +1071,9 @@ public void finish() throws IOException {
writer.append("");
}
}
+ }
+
+ private void writeTableParts() throws IOException {
if (!tables.isEmpty()){
writer.append("");
for (Map.Entry entry : tables.entrySet()) {
@@ -1050,10 +1081,9 @@ public void finish() throws IOException {
}
writer.append("");
}
+ }
- writer.append("");
- workbook.endFile();
-
+ private void writeRelatedParts(int index) throws IOException {
/* write picture files */
if (!pictures.isEmpty()) {
// First, write the drawing relationships file (this assigns rIds to pictures)
@@ -1088,9 +1118,6 @@ public void finish() throws IOException {
if (!relationships.isEmpty()) {
workbook.writeFile("xl/worksheets/_rels/sheet"+index+".xml.rels",relationships::write);
}
- // Free memory; we no longer need this data
- rows.clear();
- finished = true;
}
/**
@@ -1108,73 +1135,94 @@ public void finish() throws IOException {
*/
public void flush() throws IOException {
if (writer == null) {
- int index = workbook.getIndex(this);
- writer = workbook.beginFile("xl/worksheets/sheet" + index + ".xml");
- writer.append("");
- writer.append("");
- writer.append("");
- if (tabColor != null) {
- writer.append("");
- }
- if (!rowSumsBelow || !rowSumsRight) {
- writer.append("");
- }
- writer.append("");
- writer.append("");
- writer.append("");
- if (freezeLeftColumns > 0 || freezeTopRows > 0) {
- writeFreezePane(writer);
+ startSheet();
+ }
+ writeRows();
+ writer.flush();
+ }
+
+ private void startSheet() throws IOException {
+ int index = workbook.getIndex(this);
+ writer = workbook.beginFile("xl/worksheets/sheet" + index + ".xml");
+ writer.append("");
+ writer.append("");
+ writeSheetProperties();
+ writer.append("");
+ writeSheetViews();
+ writer.append("");
+ writeColumnsIfNeeded();
+ writer.append("");
+ }
+
+ private void writeSheetProperties() throws IOException {
+ writer.append("");
+ if (tabColor != null) {
+ writer.append("");
+ }
+ if (!rowSumsBelow || !rowSumsRight) {
+ writer.append("");
- writer.append("");
- final int nbCols = rows.stream().filter(Objects::nonNull).mapToInt(r -> r.length).max().orElse(0);
- final int maxHideCol = hiddenColumns.stream().mapToInt(a -> a).max().orElse(0);
- final int maxStyleCol = colStyles.values().stream().mapToInt(Column::getColNumber).max().orElse(0);
- final int maxNoZeroIndex = groupColumns.getMaxNoZeroIndex();
- if (nbCols > 0 || !hiddenColumns.isEmpty()||maxNoZeroIndex!=-1 || !colStyles.isEmpty()) {
- int maxCol = Math.max(nbCols, Math.max(Math.max(maxHideCol,maxNoZeroIndex), maxStyleCol) + 1);
- writeCols(writer, maxCol);
+ if (!rowSumsRight) {
+ writer.append("summaryRight=\"0\" ");
}
- writer.append("");
+ writer.append("/>");
}
+ writer.append("");
+ }
+
+ private void writeSheetViews() throws IOException {
+ writer.append("");
+ if (freezeLeftColumns > 0 || freezeTopRows > 0) {
+ writeFreezePane(writer);
+ }
+ writer.append("");
+ }
+
+ private void writeColumnsIfNeeded() throws IOException {
+ final int nbCols = rows.stream().filter(Objects::nonNull).mapToInt(r -> r.length).max().orElse(0);
+ final int maxHideCol = hiddenColumns.stream().mapToInt(a -> a).max().orElse(0);
+ final int maxStyleCol = colStyles.values().stream().mapToInt(Column::getColNumber).max().orElse(0);
+ final int maxNoZeroIndex = groupColumns.getMaxNoZeroIndex();
+ if (nbCols > 0 || !hiddenColumns.isEmpty()||maxNoZeroIndex!=-1 || !colStyles.isEmpty()) {
+ int maxCol = Math.max(nbCols, Math.max(Math.max(maxHideCol,maxNoZeroIndex), maxStyleCol) + 1);
+ writeCols(writer, maxCol);
+ }
+ }
+
+ private void writeRows() throws IOException {
final int nbRows = rows.size();
final int maxHideRow = hiddenRows.stream().mapToInt(a -> a).max().orElse(0);
final int maxGroupRow = groupRows.getMaxNoZeroIndex();
final int maxRow = Math.max(nbRows, Math.max(maxGroupRow,maxHideRow) + 1);
for (int r = flushedRows; r < maxRow; ++r) {
- boolean notEmptyRow = r < rows.size();
- Cell[] row = notEmptyRow ? rows.get(r) : null;
- boolean isHidden = hiddenRows.contains(r);
- byte groupLevel = groupRows.get(r);
- if (row != null || isHidden || groupLevel != 0) {
- writeRow(writer, r, isHidden,groupLevel,
- rowHeights.get(r), row);
- }
- if (notEmptyRow) {
- rows.set(r, null); // free flushed row data
- }
+ writeRowIfPresent(r);
}
flushedRows = maxRow - 1;
+ }
-
- writer.flush();
+ private void writeRowIfPresent(int rowIndex) throws IOException {
+ boolean notEmptyRow = rowIndex < rows.size();
+ Cell[] row = notEmptyRow ? rows.get(rowIndex) : null;
+ boolean isHidden = hiddenRows.contains(rowIndex);
+ byte groupLevel = groupRows.get(rowIndex);
+ if (row != null || isHidden || groupLevel != 0) {
+ writeRow(writer, rowIndex, isHidden, groupLevel, rowHeights.get(rowIndex), row);
+ }
+ if (notEmptyRow) {
+ rows.set(rowIndex, null); // free flushed row data
+ }
}
/**
diff --git a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java
index 1ec32dad..c482031d 100644
--- a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java
+++ b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java
@@ -313,101 +313,90 @@ void testForAllFeatures() throws Exception {
//set tab color
ws.setTabColor("F381E0");
- //set values for cell
- ws.value(0, 0, "Hello fastexcel");
- ws.inlineString(0, 1, "Hello fastexcel (inline)");
- ws.value(1, 0, 1024.2048);
- ws.value(2, 0, true);
- ws.value(3, 0, new Date());
- ws.value(4, 0, LocalDateTime.now());
- ws.value(5, 0, LocalDate.now());
- ws.value(6, 0, ZonedDateTime.now());
- //set hyperlink for cell
- ws.hyperlink(7, 0, new HyperLink("https://github.com/dhatim/fastexcel", "Test_Hyperlink_For_Cell"));
- //set comment for cell
- ws.comment(8, 0, "Test_Comment");
- //set header and footer
- ws.header("Test_Header", Position.CENTER);
- ws.footer("Test_Footer", Position.LEFT);
- //set hide row
- ws.value(9, 0, "You can't see this row");
- ws.hideRow(9);
- //set column width
- ws.width(1, 20);
- //set zoom
- ws.setZoom(120);
- //set formula
- ws.value(10, 0, 44444);
- ws.value(10, 1, 55555);
- ws.formula(10, 2, "=SUM(A11,B11)");
- //set style for cell
- ws.value(11, 0, "Test_Cell_Style");
- ws.style(11, 0)
- .borderStyle(BorderSide.DIAGONAL, BorderStyle.MEDIUM)
- .fontSize(20)
- .fontColor(Color.RED)
- .italic()
- .bold()
- .fillColor(Color.YELLOW)
- .fontName("Cooper Black")
- .borderColor(Color.SEA_BLUE)
- .underlined()
- .strikethrough()
- .rotation(90)
- .set();
- //merge cells
- ws.range(12, 0, 12, 3).merge();
- //set hyperlink for range
- ws.range(13, 0, 13, 3).setHyperlink(new HyperLink("https://github.com/dhatim/fastexcel", "Test_Hyperlink_For_Range"));
- //set name for range
- ws.range(14, 0, 14, 3).setName("Test_Set_Name");
- //set style for range
- ws.value(15, 0, "Test_Range_Style");
- ws.range(15, 0, 19, 3).style()
- .borderStyle(BorderSide.DIAGONAL, BorderStyle.MEDIUM)
- .fontSize(20)
- .fontColor(Color.RED)
- .italic()
- .bold()
- .fillColor(Color.YELLOW)
- .fontName("Cooper Black")
- .borderColor(Color.SEA_BLUE)
- .underlined()
- .strikethrough()
- .shadeAlternateRows(Color.SEA_BLUE)
- .shadeRows(Color.RED, 1)
- .set();
- //protect the sheet
- ws.protect("1234");
- //autoFilter
- ws.value(21, 0, "A");
- ws.value(21, 1, "A");
- ws.value(21, 2, "A");
- ws.value(22, 0, "B");
- ws.value(22, 1, "B");
- ws.value(22, 2, "B");
- ws.setAutoFilter(20, 0, 22, 2);
-
- //validation
- ws.value(23, 0, "ABAB");
- ws.value(23, 1, "CDCD");
- ws.value(24, 0, "EFEF");
- ws.value(24, 1, "GHGH");
- ws.range(25, 0, 25, 1).validateWithList(ws.range(23, 0, 24, 1));
-
- //table
- ws.range(0, 0, 5, 2).createTable();
-
- //group
- ws.groupRows(3, 4);
- ws.groupRows(2, 5);
-
- ws.groupCols(6, 7);
- ws.groupCols(4, 8);
- //
- ws.rowSumsBelow(false);
- ws.rowSumsRight(false);
- });
+ addAllFeatureValues(ws);
+ addAllFeatureStyleAndRanges(ws);
+ addAllFeatureSheetStructure(ws);
+ });
+ }
+
+ private static void addAllFeatureValues(Worksheet ws) {
+ ws.value(0, 0, "Hello fastexcel");
+ ws.inlineString(0, 1, "Hello fastexcel (inline)");
+ ws.value(1, 0, 1024.2048);
+ ws.value(2, 0, true);
+ ws.value(3, 0, new Date());
+ ws.value(4, 0, LocalDateTime.now());
+ ws.value(5, 0, LocalDate.now());
+ ws.value(6, 0, ZonedDateTime.now());
+ ws.hyperlink(7, 0, new HyperLink("https://github.com/dhatim/fastexcel", "Test_Hyperlink_For_Cell"));
+ ws.comment(8, 0, "Test_Comment");
+ ws.header("Test_Header", Position.CENTER);
+ ws.footer("Test_Footer", Position.LEFT);
+ ws.value(9, 0, "You can't see this row");
+ ws.hideRow(9);
+ ws.width(1, 20);
+ ws.setZoom(120);
+ ws.value(10, 0, 44444);
+ ws.value(10, 1, 55555);
+ ws.formula(10, 2, "=SUM(A11,B11)");
+ }
+
+ private static void addAllFeatureStyleAndRanges(Worksheet ws) {
+ ws.value(11, 0, "Test_Cell_Style");
+ ws.style(11, 0)
+ .borderStyle(BorderSide.DIAGONAL, BorderStyle.MEDIUM)
+ .fontSize(20)
+ .fontColor(Color.RED)
+ .italic()
+ .bold()
+ .fillColor(Color.YELLOW)
+ .fontName("Cooper Black")
+ .borderColor(Color.SEA_BLUE)
+ .underlined()
+ .strikethrough()
+ .rotation(90)
+ .set();
+ ws.range(12, 0, 12, 3).merge();
+ ws.range(13, 0, 13, 3).setHyperlink(new HyperLink("https://github.com/dhatim/fastexcel", "Test_Hyperlink_For_Range"));
+ ws.range(14, 0, 14, 3).setName("Test_Set_Name");
+ ws.value(15, 0, "Test_Range_Style");
+ ws.range(15, 0, 19, 3).style()
+ .borderStyle(BorderSide.DIAGONAL, BorderStyle.MEDIUM)
+ .fontSize(20)
+ .fontColor(Color.RED)
+ .italic()
+ .bold()
+ .fillColor(Color.YELLOW)
+ .fontName("Cooper Black")
+ .borderColor(Color.SEA_BLUE)
+ .underlined()
+ .strikethrough()
+ .shadeAlternateRows(Color.SEA_BLUE)
+ .shadeRows(Color.RED, 1)
+ .set();
+ }
+
+ private static void addAllFeatureSheetStructure(Worksheet ws) {
+ ws.protect("1234");
+ ws.value(21, 0, "A");
+ ws.value(21, 1, "A");
+ ws.value(21, 2, "A");
+ ws.value(22, 0, "B");
+ ws.value(22, 1, "B");
+ ws.value(22, 2, "B");
+ ws.setAutoFilter(20, 0, 22, 2);
+ ws.value(23, 0, "ABAB");
+ ws.value(23, 1, "CDCD");
+ ws.value(24, 0, "EFEF");
+ ws.value(24, 1, "GHGH");
+ ws.range(25, 0, 25, 1).validateWithList(ws.range(23, 0, 24, 1));
+ ws.range(0, 0, 5, 2).createTable();
+ ws.groupRows(3, 4);
+ ws.groupRows(2, 5);
+ ws.groupCols(6, 7);
+ ws.groupCols(4, 8);
+ ws.rowSumsBelow(false);
+ ws.rowSumsRight(false);
}
@Test
diff --git a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/PoiCompatibilityTest.java b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/PoiCompatibilityTest.java
index 67b3debf..2d7abf56 100644
--- a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/PoiCompatibilityTest.java
+++ b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/PoiCompatibilityTest.java
@@ -51,20 +51,8 @@ void singleWorksheet() throws Exception {
ws.pageOrientation("landscape");
ws.pageScale(80);
ws.width(0, 2);
- int i = 1;
- ws.hideRow(i);
- ws.value(i, i++, stringValue);
- ws.inlineString(i, i++, stringValue);
- ws.value(i, i++, dateValue);
- ws.value(i, i++, localDateTimeValue);
- ws.value(i, i++, zonedDateValue);
- ws.value(i, i++, doubleValue);
- ws.value(i, i++, intValue);
- ws.value(i, i++, longValue);
- ws.value(i, i++, bigDecimalValue);
- ws.value(i, i++, Boolean.TRUE);
- ws.value(i, i++, Boolean.FALSE);
- ws.hyperlink(i,i++, hyperlinkValue);
+ writeSingleWorksheetValues(ws, stringValue, dateValue, localDateTimeValue, zonedDateValue,
+ doubleValue, intValue, longValue, bigDecimalValue, hyperlinkValue);
try {
ws.close();
} catch (IOException ex) {
@@ -84,6 +72,35 @@ void singleWorksheet() throws Exception {
assertThat(xws.getPrintSetup().getScale()).isEqualTo((short)80);
Comparable row = xws.getRow(0);
assertThat(row).isNull();
+ assertSingleWorksheetValues(xws, stringValue, dateValue, localDateTimeValue, zonedDateValue,
+ timezone, doubleValue, intValue, longValue, bigDecimalValue, hyperlinkValue);
+ }
+
+ private static void writeSingleWorksheetValues(Worksheet ws, String stringValue, Date dateValue,
+ LocalDateTime localDateTimeValue, ZonedDateTime zonedDateValue,
+ double doubleValue, int intValue, long longValue,
+ BigDecimal bigDecimalValue, HyperLink hyperlinkValue) {
+ int i = 1;
+ ws.hideRow(i);
+ ws.value(i, i++, stringValue);
+ ws.inlineString(i, i++, stringValue);
+ ws.value(i, i++, dateValue);
+ ws.value(i, i++, localDateTimeValue);
+ ws.value(i, i++, zonedDateValue);
+ ws.value(i, i++, doubleValue);
+ ws.value(i, i++, intValue);
+ ws.value(i, i++, longValue);
+ ws.value(i, i++, bigDecimalValue);
+ ws.value(i, i++, Boolean.TRUE);
+ ws.value(i, i++, Boolean.FALSE);
+ ws.hyperlink(i,i++, hyperlinkValue);
+ }
+
+ private static void assertSingleWorksheetValues(XSSFSheet xws, String stringValue, Date dateValue,
+ LocalDateTime localDateTimeValue, ZonedDateTime zonedDateValue,
+ ZoneId timezone, double doubleValue, int intValue,
+ long longValue, BigDecimal bigDecimalValue,
+ HyperLink hyperlinkValue) {
int i = 1;
// poi column width is in 1/256 characters
assertThat(xws.getColumnWidth(0) / 256).isEqualTo(2);
@@ -91,8 +108,6 @@ void singleWorksheet() throws Exception {
assertThat(xws.getRow(i).getCell(i++).getStringCellValue()).isEqualTo(stringValue);
assertThat(xws.getRow(i).getCell(i++).getStringCellValue()).isEqualTo(stringValue);
assertThat(xws.getRow(i).getCell(i++).getDateCellValue()).isEqualTo(dateValue);
- // Check zoned timestamps have the same textual representation as the Dates extracted from the workbook
- // (Excel date serial numbers do not carry timezone information)
assertThat(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(xws.getRow(i).getCell(i++).getLocalDateTimeCellValue()))
.isEqualTo(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(localDateTimeValue));
assertThat(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(ZonedDateTime.of(xws.getRow(i).getCell(i++).getLocalDateTimeCellValue(), timezone)))
@@ -120,44 +135,7 @@ void multipleWorksheets() throws Exception {
ws.rowSumsRight(i == 0);
ws.rowSumsBelow(i == 0);
CompletableFuture cf = CompletableFuture.runAsync(() -> {
- for (int j = 0; j < numCols; ++j) {
- ws.value(0, j, "Column " + j);
- ws.style(0, j).bold().fontSize(12).fillColor(Color.GRAY2).set();
- for (int k = 1; k <= numRows; ++k) {
- switch (j) {
- case 0:
- ws.value(k, j, "String value " + k);
- break;
- case 1:
- ws.value(k, j, 2);
- break;
- case 2:
- ws.value(k, j, 3L);
- break;
- case 3:
- ws.value(k, j, 0.123);
- break;
- case 4:
- ws.value(k, j, new Date());
- ws.style(k, j).format("yyyy-MM-dd HH:mm:ss").set();
- break;
- case 5:
- ws.value(k, j, LocalDate.now());
- ws.style(k, j).format("yyyy-MM-dd").set();
- break;
- default:
- throw new IllegalArgumentException();
- }
- }
- }
- ws.formula(numRows + 1, 1, "SUM(" + ws.range(1, 1, numRows, 1).toString() + ")");
- ws.formula(numRows + 1, 2, "SUM(" + ws.range(1, 2, numRows, 2).toString() + ")");
- ws.formula(numRows + 1, 3, "SUM(" + ws.range(1, 3, numRows, 3).toString() + ")");
- ws.formula(numRows + 1, 4, "AVERAGE(" + ws.range(1, 4, numRows, 4).toString() + ")");
- ws.style(numRows + 1, 4).format("yyyy-MM-dd HH:mm:ss").set();
- ws.formula(numRows + 1, 5, "AVERAGE(" + ws.range(1, 5, numRows, 5).toString() + ")");
- ws.style(numRows + 1, 5).format("yyyy-MM-dd").bold().italic().fontColor(Color.RED).fontName("Garamond").fontSize(new BigDecimal("14.5")).horizontalAlignment("center").verticalAlignment("top").wrapText(true).set();
- ws.range(1, 0, numRows, numCols - 1).style().borderColor(Color.RED).borderStyle(BorderStyle.THICK).shadeAlternateRows(Color.RED).set();
+ populateConcurrentWorksheet(ws, numRows, numCols);
});
cfs[i] = cf;
}
@@ -189,6 +167,51 @@ void multipleWorksheets() throws Exception {
}
}
+ private static void populateConcurrentWorksheet(Worksheet ws, int numRows, int numCols) {
+ for (int j = 0; j < numCols; ++j) {
+ ws.value(0, j, "Column " + j);
+ ws.style(0, j).bold().fontSize(12).fillColor(Color.GRAY2).set();
+ for (int k = 1; k <= numRows; ++k) {
+ writeConcurrentCell(ws, k, j);
+ }
+ }
+ ws.formula(numRows + 1, 1, "SUM(" + ws.range(1, 1, numRows, 1).toString() + ")");
+ ws.formula(numRows + 1, 2, "SUM(" + ws.range(1, 2, numRows, 2).toString() + ")");
+ ws.formula(numRows + 1, 3, "SUM(" + ws.range(1, 3, numRows, 3).toString() + ")");
+ ws.formula(numRows + 1, 4, "AVERAGE(" + ws.range(1, 4, numRows, 4).toString() + ")");
+ ws.style(numRows + 1, 4).format("yyyy-MM-dd HH:mm:ss").set();
+ ws.formula(numRows + 1, 5, "AVERAGE(" + ws.range(1, 5, numRows, 5).toString() + ")");
+ ws.style(numRows + 1, 5).format("yyyy-MM-dd").bold().italic().fontColor(Color.RED).fontName("Garamond").fontSize(new BigDecimal("14.5")).horizontalAlignment("center").verticalAlignment("top").wrapText(true).set();
+ ws.range(1, 0, numRows, numCols - 1).style().borderColor(Color.RED).borderStyle(BorderStyle.THICK).shadeAlternateRows(Color.RED).set();
+ }
+
+ private static void writeConcurrentCell(Worksheet ws, int row, int col) {
+ switch (col) {
+ case 0:
+ ws.value(row, col, "String value " + row);
+ break;
+ case 1:
+ ws.value(row, col, 2);
+ break;
+ case 2:
+ ws.value(row, col, 3L);
+ break;
+ case 3:
+ ws.value(row, col, 0.123);
+ break;
+ case 4:
+ ws.value(row, col, new Date());
+ ws.style(row, col).format("yyyy-MM-dd HH:mm:ss").set();
+ break;
+ case 5:
+ ws.value(row, col, LocalDate.now());
+ ws.style(row, col).format("yyyy-MM-dd").set();
+ break;
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+
@Test
void sortWorksheets() throws Exception {
diff --git a/pom.xml b/pom.xml
index 286766c6..14b6d4f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,6 +9,7 @@
pom
+ fastexcel-core
fastexcel-writer
fastexcel-reader
e2e
@@ -76,6 +77,11 @@
2.22.0
test