Package org.apache.poi.ss.usermodel

Examples of org.apache.poi.ss.usermodel.Workbook


        assertEquals(wb.getAllPictures().size(), 1);
    }

    @Test
    public void bug46250(){
        Workbook wb = openSample("46250.xls");
        Sheet sh = wb.getSheet("Template");
        Sheet cSh = wb.cloneSheet(wb.getSheetIndex(sh));

        HSSFPatriarch patriarch = (HSSFPatriarch) cSh.createDrawingPatriarch();
        HSSFTextbox tb = (HSSFTextbox) patriarch.getChildren().get(2);

        tb.setString(new HSSFRichTextString("POI test"));
View Full Code Here


        wb = writeOutAndReadBack((HSSFWorkbook) wb);
    }

    @Test
    public void bug53404(){
        Workbook wb = openSample("53404.xls");
        Sheet sheet = wb.getSheet("test-sheet");
        int rowCount = sheet.getLastRowNum() + 1;
        int newRows = 5;
        for (int r = rowCount; r < rowCount + newRows; r++) {
            Row row = sheet.createRow((short) r);
            row.createCell(0).setCellValue(1.03 * (r + 7));
View Full Code Here

        }
    }

    @Test
    public void stackoverflow23114397() throws Exception {
        Workbook wb = new HSSFWorkbook();
        DataFormat format = wb.getCreationHelper().createDataFormat();
       
        // How close the sizing should be, given that not all
        //  systems will have quite the same fonts on them
        float fontAccuracy = 0.22f;
       
        // x%
        CellStyle iPercent = wb.createCellStyle();
        iPercent.setDataFormat(format.getFormat("0%"));
        // x.x%
        CellStyle d1Percent = wb.createCellStyle();
        d1Percent.setDataFormat(format.getFormat("0.0%"));
        // x.xx%
        CellStyle d2Percent = wb.createCellStyle();
        d2Percent.setDataFormat(format.getFormat("0.00%"));
       
        Sheet s = wb.createSheet();
        Row r1 = s.createRow(0);
       
        for (int i=0; i<3; i++) {
            r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(0);
        }
View Full Code Here

     * Used to fail with
     * java.lang.RuntimeException: Unexpected eval class (org.apache.poi.ss.formula.eval.NameXEval)
     */
    @Test
    public void bug56737() throws IOException {
        Workbook wb = openSample("56737.xls");
       
        // Check the named range definitions
        Name nSheetScope = wb.getName("NR_To_A1");
        Name nWBScope = wb.getName("NR_Global_B2");

        assertNotNull(nSheetScope);
        assertNotNull(nWBScope);
       
        assertEquals("Defines!$A$1", nSheetScope.getRefersToFormula());
        assertEquals("Defines!$B$2", nWBScope.getRefersToFormula());
       
        // Check the different kinds of formulas
        Sheet s = wb.getSheetAt(0);
        Cell cRefSName = s.getRow(1).getCell(3);
        Cell cRefWName = s.getRow(2).getCell(3);
       
        assertEquals("Defines!NR_To_A1", cRefSName.getCellFormula());
       
        // TODO Correct this, so that the filename is shown too, see bug #56742
        // This is what Excel itself shows
        //assertEquals("'56737.xls'!NR_Global_B2", cRefWName.getCellFormula());
        // TODO This isn't right, but it's what we currently generate....
        assertEquals("NR_Global_B2", cRefWName.getCellFormula());
       
        // Try to evaluate them
        FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
        assertEquals("Test A1", eval.evaluate(cRefSName).getStringValue());
        assertEquals(142, (int)eval.evaluate(cRefWName).getNumberValue());
       
        // Try to evaluate everything
        eval.evaluateAll();
View Full Code Here

    /**
     * Intersection formula ranges, eg =(C2:D3 D3:E4)
     */
    @Test
    public void bug52111() throws Exception {
        Workbook wb = openSample("Intersection-52111.xls");
        Sheet s = wb.getSheetAt(0);

        // Check we can read it correctly
        Cell intF = s.getRow(2).getCell(0);
        assertEquals(Cell.CELL_TYPE_FORMULA, intF.getCellType());
        assertEquals(Cell.CELL_TYPE_NUMERIC, intF.getCachedFormulaResultType());
       
        assertEquals("(C2:D3 D3:E4)", intF.getCellFormula());
       
        // Check we can evaluate it correctly
        FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
        assertEquals("4.0", eval.evaluate(intF).formatAsString());
    }
View Full Code Here

        assertEquals("4.0", eval.evaluate(intF).formatAsString());
    }

    @Test
    public void bug42016() {
        Workbook wb = openSample("42016.xls");
        Sheet s = wb.getSheetAt(0);
        for(int row = 0;row < 7;row++) {
            assertEquals("A$1+B$1", s.getRow(row).getCell(2).getCellFormula());
        }       
    }
View Full Code Here

    /**
     * Unexpected record type (org.apache.poi.hssf.record.ColumnInfoRecord)
     */
    @Test
    public void bug53984() {
        Workbook wb = openSample("53984.xls");
        Sheet s = wb.getSheetAt(0);
        assertEquals("International Communication Services SA", s.getRow(2).getCell(0).getStringCellValue());
        assertEquals("Saudi Arabia-Riyadh", s.getRow(210).getCell(0).getStringCellValue());
    }
View Full Code Here

        testRead("WithConditionalFormatting.xls");
    }

    public void test53691() throws IOException {
        SheetConditionalFormatting cf;
        final Workbook wb;
        wb = HSSFITestDataProvider.instance.openSampleWorkbook("53691.xls");
        /*
        FileInputStream s = new FileInputStream("C:\\temp\\53691bbadfixed.xls");
        try {
            wb = new HSSFWorkbook(s);
        } finally {
            s.close();
        }

        wb.removeSheetAt(1);*/
       
        // initially it is good
        writeTemp53691(wb, "agood");
       
        // clone sheet corrupts it
        Sheet sheet = wb.cloneSheet(0);
        writeTemp53691(wb, "bbad");

        // removing the sheet makes it good again
        wb.removeSheetAt(wb.getSheetIndex(sheet));
        writeTemp53691(wb, "cgood");
       
        // cloning again and removing the conditional formatting makes it good again
        sheet = wb.cloneSheet(0);
        removeConditionalFormatting(sheet);       
        writeTemp53691(wb, "dgood");
       
        // cloning the conditional formatting manually makes it bad again
        cf = sheet.getSheetConditionalFormatting();
        SheetConditionalFormatting scf = wb.getSheetAt(0).getSheetConditionalFormatting();
        for (int j = 0; j < scf.getNumConditionalFormattings(); j++) {
            cf.addConditionalFormatting(scf.getConditionalFormattingAt(j));
        }       
        writeTemp53691(wb, "ebad");

        // remove all conditional formatting for comparing BIFF output
        removeConditionalFormatting(sheet);       
        removeConditionalFormatting(wb.getSheetAt(0));       
        writeTemp53691(wb, "fgood");
    }
