Example usage for org.apache.poi.ss.usermodel Sheet isColumnHidden

List of usage examples for org.apache.poi.ss.usermodel Sheet isColumnHidden

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Sheet isColumnHidden.

Prototype

boolean isColumnHidden(int columnIndex);

Source Link

Document

Get the hidden state for a given column

Usage

From source file:com.cn.led.DrawFromExcel.java

public static void drawExcelToPNG(String excelFilePath, String pngFilePath, int[] fromIndex, int[] toIndex)
        throws Exception {
    // ???//w w w.  j  a va 2 s  .c  o m
    //        int[] fromIndex = {0, 0};
    //        int[] toIndex = {1, 5};

    int imageWidth = 0;
    int imageHeight = 0;

    File file = new File(excelFilePath);
    Workbook wb = WorkbookFactory.create(file);
    Sheet sheet = wb.getSheetAt(0);
    List<CellRangeAddress> rangeAddress = sheet.getMergedRegions(); // ?sheet????

    // ????
    int rowSum = sheet.getPhysicalNumberOfRows();
    int colSum = sheet.getRow(0).getPhysicalNumberOfCells();
    if (fromIndex[0] > rowSum || fromIndex[0] > toIndex[0] || toIndex[0] > rowSum) {
        throw new Exception("the rowIndex of the area is wrong!");
    }
    if (fromIndex[1] > colSum || fromIndex[1] > toIndex[1] || toIndex[1] > colSum) {
        throw new Exception("the colIndex of the area is wrong!");
    }

    // ?Cell???
    int rowSize = toIndex[0] + 1;
    int colSize = toIndex[1] + 1;

    // ?????
    UserCell[][] cells = new UserCell[rowSize][colSize];
    int[] rowPixPos = new int[rowSize + 1];
    rowPixPos[0] = 0;
    int[] colPixPos = new int[colSize + 1];
    colPixPos[0] = 0;
    for (int i = 0; i < rowSize; i++) {

        for (int j = 0; j < colSize; j++) {

            cells[i][j] = new UserCell();
            cells[i][j].setCell(sheet.getRow(i).getCell(j));
            cells[i][j].setRow(i);
            cells[i][j].setCol(j);
            boolean ifShow = (i >= fromIndex[0]) && (j >= fromIndex[1]); //?
            ifShow = ifShow && !(sheet.isColumnHidden(j) || sheet.getRow(i).getZeroHeight()); //????
            cells[i][j].setShow(ifShow);

            // 
            float widthPix = (!ifShow ? 0 : sheet.getColumnWidthInPixels(j)); // ???0
            if (i == fromIndex[0]) {
                imageWidth += widthPix;
            }
            colPixPos[j + 1] = (int) (widthPix + colPixPos[j]);

        }

        // 
        boolean ifShow = (i >= fromIndex[0]); //?
        ifShow = ifShow && !sheet.getRow(i).getZeroHeight(); //????
        float heightPoint = !ifShow ? 0 : sheet.getRow(i).getHeightInPoints(); // ???0
        imageHeight += heightPoint;
        rowPixPos[i + 1] = (int) (heightPoint * 96 / 80) + rowPixPos[i];
    }

    imageHeight = imageHeight * 96 / 80 + 2;

    wb.close();

    List<Grid> grids = new ArrayList<>();
    for (int i = 0; i < rowSize; i++) {
        for (int j = 0; j < colSize; j++) {
            Grid grid = new Grid();
            // ??
            grid.setX(colPixPos[j]);
            grid.setY(rowPixPos[i]);
            grid.setWidth(colPixPos[j + 1] - colPixPos[j]);
            grid.setHeight(rowPixPos[i + 1] - rowPixPos[i]);
            grid.setRow(cells[i][j].getRow());
            grid.setCol(cells[i][j].getCol());
            grid.setShow(cells[i][j].isShow());

            // ???
            int[] isInMergedStatus = isInMerged(grid.getRow(), grid.getCol(), rangeAddress);

            if (isInMergedStatus[0] == 0 && isInMergedStatus[1] == 0) {
                // ???????
                continue;
            } else if (isInMergedStatus[0] != -1 && isInMergedStatus[1] != -1) {
                // ??????                 
                int lastRowPos = isInMergedStatus[0] > rowSize - 1 ? rowSize - 1 : isInMergedStatus[0];
                int lastColPos = isInMergedStatus[1] > colSize - 1 ? colSize - 1 : isInMergedStatus[1];

                grid.setWidth(colPixPos[lastColPos + 1] - colPixPos[j]);
                grid.setHeight(rowPixPos[lastRowPos + 1] - rowPixPos[i]);

            }

            // ?
            CellStyle cs = cells[i][j].getCell().getCellStyle();
            if (cs.getFillPattern() == CellStyle.SOLID_FOREGROUND) {
                grid.setBgColor(cells[i][j].getCell().getCellStyle().getFillForegroundColorColor());
            }

            // 
            String strCell = "";
            switch (cells[i][j].getCell().getCellType()) {
            case HSSFCell.CELL_TYPE_NUMERIC:
                strCell = String.valueOf(cells[i][j].getCell().getNumericCellValue());
                break;
            case HSSFCell.CELL_TYPE_STRING:
                strCell = cells[i][j].getCell().getStringCellValue();
                break;
            case HSSFCell.CELL_TYPE_BOOLEAN:
                strCell = String.valueOf(cells[i][j].getCell().getBooleanCellValue());
                break;
            case HSSFCell.CELL_TYPE_FORMULA:
                try {
                    strCell = String.valueOf(cells[i][j].getCell().getNumericCellValue());
                } catch (IllegalStateException e) {
                    strCell = String.valueOf(cells[i][j].getCell().getRichStringCellValue());
                }
                break;
            default:
                strCell = "";
            }
            //                System.out.println("strCell:" + strCell);

            if (cells[i][j].getCell().getCellStyle().getDataFormatString().contains("0.00%")) {
                try {
                    double dbCell = Double.valueOf(strCell);
                    strCell = new DecimalFormat("#.00").format(dbCell * 100) + "%";
                } catch (NumberFormatException e) {
                }
            }

            grid.setText(strCell.matches("\\w*\\.0") ? strCell.substring(0, strCell.length() - 2) : strCell);

            grids.add(grid);
        }
    }

    BufferedImage image = new BufferedImage(imageWidth, imageHeight + 1, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    // 
    //g2d.setRenderingHint(SunHints.KEY_ANTIALIASING, SunHints.VALUE_ANTIALIAS_OFF);
    //g2d.setRenderingHint(SunHints.KEY_TEXT_ANTIALIASING, SunHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
    //g2d.setRenderingHint(SunHints.KEY_STROKE_CONTROL, SunHints.VALUE_STROKE_DEFAULT);
    //g2d.setRenderingHint(SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST, 140);
    //g2d.setRenderingHint(SunHints.KEY_FRACTIONALMETRICS, SunHints.VALUE_FRACTIONALMETRICS_OFF);
    //g2d.setRenderingHint(SunHints.KEY_RENDERING, SunHints.VALUE_RENDER_DEFAULT);

    g2d.setColor(Color.white);
    g2d.fillRect(0, 0, imageWidth, imageHeight + 1);

    // 
    Iterator<Grid> iterable = grids.iterator();
    while (iterable.hasNext()) {
        Grid g = iterable.next();
        if (!g.isShow()) {
            continue;
        }

        // 
        g2d.setColor(g.getBgColor() == null ? Color.black : g.getBgColor());
        g2d.fillRect(g.getX(), g.getY(), g.getWidth(), g.getHeight());

        // 
        g2d.setColor(Color.red);
        g2d.setStroke(new BasicStroke(1));
        g2d.drawRect(g.getX(), g.getY(), g.getWidth(), g.getHeight());

        // ,
        g2d.setColor(g.getFtColor());

        Font font = g.getFont();
        FontMetrics fm = g2d.getFontMetrics(font);
        int strWidth = fm.stringWidth(g.getText());// ??
        g2d.setFont(font);

        g2d.drawString(g.getText(), g.getX() + (g.getWidth() - strWidth) / 2,
                g.getY() + (g.getHeight() - font.getSize()) / 2 + font.getSize());
    }

    g2d.dispose();
    ImageIO.write(image, "png", new File(pngFilePath));
    //        BMPWriter.write(image, new File(pngFilePath));
    System.out.println("Output to png file Success!");
}

From source file:com.cn.led.DrawFromExcel.java

public static void drawExcelToBMP(String excelFilePath, String bmpFilePath, int[] fromIndex, int[] toIndex)
        throws Exception {
    // ???/*from  w  w w .  java2  s  . c o  m*/
    //        int[] fromIndex = {0, 0};
    //        int[] toIndex = {1, 5};

    int imageWidth = 0;
    int imageHeight = 0;

    Workbook wb = WorkbookFactory.create(new File(excelFilePath));
    Sheet sheet = wb.getSheetAt(0);
    List<CellRangeAddress> rangeAddress = sheet.getMergedRegions(); // ?sheet????

    // ????
    int rowSum = sheet.getPhysicalNumberOfRows();
    int colSum = sheet.getRow(0).getPhysicalNumberOfCells();
    if (fromIndex[0] > rowSum || fromIndex[0] > toIndex[0] || toIndex[0] > rowSum) {
        throw new Exception("the rowIndex of the area is wrong!");
    }
    if (fromIndex[1] > colSum || fromIndex[1] > toIndex[1] || toIndex[1] > colSum) {
        throw new Exception("the colIndex of the area is wrong!");
    }

    // ?Cell???
    int rowSize = toIndex[0] + 1;
    int colSize = toIndex[1] + 1;

    // ?????
    UserCell[][] cells = new UserCell[rowSize][colSize];
    int[] rowPixPos = new int[rowSize + 1];
    rowPixPos[0] = 0;
    int[] colPixPos = new int[colSize + 1];
    colPixPos[0] = 0;
    for (int i = 0; i < rowSize; i++) {

        for (int j = 0; j < colSize; j++) {

            cells[i][j] = new UserCell();
            cells[i][j].setCell(sheet.getRow(i).getCell(j));
            cells[i][j].setRow(i);
            cells[i][j].setCol(j);
            boolean ifShow = (i >= fromIndex[0]) && (j >= fromIndex[1]); //?
            ifShow = ifShow && !(sheet.isColumnHidden(j) || sheet.getRow(i).getZeroHeight()); //????
            cells[i][j].setShow(ifShow);

            // 
            float widthPix = (!ifShow ? 0 : sheet.getColumnWidthInPixels(j)); // ???0
            if (i == fromIndex[0]) {
                imageWidth += widthPix;
            }
            colPixPos[j + 1] = (int) (widthPix + colPixPos[j]);

        }

        // 
        boolean ifShow = (i >= fromIndex[0]); //?
        ifShow = ifShow && !sheet.getRow(i).getZeroHeight(); //????
        float heightPoint = !ifShow ? 0 : sheet.getRow(i).getHeightInPoints(); // ???0
        imageHeight += heightPoint;
        rowPixPos[i + 1] = (int) (heightPoint * 96 / 80) + rowPixPos[i];
    }

    imageHeight = imageHeight * 96 / 80 + 2;
    //        imageWidth = imageWidth;

    wb.close();

    List<Grid> grids = new ArrayList<>();
    for (int i = 0; i < rowSize; i++) {
        for (int j = 0; j < colSize; j++) {
            Grid grid = new Grid();
            // ??
            grid.setX(colPixPos[j]);
            grid.setY(rowPixPos[i]);
            grid.setWidth(colPixPos[j + 1] - colPixPos[j]);
            grid.setHeight(rowPixPos[i + 1] - rowPixPos[i]);
            grid.setRow(cells[i][j].getRow());
            grid.setCol(cells[i][j].getCol());
            grid.setShow(cells[i][j].isShow());

            // ???
            int[] isInMergedStatus = isInMerged(grid.getRow(), grid.getCol(), rangeAddress);

            if (isInMergedStatus[0] == 0 && isInMergedStatus[1] == 0) {
                // ???????
                continue;
            } else if (isInMergedStatus[0] != -1 && isInMergedStatus[1] != -1) {
                // ??????                 
                int lastRowPos = isInMergedStatus[0] > rowSize - 1 ? rowSize - 1 : isInMergedStatus[0];
                int lastColPos = isInMergedStatus[1] > colSize - 1 ? colSize - 1 : isInMergedStatus[1];

                grid.setWidth(colPixPos[lastColPos + 1] - colPixPos[j]);
                grid.setHeight(rowPixPos[lastRowPos + 1] - rowPixPos[i]);

            }

            // ?
            CellStyle cs = cells[i][j].getCell().getCellStyle();
            if (cs.getFillPattern() == CellStyle.SOLID_FOREGROUND) {
                grid.setBgColor(cells[i][j].getCell().getCellStyle().getFillForegroundColorColor());
            }

            // 
            String strCell = "";
            switch (cells[i][j].getCell().getCellType()) {
            case HSSFCell.CELL_TYPE_NUMERIC:
                strCell = String.valueOf(cells[i][j].getCell().getNumericCellValue());
                break;
            case HSSFCell.CELL_TYPE_STRING:
                strCell = cells[i][j].getCell().getStringCellValue();
                break;
            case HSSFCell.CELL_TYPE_BOOLEAN:
                strCell = String.valueOf(cells[i][j].getCell().getBooleanCellValue());
                break;
            case HSSFCell.CELL_TYPE_FORMULA:
                try {
                    strCell = String.valueOf(cells[i][j].getCell().getNumericCellValue());
                } catch (IllegalStateException e) {
                    strCell = String.valueOf(cells[i][j].getCell().getRichStringCellValue());
                }
                break;
            default:
                strCell = "";
            }
            //                System.out.println("strCell:" + strCell);

            if (cells[i][j].getCell().getCellStyle().getDataFormatString().contains("0.00%")) {
                try {
                    double dbCell = Double.valueOf(strCell);
                    strCell = new DecimalFormat("#.00").format(dbCell * 100) + "%";
                } catch (NumberFormatException e) {
                }
            }

            grid.setText(strCell.matches("\\w*\\.0") ? strCell.substring(0, strCell.length() - 2) : strCell);

            grids.add(grid);
        }
    }

    BufferedImage image = new BufferedImage(imageWidth, imageHeight + 1, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    // 
    //g2d.setRenderingHint(SunHints.KEY_ANTIALIASING, SunHints.VALUE_ANTIALIAS_OFF);
    //g2d.setRenderingHint(SunHints.KEY_TEXT_ANTIALIASING, SunHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
    //g2d.setRenderingHint(SunHints.KEY_STROKE_CONTROL, SunHints.VALUE_STROKE_DEFAULT);
    //g2d.setRenderingHint(SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST, 140);
    //g2d.setRenderingHint(SunHints.KEY_FRACTIONALMETRICS, SunHints.VALUE_FRACTIONALMETRICS_OFF);
    //g2d.setRenderingHint(SunHints.KEY_RENDERING, SunHints.VALUE_RENDER_DEFAULT);

    g2d.setColor(Color.white);
    g2d.fillRect(0, 0, imageWidth, imageHeight + 1);

    // 
    Iterator<Grid> iterable = grids.iterator();
    while (iterable.hasNext()) {
        Grid g = iterable.next();
        if (!g.isShow()) {
            continue;
        }

        // 
        g2d.setColor(g.getBgColor() == null ? Color.black : g.getBgColor());
        g2d.fillRect(g.getX(), g.getY(), g.getWidth(), g.getHeight());

        // 
        g2d.setColor(Color.red);
        g2d.setStroke(new BasicStroke(1));
        g2d.drawRect(g.getX(), g.getY(), g.getWidth(), g.getHeight());

        // ,
        g2d.setColor(g.getFtColor());

        Font font = g.getFont();
        FontMetrics fm = g2d.getFontMetrics(font);
        int strWidth = fm.stringWidth(g.getText());// ??
        g2d.setFont(font);

        g2d.drawString(g.getText(), g.getX() + (g.getWidth() - strWidth) / 2,
                g.getY() + (g.getHeight() - font.getSize()) / 2 + font.getSize());
    }

    g2d.dispose();
    BMPWriter.write(image, new File(bmpFilePath));
    System.out.println("Output to png file Success!");
}

From source file:com.vaadin.addon.spreadsheet.action.HideHeaderAction.java

License:Open Source License

@Override
public boolean isApplicableForHeader(Spreadsheet spreadhseet, CellRangeAddress headerRange) {
    Sheet activeSheet = spreadhseet.getActiveSheet();
    if (!isSheetProtected(activeSheet)) {
        if (headerRange.isFullColumnRange()) {
            int index = headerRange.getFirstColumn();
            if (!activeSheet.isColumnHidden(index)) {
                setCaption("Hide column " + (getColumnHeader(index + 1)));
            }/*from  ww w  .  java  2s . c  o  m*/
            return true;
        } else if (headerRange.isFullRowRange()) {
            int index = headerRange.getFirstRow();
            if (!spreadhseet.isRowHidden(index)) {
                setCaption("Hide row " + (index + 1));
            }
            return true;
        }
    }
    return false;
}

From source file:com.vaadin.addon.spreadsheet.action.UnHideHeadersAction.java

License:Open Source License

@Override
public boolean isApplicableForHeader(Spreadsheet spreadsheet, CellRangeAddress headerRange) {
    Sheet activeSheet = spreadsheet.getActiveSheet();
    if (!isSheetProtected(activeSheet)) {
        if (headerRange.isFullColumnRange()) {
            int index = headerRange.getFirstColumn();
            if (!activeSheet.isColumnHidden(index)) {
                if (index > 0 && activeSheet.isColumnHidden(index - 1)) {
                    setCaption("Unhide column " + getColumnHeader(index));
                    unhideHeaderIndex = index - 1;
                    return true;
                } else if (activeSheet.isColumnHidden(index + 1)) {
                    setCaption("Unhide column " + getColumnHeader(index + 2));
                    unhideHeaderIndex = index + 1;
                    return true;
                }/*from   w w w .  j  a v  a  2 s. co m*/
            } else {
                setCaption("Unhide column " + getColumnHeader(index + 1));
                unhideHeaderIndex = index;
                return true;
            }
        } else if (headerRange.isFullRowRange()) {
            int index = headerRange.getFirstRow();
            if (!spreadsheet.isRowHidden(index)) {
                if (index > 0 && spreadsheet.isRowHidden(index - 1)) {
                    setCaption("Unhide row " + (index));
                    unhideHeaderIndex = index - 1;
                    return true;
                } else if (spreadsheet.isRowHidden(index + 1)) {
                    setCaption("Unhide row " + (index + 2));
                    unhideHeaderIndex = index + 1;
                    return true;
                }
            } else {
                setCaption("Unhide row " + (index + 1));
                unhideHeaderIndex = index;
                return true;
            }
        }
    }
    return false;
}

From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java

License:Open Source License

private void loadCellComments(int r1, int c1, int r2, int c2) {
    Sheet sheet = getActiveSheet();
    for (int r = r1 - 1; r < r2; r++) {
        Row row = sheet.getRow(r);/*w  ww .j a v a 2  s .c o m*/
        if (row != null && row.getZeroHeight()) {
            continue;
        }
        for (int c = c1 - 1; c < c2; c++) {
            if (sheet.isColumnHidden(c)) {
                continue;
            }

            int c_one_based = c + 1;
            int row_one_based = r + 1;

            MergedRegion region = mergedRegionContainer.getMergedRegion(c_one_based, row_one_based);
            // do not add comments that are "below" merged regions.
            // client side handles cases where comment "moves" (because
            // shifting etc.) from merged cell into basic or vice versa.
            if (region == null || region.col1 == c_one_based && region.row1 == row_one_based) {
                Comment comment = sheet.getCellComment(r, c);
                String key = SpreadsheetUtil.toKey(c_one_based, row_one_based);
                if (comment != null) {
                    // by default comments are shown when mouse is over the
                    // red
                    // triangle on the cell's top right corner. the comment
                    // position is calculated so that it is completely
                    // visible.
                    getState().cellComments.put(key, comment.getString().getString());
                    getState().cellCommentAuthors.put(key, comment.getAuthor());
                    if (comment.isVisible()) {
                        getState().visibleCellComments.add(key);
                    }
                }
                if (isMarkedAsInvalidFormula(c_one_based, row_one_based)) {
                    getState().invalidFormulaCells.add(key);
                }

            } else {
                c = region.col2 - 1;
            }
        }
    }
}

From source file:com.vaadin.addon.spreadsheet.SpreadsheetFactory.java

License:Open Source License

/**
 * Calculate size-related values for the sheet. Includes row and column
 * counts, actual row heights and column widths, and hidden row and column
 * indexes.// ww w .j  av a2  s  . co  m
 * 
 * @param spreadsheet
 * @param sheet
 */
static void calculateSheetSizes(final Spreadsheet spreadsheet, final Sheet sheet) {
    // Always have at least the default amount of rows
    int rows = sheet.getLastRowNum() + 1;
    if (rows < spreadsheet.getDefaultRowCount()) {
        rows = spreadsheet.getDefaultRowCount();
    }
    spreadsheet.getState().rows = rows;

    final float[] rowHeights = new float[rows];
    int cols = 0;
    int tempRowIndex = -1;
    final ArrayList<Integer> hiddenRowIndexes = new ArrayList<Integer>();
    for (Row row : sheet) {
        int rIndex = row.getRowNum();
        // set the empty rows to have the default row width
        while (++tempRowIndex != rIndex) {
            rowHeights[tempRowIndex] = spreadsheet.getState().defRowH;
        }
        if (row.getZeroHeight()) {
            rowHeights[rIndex] = 0.0F;
            hiddenRowIndexes.add(rIndex + 1);
        } else {
            rowHeights[rIndex] = row.getHeightInPoints();
        }
        int c = row.getLastCellNum();
        if (c > cols) {
            cols = c;
        }
    }
    if (rows > sheet.getLastRowNum() + 1) {
        float defaultRowHeightInPoints = sheet.getDefaultRowHeightInPoints();

        int lastRowNum = sheet.getLastRowNum();
        // if sheet is empty, also set height for 'last row' (index
        // zero)
        if (lastRowNum == 0) {
            rowHeights[0] = defaultRowHeightInPoints;
        }

        // set default height for the rest
        for (int i = lastRowNum + 1; i < rows; i++) {
            rowHeights[i] = defaultRowHeightInPoints;
        }
    }
    spreadsheet.getState().hiddenRowIndexes = hiddenRowIndexes;
    spreadsheet.getState().rowH = rowHeights;

    // Always have at least the default amount of columns
    if (cols < spreadsheet.getDefaultColumnCount()) {
        cols = spreadsheet.getDefaultColumnCount();
    }
    spreadsheet.getState().cols = cols;

    final int[] colWidths = new int[cols];
    final ArrayList<Integer> hiddenColumnIndexes = new ArrayList<Integer>();
    for (int i = 0; i < cols; i++) {
        if (sheet.isColumnHidden(i)) {
            colWidths[i] = 0;
            hiddenColumnIndexes.add(i + 1);
        } else {
            colWidths[i] = ExcelToHtmlUtils.getColumnWidthInPx(sheet.getColumnWidth(i));
        }
    }
    spreadsheet.getState().hiddenColumnIndexes = hiddenColumnIndexes;
    spreadsheet.getState().colW = colWidths;
}

From source file:org.tiefaces.components.websheet.service.WebSheetLoader.java

License:MIT License

/**
 * Load header row without configuration tab.
 *
 * @param rangeBuildRef/*  w  w  w .ja  va2  s.c o  m*/
 *            the range build ref
 * @param rendered
 *            the rendered
 * @return the list
 */
private List<HeaderCell> loadHeaderRowWithoutConfigurationTab(final RangeBuildRef rangeBuildRef,
        final boolean rendered) {

    int firstCol = rangeBuildRef.getLeft();
    int lastCol = rangeBuildRef.getRight();
    double totalWidth = (double) rangeBuildRef.getTotalWidth();
    Sheet sheet1 = rangeBuildRef.getSheet();
    List<HeaderCell> headercells = new ArrayList<>();
    for (int i = firstCol; i <= lastCol; i++) {
        if (!sheet1.isColumnHidden(i)) {
            String style = getHeaderColumnStyle(parent.getWb(), null, sheet1.getColumnWidth(i), totalWidth);
            headercells.add(new HeaderCell("1", "1", style, style, WebSheetUtility.getExcelColumnName(i),
                    rendered, true));
        }
    }
    fillToMaxColumns(headercells);
    return headercells;

}

From source file:org.tiefaces.components.websheet.service.WebSheetLoader.java

License:MIT License

/**
 * Load header row with configuration tab.
 *
 * @param sheetConfig// w  w  w.j  av a2s  . c  o  m
 *            the sheet config
 * @param rangeBuildRef
 *            the range build ref
 * @param currentRow
 *            the current row
 * @param cellRangeMap
 *            the cell range map
 * @param skippedRegionCells
 *            the skipped region cells
 * @return the list
 */
private List<HeaderCell> loadHeaderRowWithConfigurationTab(final SheetConfiguration sheetConfig,
        final RangeBuildRef rangeBuildRef, final int currentRow,
        final Map<String, CellRangeAddress> cellRangeMap, final List<String> skippedRegionCells) {

    Sheet sheet1 = rangeBuildRef.getSheet();
    int left = rangeBuildRef.getLeft();
    int right = rangeBuildRef.getRight();
    double totalWidth = (double) rangeBuildRef.getTotalWidth();
    Row row = sheet1.getRow(currentRow);
    List<HeaderCell> headercells = new ArrayList<>();
    for (int cindex = left; cindex <= right; cindex++) {
        String cellindex = CellUtility.getCellIndexNumberKey(cindex, currentRow);

        if (!skippedRegionCells.contains(cellindex) && !sheet1.isColumnHidden(cindex)) {
            Cell cell = null;
            if (row != null) {
                cell = row.getCell(cindex, MissingCellPolicy.CREATE_NULL_AS_BLANK);
            }
            int originRowIndex = ConfigurationUtility.getOriginalRowNumInHiddenColumn(row);
            if (cell != null) {
                FacesCell fcell = new FacesCell();

                CellUtility.convertCell(sheetConfig, fcell, cell, cellRangeMap, originRowIndex,
                        parent.getCellAttributesMap(), null);
                parent.getPicHelper().setupFacesCellPictureCharts(sheet1, fcell, cell,
                        WebSheetUtility.getFullCellRefName(sheet1, cell));
                CellStyleUtility.setupCellStyle(parent.getWb(), fcell, cell, row.getHeightInPoints());
                fcell.setColumnStyle(fcell.getColumnStyle()
                        + getColumnWidthStyle(sheet1, cellRangeMap, cellindex, cindex, totalWidth));
                fcell.setColumnIndex(cindex);

                headercells.add(new HeaderCell(Integer.toString(fcell.getRowspan()),
                        Integer.toString(fcell.getColspan()), fcell.getStyle(), fcell.getColumnStyle(),
                        CellUtility.getCellValueWithFormat(cell, parent.getFormulaEvaluator(),
                                parent.getDataFormatter()),
                        true, true));
            }
        }

    }
    fillToMaxColumns(headercells);
    return headercells;
}

From source file:org.tiefaces.components.websheet.service.WebSheetLoader.java

License:MIT License

/**
 * Assemble faces body row./*from ww w.  j  a v  a  2 s  . c o m*/
 *
 * @param rowIndex
 *            the row index
 * @param sheet1
 *            the sheet 1
 * @param left
 *            the left
 * @param right
 *            the right
 * @param sheetConfig
 *            the sheet config
 * @param cellRangeMap
 *            the cell range map
 * @param skippedRegionCells
 *            the skipped region cells
 * @return the faces row
 */
private FacesRow assembleFacesBodyRow(final int rowIndex, final Sheet sheet1, final int left, final int right,
        final SheetConfiguration sheetConfig, final Map<String, CellRangeAddress> cellRangeMap,
        final List<String> skippedRegionCells) {

    FacesRow facesRow = new FacesRow(rowIndex);
    Row row = sheet1.getRow(rowIndex);
    setupRowInfo(facesRow, sheet1, row, rowIndex, CommandUtility.isRowAllowAdd(row, sheetConfig));
    String saveAttrList = SaveAttrsUtility.getSaveAttrListFromRow(row);
    List<FacesCell> bodycells = new ArrayList<>();
    for (int cindex = left; cindex <= right; cindex++) {
        String cellindex = CellUtility.getCellIndexNumberKey(cindex, rowIndex);
        if (!skippedRegionCells.contains(cellindex) && !sheet1.isColumnHidden(cindex)) {
            Cell cell = null;
            if (row != null) {
                cell = row.getCell(cindex, MissingCellPolicy.CREATE_NULL_AS_BLANK);
            }
            if (cell != null) {
                FacesCell fcell = new FacesCell();

                CellUtility.convertCell(sheetConfig, fcell, cell, cellRangeMap, facesRow.getOriginRowIndex(),
                        parent.getCellAttributesMap(), saveAttrList);
                parent.getPicHelper().setupFacesCellPictureCharts(sheet1, fcell, cell,
                        WebSheetUtility.getFullCellRefName(sheet1, cell));
                CellStyleUtility.setupCellStyle(parent.getWb(), fcell, cell, row.getHeightInPoints());
                fcell.setColumnIndex(cindex);
                bodycells.add(fcell);
                addCache(cell);
            } else {
                bodycells.add(null);
            }
        } else {
            bodycells.add(null);
        }
    }
    facesRow.setCells(bodycells);
    return facesRow;
}