import org.apache.poi.ss.usermodel.BaseTestDataFormat;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
*/
}
}
-
- @Test
- public void testFormatCellValueDecimal() throws IOException {
- DataFormatter df = new DataFormatter();
-
- try (Workbook wb = new XSSFWorkbook()) {
- Cell cell = wb.createSheet("test").createRow(0).createCell(0);
- assertEquals("", df.formatCellValue(cell));
-
- cell.setCellValue(1.005);
- assertEquals("1.005", df.formatCellValue(cell));
- }
- }
-
+
}
import org.apache.poi.ss.usermodel.BaseTestDataFormat;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.DataFormat;
+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;
import org.junit.jupiter.api.Test;
/**
assertEquals("12'345'678", formatter.formatCellValue(lge));
}
}
+
+ @Test
+ public void testFormatCellValueDecimal() throws IOException {
+ DataFormatter df = new DataFormatter();
+
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Cell cell = wb.createSheet("test").createRow(0).createCell(0);
+ assertEquals("", df.formatCellValue(cell));
+
+ cell.setCellValue(1.005);
+ assertEquals("1.005", df.formatCellValue(cell));
+
+ DataFormat format = wb.createDataFormat();
+ CellStyle cellStyle = wb.createCellStyle();
+ cellStyle.setDataFormat(format.getFormat("0.00"));
+ cell.setCellStyle(cellStyle);
+ assertEquals("1.01", df.formatCellValue(cell));
+ }
+ }
+
}