Skip to content

Commit

Permalink
Merge branch 'release/4.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
astrapi69 committed Mar 1, 2019
2 parents b43a455 + 4c4d6db commit 69ec44e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 102 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
## Change log
----------------------

Version 4.0.1
-------------

CHANGED:

- update of parent version to 4.7
- update of file-worker dependency version to 5.1
- update of jcommons-lang dependency version to 5.1.1
- update of test-objects dependency version to 5.0.1

Version 4
-------------

Expand All @@ -13,6 +23,7 @@ CHANGED:
- update of jobject-evaluate dependency version to 2.5
- update of jobject-core dependency version to 2.5
- update of file-worker dependency version to 5.0.1
- update of poi dependency version to 4.0.1
- excluded logging dependencies

Version 3.17
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Add the following maven dependency to your project `pom.xml` if you want to impo
<properties>
...
<!-- POI-WORKER version -->
<poi-worker.version>4</poi-worker.version>
<poi-worker.version>4.0.1</poi-worker.version>
...
</properties>
...
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<parent>
<groupId>de.alpharogroup</groupId>
<artifactId>mvn-java-parent</artifactId>
<version>4.5</version>
<version>4.7</version>
<relativePath></relativePath>
</parent>

<artifactId>poi-worker</artifactId>
<version>4</version>
<version>4.0.1</version>

<name>${project.artifactId}</name>

Expand All @@ -21,18 +21,18 @@
<url>https://github.com/lightblueseas/${project.artifactId}</url>

<properties>
<!-- FILE-WORKER version -->
<file-worker.version>5.1</file-worker.version>
<!-- JCOMMONS-LANG version -->
<jcommons-lang.version>5.1</jcommons-lang.version>
<jcommons-lang.version>5.1.1</jcommons-lang.version>
<!-- TEST-OBJECTS version -->
<test-objects.version>5</test-objects.version>
<test-objects.version>5.0.1</test-objects.version>
<!-- EXTERNAL LIBRARIES versions -->
<poi.version>3.17</poi.version>
<poi.version>4.0.1</poi.version>
<!-- JOBJECT-EXTENSIONS version -->
<jobject-extensions.version>2.5</jobject-extensions.version>
<jobject-evaluate.version>${jobject-extensions.version}</jobject-evaluate.version>
<jobject-core.version>${jobject-extensions.version}</jobject-core.version>
<!-- FILE-WORKER version -->
<file-worker.version>5.0.1</file-worker.version>
</properties>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;

import lombok.experimental.UtilityClass;

/**
* The class {@link ExportExcelExtensions}.
* The class {@link ExportExcelExtensions} provides methods for export excel sheet {@link File}
* objects
*/
@UtilityClass
public final class ExportExcelExtensions
public class ExportExcelExtensions
{

/**
* Exportiert die übergebene excel-Datei in eine Liste mit zweidimensionalen Arrays für jeweils
* ein sheet in der excel-Datei.
* Exports the given excel sheet {@link File} and return a two dimensonal array which holds the
* sheets and arrays of the rows
*
* @param excelSheet
* Die excel-Datei.
* @return Gibt eine Liste mit zweidimensionalen Arrays für jeweils ein sheet in der excel-Datei
* zurück.
* the excel sheet {@link File}
* @return the a two dimensonal array which holds the sheets and arrays of the rows
* @throws IOException
* Fals ein Fehler beim Lesen aufgetreten ist.
* Signals that an I/O exception has occurred.
* @throws FileNotFoundException
* Fals die excel-Datei nicht gefunden wurde.
* Signals that the file was not found
*/
@SuppressWarnings("deprecation")
public static List<String[][]> exportWorkbook(final File excelSheet)
throws IOException, FileNotFoundException
{
Expand All @@ -85,42 +85,7 @@ public static List<String[][]> exportWorkbook(final File excelSheet)
{
for (int j = 0; j < columns; j++)
{
final HSSFCell cell = row.getCell(j);
if (null == cell)
{
excelSheetInTDArray[i][j] = "";
}
else
{
final int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_BLANK)
{
excelSheetInTDArray[i][j] = "";
}
else if (cellType == Cell.CELL_TYPE_BOOLEAN)
{
excelSheetInTDArray[i][j] = Boolean
.toString(cell.getBooleanCellValue());
}
else if (cellType == Cell.CELL_TYPE_ERROR)
{
excelSheetInTDArray[i][j] = "";
}
else if (cellType == Cell.CELL_TYPE_FORMULA)
{
excelSheetInTDArray[i][j] = cell.getCellFormula();
}
else if (cellType == Cell.CELL_TYPE_NUMERIC)
{
excelSheetInTDArray[i][j] = Double
.toString(cell.getNumericCellValue());
}
else if (cellType == Cell.CELL_TYPE_STRING)
{
excelSheetInTDArray[i][j] = cell.getRichStringCellValue()
.getString();
}
}
excelSheetInTDArray[i][j] = getCellValueAsString(row.getCell(j));
}
}
}
Expand All @@ -130,22 +95,61 @@ else if (cellType == Cell.CELL_TYPE_STRING)
return sheetList;
}

