Skip to content

Commit 2dd519f

Browse files
authored
Merge branch 'master' into JAVA-8204
2 parents 67a62f8 + dc5826c commit 2dd519f

File tree

209 files changed

+3217
-1314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+3217
-1314
lines changed

algorithms-miscellaneous-5/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
<artifactId>guava</artifactId>
3535
<version>${guava.version}</version>
3636
</dependency>
37-
<dependency>
38-
<groupId>org.junit.platform</groupId>
39-
<artifactId>junit-platform-commons</artifactId>
40-
<version>${junit-platform.version}</version>
41-
</dependency>
4237
<dependency>
4338
<groupId>org.assertj</groupId>
4439
<artifactId>assertj-core</artifactId>

algorithms-miscellaneous-6/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
<artifactId>guava</artifactId>
2020
<version>${guava.version}</version>
2121
</dependency>
22-
<dependency>
23-
<groupId>org.junit.platform</groupId>
24-
<artifactId>junit-platform-commons</artifactId>
25-
<version>${junit-platform.version}</version>
26-
</dependency>
2722
<dependency>
2823
<groupId>org.assertj</groupId>
2924
<artifactId>assertj-core</artifactId>

algorithms-sorting-2/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
<version>${lombok.version}</version>
3030
<scope>provided</scope>
3131
</dependency>
32-
<dependency>
33-
<groupId>org.junit.jupiter</groupId>
34-
<artifactId>junit-jupiter-api</artifactId>
35-
<version>${junit-jupiter.version}</version>
36-
<scope>test</scope>
37-
</dependency>
3832
<dependency>
3933
<groupId>org.assertj</groupId>
4034
<artifactId>assertj-core</artifactId>

algorithms-sorting/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030
<version>${lombok.version}</version>
3131
<scope>provided</scope>
3232
</dependency>
33-
<dependency>
34-
<groupId>org.junit.jupiter</groupId>
35-
<artifactId>junit-jupiter-api</artifactId>
36-
<version>${junit-jupiter.version}</version>
37-
<scope>test</scope>
38-
</dependency>
3933
<dependency>
4034
<groupId>org.assertj</groupId>
4135
<artifactId>assertj-core</artifactId>

