use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyJLabelCellForDateFormat.
@Test
public void testApplyJLabelCellForDateFormat() throws Exception {
// Create a workbook, row and cell to test with
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell0 = row.createCell(0);
Cell cell1 = row.createCell(1);
CellFormat cf = CellFormat.getInstance("dd/mm/yyyy");
JLabel label0 = new JLabel();
JLabel label1 = new JLabel();
cell0.setCellValue(10);
CellFormatResult result0 = cf.apply(label0, cell0);
assertEquals("10/01/1900", result0.text);
assertEquals("10/01/1900", label0.getText());
cell1.setCellValue(-1);
CellFormatResult result1 = cf.apply(label1, cell1);
assertEquals(_255_POUND_SIGNS, result1.text);
assertEquals(_255_POUND_SIGNS, label1.getText());
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class CellFormatTestBase method readFlags.
/**
* Read the flags from the workbook. Flags are on the sheet named "Flags",
* and consist of names in column A and values in column B. These are put
* into a map that can be queried later.
*
* @param wb The workbook to look in.
*/
private void readFlags(Workbook wb) {
Sheet flagSheet = wb.getSheet("Flags");
testFlags = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
if (flagSheet != null) {
int end = flagSheet.getLastRowNum();
// Skip the header row, therefore "+ 1"
for (int r = flagSheet.getFirstRowNum() + 1; r <= end; r++) {
Row row = flagSheet.getRow(r);
if (row == null)
continue;
String flagName = row.getCell(0).getStringCellValue();
String flagValue = row.getCell(1).getStringCellValue();
if (flagName.length() > 0) {
testFlags.put(flagName, flagValue);
}
}
}
tryAllColors = flagBoolean("AllColors", true);
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyJLabelCellForTimeFormat.
@Test
public void testApplyJLabelCellForTimeFormat() throws Exception {
// Create a workbook, row and cell to test with
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
CellFormat cf = CellFormat.getInstance("hh:mm");
JLabel label = new JLabel();
cell.setCellValue(DateUtil.convertTime("03:04:05"));
CellFormatResult result = cf.apply(label, cell);
assertEquals("03:04", result.text);
assertEquals("03:04", label.getText());
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyJLabelCellForDateFormatAndNegativeFormat.
@Test
public void testApplyJLabelCellForDateFormatAndNegativeFormat() throws Exception {
// Create a workbook, row and cell to test with
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell0 = row.createCell(0);
Cell cell1 = row.createCell(1);
CellFormat cf = CellFormat.getInstance("dd/mm/yyyy;(0)");
JLabel label0 = new JLabel();
JLabel label1 = new JLabel();
cell0.setCellValue(10);
CellFormatResult result0 = cf.apply(label0, cell0);
assertEquals("10/01/1900", result0.text);
assertEquals("10/01/1900", label0.getText());
cell1.setCellValue(-1);
CellFormatResult result1 = cf.apply(label1, cell1);
assertEquals("(1)", result1.text);
assertEquals("(1)", label1.getText());
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyCellForDateFormatWithConditions.
@Test
public void testApplyCellForDateFormatWithConditions() throws Exception {
// Create a workbook, row and cell to test with
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
CellFormat cf = CellFormat.getInstance("[<1]hh:mm:ss AM/PM;[>=1]dd/mm/yyyy hh:mm:ss AM/PM;General");
cell.setCellValue(0.5);
assertEquals("12:00:00 PM", cf.apply(cell).text);
cell.setCellValue(1.5);
assertEquals("01/01/1900 12:00:00 PM", cf.apply(cell).text);
cell.setCellValue(-1);
assertEquals(_255_POUND_SIGNS, cf.apply(cell).text);
wb.close();
}
Aggregations