-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
160 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/poiji/bind/mapping/PoijiDataFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.poiji.bind.mapping; | ||
|
||
import com.poiji.option.PoijiOptions; | ||
import org.apache.poi.ss.usermodel.DataFormatter; | ||
import org.apache.poi.ss.usermodel.DateUtil; | ||
import org.apache.poi.ss.util.NumberToTextConverter; | ||
|
||
/** | ||
* Created by hakan on 16.05.2021 | ||
*/ | ||
public class PoijiDataFormatter extends DataFormatter { | ||
|
||
PoijiOptions options; | ||
|
||
public PoijiDataFormatter(PoijiOptions options) { | ||
super(); | ||
this.options = options; | ||
} | ||
|
||
@Override | ||
public String formatRawCellContents(double value, int formatIndex, String formatString, boolean use1904Windowing) { | ||
if (!DateUtil.isADateFormat(formatIndex, formatString) && options.isRawData()) { | ||
return NumberToTextConverter.toText(value); | ||
} else { | ||
return super.formatRawCellContents(value, formatIndex, formatString, use1904Windowing); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.poiji.deserialize; | ||
|
||
import com.poiji.bind.Poiji; | ||
import com.poiji.deserialize.model.RowModel; | ||
import com.poiji.option.PoijiOptions; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Created by hakan on 02/08/2018 | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class RawValueTest { | ||
|
||
private String path; | ||
|
||
public RawValueTest(String path) { | ||
this.path = path; | ||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: ({0})={1}") | ||
public static Iterable<Object[]> queries() { | ||
return Arrays.asList(new Object[][]{ | ||
{"src/test/resources/raw_value.xls"}, | ||
{"src/test/resources/raw_value.xlsx"}, | ||
}); | ||
} | ||
|
||
@Test | ||
public void shouldMapCalculations() { | ||
|
||
PoijiOptions options = PoijiOptions.PoijiOptionsBuilder.settings().headerCount(0).rawData(true).build(); | ||
List<RowModel> models = Poiji.fromExcel(new File(path), RowModel.class, options); | ||
|
||
for (RowModel model : models) { | ||
assertThat(model.getRowValue(), is(57363987456321L)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.poiji.deserialize.model; | ||
|
||
import com.poiji.annotation.ExcelCell; | ||
|
||
/** | ||
* Created by hakan on 16.05.2021 | ||
*/ | ||
public class RowModel { | ||
|
||
@ExcelCell(0) | ||
private Long rowValue; | ||
|
||
public Long getRowValue() { | ||
return rowValue; | ||
} | ||
|
||
public void setRowValue(Long rowValue) { | ||
this.rowValue = rowValue; | ||
} | ||
} |
Binary file not shown.
Binary file not shown.