View Full Code Here

    }

    private void writeTemp53691(Workbook wb, String suffix) throws FileNotFoundException,
            IOException {
        // assert that we can write/read it in memory
        Workbook wbBack = HSSFITestDataProvider.instance.writeOutAndReadBack(wb);
        assertNotNull(wbBack);
       
        /* Just necessary for local testing... */
        /*OutputStream out = new FileOutputStream("C:\\temp\\53691" + suffix + ".xls");
        try {
View Full Code Here

     * A specific sequence of strings can result in broken CDATA section in sharedStrings.xml file.
     *
     * @author Philippe Laflamme
     */
    public void testBug48936() throws IOException {
        Workbook w = new XSSFWorkbook();
        Sheet s = w.createSheet();
        int i = 0;
        List<String> lst = readStrings("48936-strings.txt");
        for (String str : lst) {
            s.createRow(i++).createCell(0).setCellValue(str);
        }

        try {
            w = XSSFTestDataSamples.writeOutAndReadBack(w);
        } catch (POIXMLException e){
            fail("Detected Bug #48936");       
        }
        s = w.getSheetAt(0);
        i = 0;
        for (String str : lst) {
            String val = s.getRow(i++).getCell(0).getStringCellValue();
            assertEquals(str, val);
        }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.usermodel.Workbook

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.