Search in sources :

Example 91 with Row

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();
}
Also used : JLabel(javax.swing.JLabel) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 92 with Row

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);
}
Also used : Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 93 with Row

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();
}
Also used : JLabel(javax.swing.JLabel) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 94 with Row

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();
}
Also used : JLabel(javax.swing.JLabel) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 95 with Row

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();
}
Also used : Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

Row (org.apache.poi.ss.usermodel.Row)316 Cell (org.apache.poi.ss.usermodel.Cell)230 Sheet (org.apache.poi.ss.usermodel.Sheet)179 Workbook (org.apache.poi.ss.usermodel.Workbook)125 Test (org.junit.Test)116 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)55 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)44 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)35 CellStyle (org.apache.poi.ss.usermodel.CellStyle)27 CellReference (org.apache.poi.ss.util.CellReference)22 ArrayList (java.util.ArrayList)21 FileOutputStream (java.io.FileOutputStream)20 IOException (java.io.IOException)17 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)17 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)17 HashMap (java.util.HashMap)16 RichTextString (org.apache.poi.ss.usermodel.RichTextString)16 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)16 List (java.util.List)14 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)14