apache-poi/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ This module contains articles about Apache POI
1212
- [Read Excel Cell Value Rather Than Formula With Apache POI](https://www.baeldung.com/apache-poi-read-cell-value-formula)
1313
- [Setting Formulas in Excel with Apache POI](https://www.baeldung.com/java-apache-poi-set-formulas)
1414
- [Insert a Row in Excel Using Apache POI](https://www.baeldung.com/apache-poi-insert-excel-row)
15+
- [Multiline Text in Excel Cell Using Apache POI](https://www.baeldung.com/apache-poi-write-multiline-text)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.poi.excel.cellstyle;
2+
3+
import org.apache.poi.ss.usermodel.Cell;
4+
import org.apache.poi.ss.usermodel.CellStyle;
5+
import org.apache.poi.ss.usermodel.FillPatternType;
6+
import org.apache.poi.ss.usermodel.IndexedColors;
7+
8+
public class CellStyleHandler {
9+
10+
public void changeCellBackgroundColor(Cell cell) {
11+
CellStyle cellStyle = cell.getCellStyle();
12+
if(cellStyle == null) {
13+
cellStyle = cell.getSheet().getWorkbook().createCellStyle();
14+
}
15+
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
16+
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
17+
cell.setCellStyle(cellStyle);
18+
}
19+
20+
public void changeCellBackgroundColorWithPattern(Cell cell) {
21+
CellStyle cellStyle = cell.getCellStyle();
22+
if(cellStyle == null) {
23+
cellStyle = cell.getSheet().getWorkbook().createCellStyle();
24+
}
25+
cellStyle.setFillBackgroundColor(IndexedColors.BLACK.index);
26+
cellStyle.setFillPattern(FillPatternType.BIG_SPOTS);
27+
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
28+
cell.setCellStyle(cellStyle);
29+
}
30+
}
7.32 KB
Binary file not shown.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.baeldung.poi.excel.cellstyle;
2+
3+
import org.apache.poi.ss.usermodel.*;
4+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import java.io.FileOutputStream;
9+
import java.io.IOException;
10+
import java.io.OutputStream;
11+
import java.net.URISyntaxException;
12+
import java.nio.file.Paths;
13+
14+
import static org.junit.Assert.assertEquals;
15+
16+
public class CellStyleHandlerUnitTest {
17+
private static final String FILE_NAME = "cellstyle/CellStyleHandlerTest.xlsx";
18+
private static final int SHEET_INDEX = 0;
19+
private static final int ROW_INDEX = 0;
20+
private static final int CELL_INDEX = 0;
21+
22+
private String fileLocation;
23+
private CellStyleHandler cellStyleHandler;
24+
25+
@Before
26+
public void setup() throws URISyntaxException {
27+
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
28+
cellStyleHandler = new CellStyleHandler();
29+
}
30+
31+
@Test
32+
public void givenWorkbookCell_whenChangeCellBackgroundColor() throws IOException {
33+
Workbook workbook = new XSSFWorkbook(fileLocation);
34+
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
35+
Row row = sheet.getRow(ROW_INDEX);
36+
Cell cell = row.getCell(CELL_INDEX);
37+
38+
cellStyleHandler.changeCellBackgroundColor(cell);
39+
40+
assertEquals(IndexedColors.LIGHT_BLUE.index, cell.getCellStyle().getFillForegroundColor());
41+
workbook.close();
42+
}
43+
44+
@Test
45+
public void givenWorkbookCell_whenChangeCellBackgroundColorWithPattern() throws IOException {
46+
Workbook workbook = new XSSFWorkbook(fileLocation);
47+
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
48+
Row row = sheet.getRow(ROW_INDEX);
49+
Cell cell = row.getCell(CELL_INDEX + 1);
50+
51+
cellStyleHandler.changeCellBackgroundColorWithPattern(cell);
52+
53+
assertEquals(IndexedColors.LIGHT_BLUE.index, cell.getCellStyle().getFillForegroundColor());
54+
workbook.close();
55+
}
56+
}

atomikos/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@
7171
<artifactId>derby</artifactId>
7272
<version>${derby.version}</version>
7373
</dependency>
74-
<dependency>
75-
<groupId>org.junit.vintage</groupId>
76-
<artifactId>junit-vintage-engine</artifactId>
77-
<version>${junit-jupiter.version}</version>
78-
<scope>test</scope>
79-
</dependency>
8074
<!-- the JTA API -->
8175
<dependency>
8276
<groupId>javax.transaction</groupId>

core-java-modules/core-java-11-2/pom.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,6 @@
3131
<artifactId>mockserver-junit-jupiter</artifactId>
3232
<version>${mockserver.version}</version>
3333
</dependency>
34-
<dependency>
35-
<groupId>org.junit.jupiter</groupId>
36-
<artifactId>junit-jupiter-engine</artifactId>
37-
<version>${junit-jupiter.version}</version>
38-
<scope>test</scope>
39-
</dependency>
40-
<dependency>
41-
<groupId>org.junit.jupiter</groupId>
42-
<artifactId>junit-jupiter-params</artifactId>
43-
<version>${junit-jupiter.version}</version>
44-
<scope>test</scope>
45-
</dependency>
46-
<dependency>
47-
<groupId>org.junit.jupiter</groupId>
48-
<artifactId>junit-jupiter-api</artifactId>
49-
<version>${junit-jupiter.version}</version>
50-
<scope>test</scope>
51-
</dependency>
5234
<dependency>
5335
<groupId>org.apache.commons</groupId>
5436
<artifactId>commons-lang3</artifactId>

0 commit comments

Comments
 (0)