Search in sources :

Example 61 with CellRangeAddress

use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.

the class BaseTestConditionalFormatting method testBug55380.

@Test
public void testBug55380() throws IOException {
    Workbook wb = _testDataProvider.createWorkbook();
    Sheet sheet = wb.createSheet();
    CellRangeAddress[] ranges = new CellRangeAddress[] { CellRangeAddress.valueOf("C9:D30"), CellRangeAddress.valueOf("C7:C31") };
    ConditionalFormattingRule rule = sheet.getSheetConditionalFormatting().createConditionalFormattingRule("$A$1>0");
    sheet.getSheetConditionalFormatting().addConditionalFormatting(ranges, rule);
    wb.close();
}
Also used : CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) HSSFConditionalFormattingRule(org.apache.poi.hssf.usermodel.HSSFConditionalFormattingRule) Test(org.junit.Test)

Example 62 with CellRangeAddress

use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.

the class TestCellWalk method testNotTraverseEmptyCells.

public void testNotTraverseEmptyCells() {
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = new SheetBuilder(wb, testData).build();
    CellRangeAddress range = CellRangeAddress.valueOf("A1:C3");
    CellWalk cellWalk = new CellWalk(sheet, range);
    countCellHandler.reset();
    cellWalk.traverse(countCellHandler);
    assertEquals(4, countCellHandler.getVisitedCellsNumber());
    /* 1 + 2 + 5 + 9 */
    assertEquals(17L, countCellHandler.getOrdinalNumberSum());
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 63 with CellRangeAddress

use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.

the class TestCellRange method testValueOf.

public void testValueOf() {
    CellRangeAddress cr1 = CellRangeAddress.valueOf("A1:B1");
    assertEquals(0, cr1.getFirstColumn());
    assertEquals(0, cr1.getFirstRow());
    assertEquals(1, cr1.getLastColumn());
    assertEquals(0, cr1.getLastRow());
    CellRangeAddress cr2 = CellRangeAddress.valueOf("B1");
    assertEquals(1, cr2.getFirstColumn());
    assertEquals(0, cr2.getFirstRow());
    assertEquals(1, cr2.getLastColumn());
    assertEquals(0, cr2.getLastRow());
}
Also used : CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 64 with CellRangeAddress

use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.

the class TestBugs method test53564.

// As of POI 3.15 beta 2, LibreOffice does not display the diagonal border while it does display the bottom border
// I have not checked Excel to know if this is a LibreOffice or a POI problem.
@Test
public void test53564() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Page 1");
    final short BLUE = 30;
    HSSFSheetConditionalFormatting scf = sheet.getSheetConditionalFormatting();
    HSSFConditionalFormattingRule rule = scf.createConditionalFormattingRule(ComparisonOperator.GT, "10");
    HSSFBorderFormatting bord = rule.createBorderFormatting();
    bord.setBorderDiagonal(BorderStyle.THICK);
    assertEquals(BorderStyle.THICK, bord.getBorderDiagonalEnum());
    bord.setBackwardDiagonalOn(true);
    assertTrue(bord.isBackwardDiagonalOn());
    bord.setForwardDiagonalOn(true);
    assertTrue(bord.isForwardDiagonalOn());
    bord.setDiagonalBorderColor(BLUE);
    assertEquals(BLUE, bord.getDiagonalBorderColor());
    // Create the bottom border style so we know what a border is supposed to look like
    bord.setBorderBottom(BorderStyle.THICK);
    assertEquals(BorderStyle.THICK, bord.getBorderBottomEnum());
    bord.setBottomBorderColor(BLUE);
    assertEquals(BLUE, bord.getBottomBorderColor());
    CellRangeAddress[] A2_D4 = { new CellRangeAddress(1, 3, 0, 3) };
    scf.addConditionalFormatting(A2_D4, rule);
    // Set a cell value within the conditional formatting range whose rule would resolve to True.
    Cell C3 = sheet.createRow(2).createCell(2);
    C3.setCellValue(30.0);
    // Manually check the output file with Excel to see if the diagonal border is present
    //OutputStream fos = new FileOutputStream("/tmp/53564.xls");
    //wb.write(fos);
    //fos.close();
    wb.close();
}
Also used : CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Cell(org.apache.poi.ss.usermodel.Cell) Test(org.junit.Test)

Example 65 with CellRangeAddress

use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.

the class TestWorkbook method testRepeatingColsRowsMinusOne.

/**
     * Test setRepeatingRowsAndColumns when startRow and startColumn are -1.
     */
@Test
public void testRepeatingColsRowsMinusOne() throws IOException {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Test Print Titles");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell(1);
    cell.setCellValue(new HSSFRichTextString("hi"));
    CellRangeAddress cra = new CellRangeAddress(-1, 1, -1, 1);
    try {
        sheet.setRepeatingColumns(cra);
        fail("invalid start index is ignored");
    } catch (IllegalArgumentException e) {
    }
    try {
        sheet.setRepeatingRows(cra);
        fail("invalid start index is ignored");
    } catch (IllegalArgumentException e) {
    }
    sheet.setRepeatingColumns(null);
    sheet.setRepeatingRows(null);
    HSSFTestDataSamples.writeOutAndReadBack(workbook).close();
    workbook.close();
}
Also used : CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Test(org.junit.Test)

Aggregations

CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)247 Test (org.junit.Test)74 Row (org.apache.poi.ss.usermodel.Row)53 Cell (org.apache.poi.ss.usermodel.Cell)50 Sheet (org.apache.poi.ss.usermodel.Sheet)30 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)27 ArrayList (java.util.ArrayList)26 Workbook (org.apache.poi.ss.usermodel.Workbook)24 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)19 FileOutputStream (java.io.FileOutputStream)18 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)17 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)17 HSSFConditionalFormattingRule (org.apache.poi.hssf.usermodel.HSSFConditionalFormattingRule)16 ConditionalFormattingRule (org.apache.poi.ss.usermodel.ConditionalFormattingRule)16 SheetConditionalFormatting (org.apache.poi.ss.usermodel.SheetConditionalFormatting)15 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)15 CellReference (org.apache.poi.ss.util.CellReference)14 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)13 HSSFConditionalFormatting (org.apache.poi.hssf.usermodel.HSSFConditionalFormatting)12 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)11