Examples of SXSSFWorkbook


Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

    }

    public synchronized boolean cleanup(){
        boolean ok = true;
        for(int i = 0; i < instances.size(); i++){
            SXSSFWorkbook wb = instances.get(i);
            ok = ok && wb.dispose();
            instances.remove(i);
        }
        return ok;
    }
View Full Code Here

Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

        if ("HSSF".equals(type))
            return new HSSFWorkbook();
        else if ("XSSF".equals(type))
            return new XSSFWorkbook();
        else if ("SXSSF".equals(type))
            return new SXSSFWorkbook();
        else
            usage("Unknown type \"" + type + "\"");
        return null;
    }
View Full Code Here

Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

    @Ignore("Shifting rows is not yet implemented in SXSSFSheet")
    @Test
    public void testBug53798XLSXStream() throws IOException {
        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("53798_shiftNegative_TMPL.xlsx");
        File xlsOutput = TempFile.createTempFile("testBug53798", ".xlsx");
        bug53798Work(new SXSSFWorkbook(wb), xlsOutput);
    }
View Full Code Here

Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

                if(wb instanceof XSSFWorkbook) {
                    newWB = new XSSFWorkbook(is);
                } else if(wb instanceof HSSFWorkbook) {
                    newWB = new HSSFWorkbook(is);
                } else if(wb instanceof SXSSFWorkbook) {
                    newWB = new SXSSFWorkbook(new XSSFWorkbook(is));
                } else {
                    throw new IllegalStateException("Unknown workbook: " + wb);
                }
                assertNotNull(newWB.getSheet("test"));
            } finally {
View Full Code Here

Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

            assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow());
        }

        // for XSSF also test with SXSSF
        if(isXSSF) {
            Workbook swb = new SXSSFWorkbook((XSSFWorkbook) wb);
            for (int si = 0; si < swb.getNumberOfSheets(); si++) {
                Sheet sh = swb.getSheetAt(si);
                assertNotNull(sh.getSheetName());
                assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow());
            }
        }
    }
View Full Code Here

Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

            headers.add(cell.getStringCellValue());
        }

        // save the worksheet as-is using SXSSF
        File outputFile = TempFile.createTempFile("poi-56274", ".xlsx");
        SXSSFWorkbook outputWorkbook = new org.apache.poi.xssf.streaming.SXSSFWorkbook(inputWorkbook);
        outputWorkbook.write(new FileOutputStream(outputFile));

        // re-read the saved file and make sure headers in the xml are in the original order
        inputWorkbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook(new FileInputStream(outputFile));
        CTTable ctTable = inputWorkbook.getSheetAt(0).getTables().get(0).getCTTable();
        CTTableColumn[] ctTableColumnArray = ctTable.getTableColumns().getTableColumnArray();
View Full Code Here

Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

            assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol());
        }

        // for XSSF also test with SXSSF
        if(isXSSF) {
            Workbook swb = new SXSSFWorkbook((XSSFWorkbook) wb);
            for (int si = 0; si < swb.getNumberOfSheets(); si++) {
                Sheet sh = swb.getSheetAt(si);
                assertNotNull(sh.getSheetName());
                assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol());
            }
        }
    }
View Full Code Here

Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

        checkRowCount(wb);
    }

    @Test
    public void showInPaneManyRowsBug55248SXSSF() {
        SXSSFWorkbook workbook = new SXSSFWorkbook(new XSSFWorkbook());
        SXSSFSheet sheet = (SXSSFSheet) workbook.createSheet("Sheet 1");

        sheet.showInPane(0, 0);

        for(int i = ROW_COUNT/2;i < ROW_COUNT;i++) {
            sheet.createRow(i);
View Full Code Here

Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

        if (tableModel == null) throw new IllegalArgumentException("Invalid tabla data model!");
        int columnCount = tableModel.getColumnCount();
        int rowCount = tableModel.getRowCount() + 1; //Include header row
        int row = 0;

        SXSSFWorkbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
        Map<String, CellStyle> styles = createStyles(wb);
        Sheet sh = wb.createSheet("Sheet 1");

        // General setup
        sh.setDisplayGridlines(true);
        sh.setPrintGridlines(false);
        sh.setFitToPage(true);
        sh.setHorizontallyCenter(true);
        PrintSetup printSetup = sh.getPrintSetup();
        printSetup.setLandscape(true);

        // Create header
        Row header = sh.createRow(row++);
        header.setHeightInPoints(20f);
        for (int i = 0; i < columnCount; i++) {
            Cell cell = header.createCell(i);
            cell.setCellStyle(styles.get("header"));
            cell.setCellValue(tableModel.getColumnName(i));
        }

        // Create data rows
        for(; row < rowCount; row++){
            Row _row = sh.createRow(row);
            for(int cellnum = 0; cellnum < columnCount; cellnum++){
                Cell cell = _row.createCell(cellnum);
                Object value = tableModel.getValueAt(row-1, cellnum);
                if (value instanceof Short || value instanceof Long || value instanceof Integer || value instanceof BigInteger) {
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellStyle(styles.get("integer_number_cell"));
                    if (value!= null) cell.setCellValue( ((Number)value).doubleValue());
                } else if (value instanceof Float || value instanceof Double || value instanceof BigDecimal) {
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellStyle(styles.get("decimal_number_cell"));
                    if (value!= null) cell.setCellValue( ((Number)value).doubleValue());
                } else if (value instanceof Date) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    cell.setCellStyle(styles.get("date_cell"));
                    if (value!= null) cell.setCellValue( (Date)value );
                } else if (value instanceof Interval) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    cell.setCellStyle(styles.get("text_cell"));
                    if (value!= null) cell.setCellValue( ((Interval)value).getDescription(LocaleManager.currentLocale()) );
                } else {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    cell.setCellStyle(styles.get("text_cell"));
                    if (value!= null) cell.setCellValue( value.toString() );
                }
            }

        }

        // Adjust column size
        for (int i = 0; i < columnCount; i++) {
            sh.autoSizeColumn(i);
        }

        // Put border around table data
        CellRangeAddress range = new CellRangeAddress(0, rowCount-1, 0, columnCount-1);
        RegionUtil.setBorderRight(BorderFormatting.BORDER_THIN, range, sh, wb);
        RegionUtil.setRightBorderColor(IndexedColors.BLACK.getIndex(), range, sh, wb);
        RegionUtil.setBorderLeft(BorderFormatting.BORDER_THIN, range, sh, wb);
        RegionUtil.setLeftBorderColor(IndexedColors.BLACK.getIndex(), range, sh, wb);
        RegionUtil.setBorderTop(BorderFormatting.BORDER_THIN, range, sh, wb);
        RegionUtil.setTopBorderColor(IndexedColors.BLACK.getIndex(), range, sh, wb);
        RegionUtil.setBorderBottom(BorderFormatting.BORDER_THIN, range, sh, wb);
        RegionUtil.setBottomBorderColor(IndexedColors.BLACK.getIndex(), range, sh, wb);

        ByteArrayInputStream bis = null;
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            wb.write(bos);
            bis = new ByteArrayInputStream(bos.toByteArray());
            bos.close();
        } catch (IOException e) {
            log.error("Data export error: ", e);
        }

        // Dispose of temporary files backing this workbook on disk
        if (!wb.dispose()) log.warn("Could not dispose of temporary file associated to data export!");

        return bis;
    }
