Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ials into BAEL-4546
  • Loading branch information
Swapan Pramanick committed Nov 5, 2021
2 parents b2aaaea + 3efbc32 commit d17820b
Show file tree
Hide file tree
Showing 136 changed files with 1,595 additions and 1,078 deletions.
1 change: 1 addition & 0 deletions apache-poi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ This module contains articles about Apache POI
- [Read Excel Cell Value Rather Than Formula With Apache POI](https://www.baeldung.com/apache-poi-read-cell-value-formula)
- [Setting Formulas in Excel with Apache POI](https://www.baeldung.com/java-apache-poi-set-formulas)
- [Insert a Row in Excel Using Apache POI](https://www.baeldung.com/apache-poi-insert-excel-row)
- [Multiline Text in Excel Cell Using Apache POI](https://www.baeldung.com/apache-poi-write-multiline-text)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.baeldung.poi.excel.cellstyle;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;

public class CellStyleHandler {

public void changeCellBackgroundColor(Cell cell) {
CellStyle cellStyle = cell.getCellStyle();
if(cellStyle == null) {
cellStyle = cell.getSheet().getWorkbook().createCellStyle();
}
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell.setCellStyle(cellStyle);
}

public void changeCellBackgroundColorWithPattern(Cell cell) {
CellStyle cellStyle = cell.getCellStyle();
if(cellStyle == null) {
cellStyle = cell.getSheet().getWorkbook().createCellStyle();
}
cellStyle.setFillBackgroundColor(IndexedColors.BLACK.index);
cellStyle.setFillPattern(FillPatternType.BIG_SPOTS);
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
cell.setCellStyle(cellStyle);
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.baeldung.poi.excel.cellstyle;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Before;
import org.junit.Test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.nio.file.Paths;

import static org.junit.Assert.assertEquals;

public class CellStyleHandlerUnitTest {
private static final String FILE_NAME = "cellstyle/CellStyleHandlerTest.xlsx";
private static final int SHEET_INDEX = 0;
private static final int ROW_INDEX = 0;
private static final int CELL_INDEX = 0;

private String fileLocation;
private CellStyleHandler cellStyleHandler;

@Before
public void setup() throws URISyntaxException {
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
cellStyleHandler = new CellStyleHandler();
}

@Test
public void givenWorkbookCell_whenChangeCellBackgroundColor() throws IOException {
Workbook workbook = new XSSFWorkbook(fileLocation);
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
Row row = sheet.getRow(ROW_INDEX);
Cell cell = row.getCell(CELL_INDEX);

cellStyleHandler.changeCellBackgroundColor(cell);

assertEquals(IndexedColors.LIGHT_BLUE.index, cell.getCellStyle().getFillForegroundColor());
workbook.close();
}

@Test
public void givenWorkbookCell_whenChangeCellBackgroundColorWithPattern() throws IOException {
Workbook workbook = new XSSFWorkbook(fileLocation);
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
Row row = sheet.getRow(ROW_INDEX);
Cell cell = row.getCell(CELL_INDEX + 1);

cellStyleHandler.changeCellBackgroundColorWithPattern(cell);

assertEquals(IndexedColors.LIGHT_BLUE.index, cell.getCellStyle().getFillForegroundColor());
workbook.close();
}
}
18 changes: 0 additions & 18 deletions core-java-modules/core-java-11-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@
<artifactId>mockserver-junit-jupiter</artifactId>
<version>${mockserver.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
12 changes: 0 additions & 12 deletions core-java-modules/core-java-14/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
12 changes: 0 additions & 12 deletions core-java-modules/core-java-15/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
12 changes: 0 additions & 12 deletions core-java-modules/core-java-16/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
12 changes: 0 additions & 12 deletions core-java-modules/core-java-17/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
11 changes: 6 additions & 5 deletions core-java-modules/core-java-concurrency-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
</parent>

<dependencies>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.thread-weaver</groupId>
<artifactId>threadweaver</artifactId>
Expand All @@ -31,6 +26,12 @@
<artifactId>tempus-fugit</artifactId>
<version>${tempus-fugit.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.googlecode.multithreadedtc</groupId>
Expand Down
1 change: 1 addition & 0 deletions core-java-modules/core-java-jndi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
### Relevant Articles:

- [Java Naming and Directory Interface Overview](https://www.baeldung.com/jndi)
- [LDAP Authentication Using Pure Java](https://www.baeldung.com/java-ldap-auth)
30 changes: 13 additions & 17 deletions core-java-modules/core-java-jndi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@
</parent>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand All @@ -58,6 +41,18 @@
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-test-framework</artifactId>
<version>${apacheds.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.21.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -76,6 +71,7 @@
<properties>
<spring.version>5.0.9.RELEASE</spring.version>
<h2.version>1.4.199</h2.version>
<apacheds.version>2.0.0.AM26</apacheds.version>
<source.version>1.8</source.version>
<target.version>1.8</target.version>
</properties>
Expand Down
Loading

0 comments on commit d17820b

Please sign in to comment.