Search in sources :

Example 91 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.

the class TestFormulaParser method testRanges.

@Test
public void testRanges() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    wb.createSheet("Cash_Flow");
    HSSFSheet sheet = wb.createSheet("Test");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell(0);
    String formula;
    cell.setCellFormula("A1.A2");
    formula = cell.getCellFormula();
    assertEquals("A1:A2", formula);
    cell.setCellFormula("A1..A2");
    formula = cell.getCellFormula();
    assertEquals("A1:A2", formula);
    cell.setCellFormula("A1...A2");
    formula = cell.getCellFormula();
    assertEquals("A1:A2", formula);
    wb.close();
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 92 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.

the class TestFormulaParser method testBackSlashInNames.

/** Named ranges with backslashes, e.g. 'POI\\2009' */
@Test
public void testBackSlashInNames() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFName name = wb.createName();
    name.setNameName("POI\\2009");
    name.setRefersToFormula("Sheet1!$A$1");
    HSSFSheet sheet = wb.createSheet();
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell_C1 = row.createCell(2);
    cell_C1.setCellFormula("POI\\2009");
    assertEquals("POI\\2009", cell_C1.getCellFormula());
    HSSFCell cell_D1 = row.createCell(2);
    cell_D1.setCellFormula("NOT(POI\\2009=\"3.5-final\")");
    assertEquals("NOT(POI\\2009=\"3.5-final\")", cell_D1.getCellFormula());
    wb.close();
}
Also used : TestHSSFName(org.apache.poi.hssf.usermodel.TestHSSFName) HSSFName(org.apache.poi.hssf.usermodel.HSSFName) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 93 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.

the class TestFormulaParser method testWorksheetReferences.

@Test
public void testWorksheetReferences() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    wb.createSheet("NoQuotesNeeded");
    wb.createSheet("Quotes Needed Here &#$@");
    HSSFSheet sheet = wb.createSheet("Test");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell;
    cell = row.createCell(0);
    cell.setCellFormula("NoQuotesNeeded!A1");
    cell = row.createCell(1);
    cell.setCellFormula("'Quotes Needed Here &#$@'!A1");
    wb.close();
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 94 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.

the class TestSheet method testSetMargins_bug45717.

/**
	 * In 3.1, setting margins between creating first row and first cell caused an exception.
	 */
@Test
public void testSetMargins_bug45717() throws Exception {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Vorschauliste");
    HSSFRow row = sheet.createRow(0);
    sheet.setMargin(HSSFSheet.LeftMargin, 0.3);
    try {
        row.createCell(0);
    } catch (IllegalStateException e) {
        if (e.getMessage().equals("Cannot create value records before row records exist")) {
            fail("Identified bug 45717");
        }
        throw e;
    } finally {
        workbook.close();
    }
}
Also used : HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 95 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.

the class TestRangeEval method testRangeUsingOffsetFunc_bug46948.

public void testRangeUsingOffsetFunc_bug46948() {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFRow row = wb.createSheet("Sheet1").createRow(0);
    HSSFCell cellA1 = row.createCell(0);
    HSSFCell cellB1 = row.createCell(1);
    // C1
    row.createCell(2).setCellValue(5.0);
    // D1
    row.createCell(3).setCellValue(7.0);
    // E1
    row.createCell(4).setCellValue(9.0);
    cellA1.setCellFormula("SUM(C1:OFFSET(C1,0,B1))");
    // range will be C1:D1
    cellB1.setCellValue(1.0);
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv;
    try {
        cv = fe.evaluate(cellA1);
    } catch (IllegalArgumentException e) {
        if (e.getMessage().equals("Unexpected ref arg class (org.apache.poi.ss.formula.LazyAreaEval)")) {
            throw new AssertionFailedError("Identified bug 46948");
        }
        throw e;
    }
    assertEquals(12.0, cv.getNumberValue(), 0.0);
    // range will be C1:E1
    cellB1.setCellValue(2.0);
    fe.notifyUpdateCell(cellB1);
    cv = fe.evaluate(cellA1);
    assertEquals(21.0, cv.getNumberValue(), 0.0);
    // range will be C1:C1
    cellB1.setCellValue(0.0);
    fe.notifyUpdateCell(cellB1);
    cv = fe.evaluate(cellA1);
    assertEquals(5.0, cv.getNumberValue(), 0.0);
}
Also used : HSSFFormulaEvaluator(org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) CellValue(org.apache.poi.ss.usermodel.CellValue) AssertionFailedError(junit.framework.AssertionFailedError) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)124 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)98 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)82 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)71 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)29 FileOutputStream (java.io.FileOutputStream)24 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)24 Test (org.junit.Test)18 IOException (java.io.IOException)16 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)15 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)14 File (java.io.File)13 ArrayList (java.util.ArrayList)12 CellValue (org.apache.poi.ss.usermodel.CellValue)10 OutputStream (java.io.OutputStream)8 HashMap (java.util.HashMap)8 Map (java.util.Map)7 AssertionFailedError (junit.framework.AssertionFailedError)7 FileInputStream (java.io.FileInputStream)6 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)6