/**
* Gets the cell value as String from the given {@link Cell} object
*
* @param cell
* the cell
* @return the cell value
*/
public static String getCellValueAsString(Cell cell)
{
String result = null;
if (null == cell)
{
return "";
}
CellType cellType = cell.getCellType();

if (CellType.BLANK.equals(cellType))
{
result = "";
}
else if (CellType.BOOLEAN.equals(cellType))
{
result = Boolean.toString(cell.getBooleanCellValue());
}
else if (CellType.ERROR.equals(cellType))
{
result = "";
}
else if (CellType.FORMULA.equals(cellType))
{
result = cell.getCellFormula();
}
else if (CellType.NUMERIC.equals(cellType))
{
result = Double.toString(cell.getNumericCellValue());
}
else if (CellType.STRING.equals(cellType))
{
result = cell.getRichStringCellValue().getString();
}
return result;
}

/**
* Exportiert die übergebene excel-Datei in eine geschachtelte Liste mit Listen von sheets und
* Listen von den Zeilen der sheets von der excel-Datei.
* Exports the given excel sheet {@link File} in a list of lists with the list of the sheets and
* lists of the rows.
*
* @param excelSheet
* Die excel-Datei.
* @return Gibt eine Liste mit Listen von den sheets in der excel-Datei zurück. Die Listen mit
* den sheets beinhalten weitere Listen mit String die jeweils eine Zeile
* repräsentieren.
* the excel sheet {@link File}
* @return the a list with the sheets and lists of the rows.
* @throws IOException
* Fals ein Fehler beim Lesen aufgetreten ist.
* Signals that an I/O exception has occurred.
* @throws FileNotFoundException
* Fals die excel-Datei nicht gefunden wurde.
* Signals that the file was not found
*/
@SuppressWarnings("deprecation")
public static List<List<List<String>>> exportWorkbookAsStringList(final File excelSheet)
throws IOException, FileNotFoundException
{
Expand All @@ -168,39 +172,7 @@ public static List<List<List<String>>> exportWorkbookAsStringList(final File exc
final List<String> reihe = new ArrayList<>();
for (int j = 0; j < columns; j++)
{
final HSSFCell cell = row.getCell(j);
if (null == cell)
{
reihe.add("");
}
else
{
final int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_BLANK)
{
reihe.add("");
}
else if (cellType == Cell.CELL_TYPE_BOOLEAN)
{
reihe.add(Boolean.toString(cell.getBooleanCellValue()));
}
else if (cellType == Cell.CELL_TYPE_ERROR)
{
reihe.add("");
}
else if (cellType == Cell.CELL_TYPE_FORMULA)
{
reihe.add(cell.getCellFormula());
}
else if (cellType == Cell.CELL_TYPE_NUMERIC)
{
reihe.add(Double.toString(cell.getNumericCellValue()));
}
else if (cellType == Cell.CELL_TYPE_STRING)
{
reihe.add(cell.getRichStringCellValue().getString());
}
}
reihe.add(getCellValueAsString(row.getCell(j)));
}
excelSheetList.add(reihe);
}
Expand All @@ -222,7 +194,6 @@ else if (cellType == Cell.CELL_TYPE_STRING)
* @throws FileNotFoundException
* the file not found exception
*/
@SuppressWarnings("deprecation")
public static HSSFWorkbook replaceNullCellsIntoEmptyCells(final File excelSheet)
throws IOException, FileNotFoundException
{
Expand All @@ -245,7 +216,7 @@ public static HSSFWorkbook replaceNullCellsIntoEmptyCells(final File excelSheet)
HSSFCell cell = row.getCell(j);
if (cell == null)
{
cell = row.createCell(j, Cell.CELL_TYPE_BLANK);
cell = row.createCell(j, CellType.BLANK);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,6 @@ public void testReplaceNullCellsIntoEmptyCells() throws FileNotFoundException, I
workbook.write(fileOut);
workbook.close();
}
// FileOutputStream fileOut = new FileOutputStream(emptyWorkbook);
// workbook.write(fileOut);
// fileOut.close();
workbook.close();

HSSFWorkbook hssfWorkbook = ExportExcelExtensions
.replaceNullCellsIntoEmptyCells(emptyWorkbook);
Expand Down

0 comments on commit 69ec44e

Please sign in to comment.