diff options
author | PJ Fanning <fanningpj@apache.org> | 2023-03-07 22:03:58 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2023-03-07 22:03:58 +0000 |
commit | 1639f8b923bb4a56e56bf76d1b8dd3449a7f1814 (patch) | |
tree | b574f2550cf504dca05e6ed575cd25f006a55d3c /poi-ooxml | |
parent | 4ec643c624caa8fc56f2b2e6b36c59cbeb8529a3 (diff) | |
download | poi-1639f8b923bb4a56e56bf76d1b8dd3449a7f1814.tar.gz poi-1639f8b923bb4a56e56bf76d1b8dd3449a7f1814.zip |
sxssf date style test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1908173 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java index 98d14afb40..c0011da4e2 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java @@ -34,6 +34,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.time.LocalDate; import java.util.Arrays; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; @@ -43,7 +44,9 @@ import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.ss.tests.usermodel.BaseTestXWorkbook; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; @@ -648,6 +651,31 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { } } + @Test + void dateStyle() throws IOException { + try ( + SXSSFWorkbook workbook = new SXSSFWorkbook(); + UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + ) { + SXSSFSheet sheet = workbook.createSheet(); + SXSSFRow row = sheet.createRow(0); + SXSSFCreationHelper createHelper = (SXSSFCreationHelper) workbook.getCreationHelper(); + CellStyle cellStyle = workbook.createCellStyle(); + cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("dd.MM.yyyy")); + SXSSFCell cell = row.createCell(0); + cell.setCellValue(LocalDate.parse("2023-03-07")); + cell.setCellStyle(cellStyle); + workbook.write(bos); + + try (XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bos.toInputStream())) { + XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); + DataFormatter dataFormatter = new DataFormatter(); + final String result = dataFormatter.formatCellValue(xssfSheet.getRow(0).getCell(0)); + assertEquals("07.03.2023", result); + } + } + } + @Override @Disabled("not implemented") protected void changeSheetNameWithSharedFormulas() { |