View Full Code Here

Examples of org.apache.poi.xssf.streaming.SXSSFWorkbook

        if (tableModel == null) throw new IllegalArgumentException("Invalid tabla data model!");
        int columnCount = tableModel.getColumnCount();
        int rowCount = tableModel.getRowCount() + 1; //Include header row
        int row = 0;

        SXSSFWorkbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
        Map<String, CellStyle> styles = createStyles(wb);
        Sheet sh = wb.createSheet("Sheet 1");

        // General setup
        sh.setDisplayGridlines(true);
        sh.setPrintGridlines(false);
        sh.setFitToPage(true);
        sh.setHorizontallyCenter(true);
        PrintSetup printSetup = sh.getPrintSetup();
        printSetup.setLandscape(true);

        // Create header
        Row header = sh.createRow(row++);
        header.setHeightInPoints(20f);
        for (int i = 0; i < columnCount; i++) {
            Cell cell = header.createCell(i);
            cell.setCellStyle(styles.get("header"));
            cell.setCellValue(tableModel.getColumnName(i));
        }

        // Create data rows
        for (; row < rowCount; row++) {
            Row _row = sh.createRow(row);
            for (int cellnum = 0; cellnum < columnCount; cellnum++) {
                Cell cell = _row.createCell(cellnum);
                Object value = tableModel.getValueAt(row - 1, cellnum);
                if (value instanceof Short || value instanceof Long || value instanceof Integer || value instanceof BigInteger) {
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellStyle(styles.get("integer_number_cell"));
                    cell.setCellValue(((Number) value).doubleValue());
                } else if (value instanceof Float || value instanceof Double || value instanceof BigDecimal) {
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellStyle(styles.get("decimal_number_cell"));
                    cell.setCellValue(((Number) value).doubleValue());
                } else if (value instanceof Date) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    cell.setCellStyle(styles.get("date_cell"));
                    cell.setCellValue((Date) value);
                } else if (value instanceof Interval) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    cell.setCellStyle(styles.get("text_cell"));
                    cell.setCellValue(((Interval) value).getDescription(LocaleManager.currentLocale()));
                } else {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    cell.setCellStyle(styles.get("text_cell"));
                    cell.setCellValue(value.toString());
                }
            }
        }

        // Adjust column size
        for (int i = 0; i < columnCount; i++) {
            sh.autoSizeColumn(i);
        }

        // Put border around table data
        CellRangeAddress range = new CellRangeAddress(0, rowCount-1, 0, columnCount-1);
        RegionUtil.setBorderRight(BorderFormatting.BORDER_THIN, range, sh, wb);
        RegionUtil.setRightBorderColor(IndexedColors.BLACK.getIndex(), range, sh, wb);
        RegionUtil.setBorderLeft(BorderFormatting.BORDER_THIN, range, sh, wb);
        RegionUtil.setLeftBorderColor(IndexedColors.BLACK.getIndex(), range, sh, wb);
        RegionUtil.setBorderTop(BorderFormatting.BORDER_THIN, range, sh, wb);
        RegionUtil.setTopBorderColor(IndexedColors.BLACK.getIndex(), range, sh, wb);
        RegionUtil.setBorderBottom(BorderFormatting.BORDER_THIN, range, sh, wb);
        RegionUtil.setBottomBorderColor(IndexedColors.BLACK.getIndex(), range, sh, wb);

        ByteArrayInputStream bis = null;
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            wb.write(bos);
            bis = new ByteArrayInputStream(bos.toByteArray());
            bos.close();
        } catch (IOException e) {
            log.error("Data export error: ", e);
        }

        // Dispose of temporary files backing this workbook on disk
        if (!wb.dispose()) log.warn("Could not dispose of temporary file associated to data export!");

        return bis;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.