Search in sources :

Example 11 with HSSFRow

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

the class TestFormulaParser method testExponentialInSheet.

@Test
public void testExponentialInSheet() 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("1.3E21/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "1.3E+21/3", formula);
    cell.setCellFormula("-1.3E21/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "-1.3E+21/3", formula);
    cell.setCellFormula("1322E21/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "1.322E+24/3", formula);
    cell.setCellFormula("-1322E21/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "-1.322E+24/3", formula);
    cell.setCellFormula("1.3E1/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "13/3", formula);
    cell.setCellFormula("-1.3E1/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "-13/3", formula);
    cell.setCellFormula("1.3E-4/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "0.00013/3", formula);
    cell.setCellFormula("-1.3E-4/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "-0.00013/3", formula);
    cell.setCellFormula("13E-15/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "0.000000000000013/3", formula);
    cell.setCellFormula("-13E-15/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "-0.000000000000013/3", formula);
    cell.setCellFormula("1.3E3/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "1300/3", formula);
    cell.setCellFormula("-1.3E3/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "-1300/3", formula);
    cell.setCellFormula("1300000000000000/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "1300000000000000/3", formula);
    cell.setCellFormula("-1300000000000000/3");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "-1300000000000000/3", formula);
    cell.setCellFormula("-10E-1/3.1E2*4E3/3E4");
    formula = cell.getCellFormula();
    assertEquals("Exponential formula string", "-1/310*4000/30000", 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 12 with HSSFRow

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

the class TestFormulaParser method testMultiSheetReference.

@Test
public void testMultiSheetReference() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    wb.createSheet("Cash_Flow");
    wb.createSheet("Test Sheet");
    HSSFSheet sheet = wb.createSheet("Test");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell(0);
    String formula;
    // References to a single cell:
    // One sheet
    cell.setCellFormula("Cash_Flow!A1");
    formula = cell.getCellFormula();
    assertEquals("Cash_Flow!A1", formula);
    // Then the other
    cell.setCellFormula("\'Test Sheet\'!A1");
    formula = cell.getCellFormula();
    assertEquals("\'Test Sheet\'!A1", formula);
    // Now both
    cell.setCellFormula("Cash_Flow:\'Test Sheet\'!A1");
    formula = cell.getCellFormula();
    assertEquals("Cash_Flow:\'Test Sheet\'!A1", formula);
    // References to a range (area) of cells:
    // One sheet
    cell.setCellFormula("Cash_Flow!A1:B2");
    formula = cell.getCellFormula();
    assertEquals("Cash_Flow!A1:B2", formula);
    // Then the other
    cell.setCellFormula("\'Test Sheet\'!A1:B2");
    formula = cell.getCellFormula();
    assertEquals("\'Test Sheet\'!A1:B2", formula);
    // Now both
    cell.setCellFormula("Cash_Flow:\'Test Sheet\'!A1:B2");
    formula = cell.getCellFormula();
    assertEquals("Cash_Flow:\'Test Sheet\'!A1:B2", 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 13 with HSSFRow

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

the class TestRVA method data.

@Parameters(name = "{1}")
public static Collection<Object[]> data() throws Exception {
    poifs = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("testRVA.xls"), true);
    workbook = new HSSFWorkbook(poifs);
    sheet = workbook.getSheetAt(0);
    List<Object[]> data = new ArrayList<Object[]>();
    for (int rowIdx = 0; true; rowIdx++) {
        HSSFRow row = sheet.getRow(rowIdx);
        if (row == null) {
            break;
        }
        HSSFCell cell = row.getCell(0);
        if (cell == null || cell.getCellTypeEnum() == CellType.BLANK) {
            break;
        }
        String formula = cell.getCellFormula();
        data.add(new Object[] { cell, formula });
    }
    return data;
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) ArrayList(java.util.ArrayList) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Parameters(org.junit.runners.Parameterized.Parameters)

Example 14 with HSSFRow

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

the class TestSheet method testMisplacedMergedCellsRecords_bug45699.

@Test
public void testMisplacedMergedCellsRecords_bug45699() throws Exception {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls");
    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFRow row = sheet.getRow(3);
    HSSFCell cell = row.getCell(4);
    if (cell == null) {
        fail("Identified bug 45699");
    }
    assertEquals("Informations", cell.getRichStringCellValue().getString());
    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 15 with HSSFRow

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

the class CellTypes method main.

public static void main(String[] args) throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    try {
        HSSFSheet sheet = wb.createSheet("new sheet");
        HSSFRow row = sheet.createRow(2);
        row.createCell(0).setCellValue(1.1);
        row.createCell(1).setCellValue(new Date());
        row.createCell(2).setCellValue("a string");
        row.createCell(3).setCellValue(true);
        row.createCell(4).setCellType(CellType.ERROR);
        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
        wb.write(fileOut);
        fileOut.close();
    } finally {
        wb.close();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Date(java.util.Date)

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