Example usage for org.apache.poi.hssf.usermodel HSSFSheet isColumnHidden

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet isColumnHidden

Introduction

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

Prototype

@Override
public boolean isColumnHidden(int columnIndex) 

Source Link

Document

Get the hidden state for a given column.

Usage

From source file:com.eryansky.core.excelTools.ExcelUtils.java

License:Apache License

public static void copySheetStyle(HSSFWorkbook destwb, HSSFSheet dest, HSSFWorkbook srcwb, HSSFSheet src) {
    if (src == null || dest == null)
        return;//  w w  w  .  jav  a2 s .c o  m

    dest.setAlternativeExpression(src.getAlternateExpression());
    dest.setAlternativeFormula(src.getAlternateFormula());
    dest.setAutobreaks(src.getAutobreaks());
    dest.setDialog(src.getDialog());
    if (src.getColumnBreaks() != null) {
        for (int col : src.getColumnBreaks()) {
            dest.setColumnBreak(col);
        }
    }
    dest.setDefaultColumnWidth(src.getDefaultColumnWidth());
    dest.setDefaultRowHeight(src.getDefaultRowHeight());
    dest.setDefaultRowHeightInPoints(src.getDefaultRowHeightInPoints());
    dest.setDisplayGuts(src.getDisplayGuts());
    dest.setFitToPage(src.getFitToPage());
    dest.setHorizontallyCenter(src.getHorizontallyCenter());
    dest.setDisplayFormulas(src.isDisplayFormulas());
    dest.setDisplayGridlines(src.isDisplayGridlines());
    dest.setDisplayRowColHeadings(src.isDisplayRowColHeadings());
    dest.setGridsPrinted(src.isGridsPrinted());
    dest.setPrintGridlines(src.isPrintGridlines());

    for (int i = 0; i < src.getNumMergedRegions(); i++) {
        CellRangeAddress r = src.getMergedRegion(i);
        dest.addMergedRegion(r);
    }

    if (src.getRowBreaks() != null) {
        for (int row : src.getRowBreaks()) {
            dest.setRowBreak(row);
        }
    }
    dest.setRowSumsBelow(src.getRowSumsBelow());
    dest.setRowSumsRight(src.getRowSumsRight());

    int maxcol = 0;
    for (int i = 0; i <= src.getLastRowNum(); i++) {
        HSSFRow row = src.getRow(i);
        if (row != null) {
            if (maxcol < row.getLastCellNum())
                maxcol = row.getLastCellNum();
        }
    }
    for (int col = 0; col <= maxcol; col++) {
        if (src.getColumnWidth(col) != src.getDefaultColumnWidth())
            dest.setColumnWidth(col, src.getColumnWidth(col));
        dest.setColumnHidden(col, src.isColumnHidden(col));
    }
}

From source file:com.report.excel.ExcelToHtmlConverter.java

License:Apache License

protected void processColumnHeaders(HSSFSheet sheet, int maxSheetColumns, Element table) {
    Element tableHeader = htmlDocumentFacade.createTableHeader();
    table.appendChild(tableHeader);/*from w w  w .  j ava 2 s .co  m*/

    Element tr = htmlDocumentFacade.createTableRow();

    if (isOutputRowNumbers()) {
        // empty row at left-top corner
        tr.appendChild(htmlDocumentFacade.createTableHeaderCell());
    }

    for (int c = 0; c < maxSheetColumns; c++) {
        if (!isOutputHiddenColumns() && sheet.isColumnHidden(c))
            continue;

        Element th = htmlDocumentFacade.createTableHeaderCell();
        String text = getColumnName(c);
        th.appendChild(htmlDocumentFacade.createText(text));
        tr.appendChild(th);
    }
    tableHeader.appendChild(tr);
}

From source file:com.report.excel.ExcelToHtmlConverter.java

License:Apache License

/**
 * Creates COLGROUP element with width specified for all columns. (Except
 * first if <tt>{@link #isOutputRowNumbers()}==true</tt>)
 *//*from   www .  java2 s .  c om*/
protected void processColumnWidths(HSSFSheet sheet, int maxSheetColumns, Element table) {
    // draw COLS after we know max column number
    Element columnGroup = htmlDocumentFacade.createTableColumnGroup();
    if (isOutputRowNumbers()) {
        columnGroup.appendChild(htmlDocumentFacade.createTableColumn());
    }
    for (int c = 0; c < maxSheetColumns; c++) {
        if (!isOutputHiddenColumns() && sheet.isColumnHidden(c))
            continue;

        Element col = htmlDocumentFacade.createTableColumn();
        col.setAttribute("width", String.valueOf(getColumnWidth(sheet, c)));
        columnGroup.appendChild(col);
    }
    table.appendChild(columnGroup);
}

From source file:com.report.excel.ExcelToHtmlConverter.java

License:Apache License

/**
 * @return maximum 1-base index of column that were rendered, zero if none
 *//* ww  w. j  a  v a2s .co  m*/
protected int processRow(CellRangeAddress[][] mergedRanges, HSSFRow row, Element tableRowElement) {
    final HSSFSheet sheet = row.getSheet();
    final short maxColIx = row.getLastCellNum();
    if (maxColIx <= 0)
        return 0;

    final List<Element> emptyCells = new ArrayList<Element>(maxColIx);

    if (isOutputRowNumbers()) {
        Element tableRowNumberCellElement = htmlDocumentFacade.createTableHeaderCell();
        //processRowNumber( row, tableRowNumberCellElement );
        emptyCells.add(tableRowNumberCellElement);
    }

    int maxRenderedColumn = 0;
    for (int colIx = 0; colIx < maxColIx; colIx++) {
        if (!isOutputHiddenColumns() && sheet.isColumnHidden(colIx))
            continue;

        CellRangeAddress range = ExcelToHtmlUtils.getMergedRange(mergedRanges, row.getRowNum(), colIx);

        if (range != null && (range.getFirstColumn() != colIx || range.getFirstRow() != row.getRowNum()))
            continue;

        HSSFCell cell = row.getCell(colIx);

        int divWidthPx = 0;
        if (isUseDivsToSpan()) {
            divWidthPx = getColumnWidth(sheet, colIx);

            boolean hasBreaks = false;
            for (int nextColumnIndex = colIx + 1; nextColumnIndex < maxColIx; nextColumnIndex++) {
                if (!isOutputHiddenColumns() && sheet.isColumnHidden(nextColumnIndex))
                    continue;

                if (row.getCell(nextColumnIndex) != null && !isTextEmpty(row.getCell(nextColumnIndex))) {
                    hasBreaks = true;
                    break;
                }

                divWidthPx += getColumnWidth(sheet, nextColumnIndex);
            }

            if (!hasBreaks)
                divWidthPx = Integer.MAX_VALUE;
        }

        Element tableCellElement = htmlDocumentFacade.createTableCell();

        if (range != null) {
            if (range.getFirstColumn() != range.getLastColumn())
                tableCellElement.setAttribute("colspan",
                        String.valueOf(range.getLastColumn() - range.getFirstColumn() + 1));
            if (range.getFirstRow() != range.getLastRow())
                tableCellElement.setAttribute("rowspan",
                        String.valueOf(range.getLastRow() - range.getFirstRow() + 1));
        }

        boolean emptyCell;
        if (cell != null) {
            emptyCell = processCell(cell, tableCellElement, getColumnWidth(sheet, colIx), divWidthPx,
                    row.getHeight() / 20f);
        } else {
            emptyCell = true;
        }

        if (emptyCell) {
            emptyCells.add(tableCellElement);
        } else {
            for (Element emptyCellElement : emptyCells) {
                tableRowElement.appendChild(emptyCellElement);
            }
            emptyCells.clear();

            tableRowElement.appendChild(tableCellElement);
            maxRenderedColumn = colIx;
        }
    }

    return maxRenderedColumn + 1;
}

From source file:com.wangzhu.poi.ExcelToHtmlConverter.java

License:Apache License

protected void processColumnHeaders(HSSFSheet sheet, int maxSheetColumns, Element table) {
    Element tableHeader = this.htmlDocumentFacade.createTableHeader();
    table.appendChild(tableHeader);//from   ww w  .  j  a v a  2s . c o m

    Element tr = this.htmlDocumentFacade.createTableRow();

    if (this.isOutputRowNumbers()) {
        // empty row at left-top corner
        tr.appendChild(this.htmlDocumentFacade.createTableHeaderCell());
    }

    for (int c = 0; c < maxSheetColumns; c++) {
        if (!this.isOutputHiddenColumns() && sheet.isColumnHidden(c)) {
            continue;
        }

        Element th = this.htmlDocumentFacade.createTableHeaderCell();
        String text = this.getColumnName(c);
        th.appendChild(this.htmlDocumentFacade.createText(text));
        tr.appendChild(th);
    }
    tableHeader.appendChild(tr);
}

From source file:com.wangzhu.poi.ExcelToHtmlConverter.java

License:Apache License

/**
 * Creates COLGROUP element with width specified for all columns. (Except
 * first if <tt>{@link #isOutputRowNumbers()}==true</tt>)
 *///from w w w.jav  a  2 s  .  c om
protected void processColumnWidths(HSSFSheet sheet, int maxSheetColumns, Element table) {
    // draw COLS after we know max column number
    Element columnGroup = this.htmlDocumentFacade.createTableColumnGroup();
    if (this.isOutputRowNumbers()) {
        columnGroup.appendChild(this.htmlDocumentFacade.createTableColumn());
    }
    for (int c = 0; c < maxSheetColumns; c++) {
        if (!this.isOutputHiddenColumns() && sheet.isColumnHidden(c)) {
            continue;
        }

        Element col = this.htmlDocumentFacade.createTableColumn();
        col.setAttribute("width", String.valueOf(AbstractExcelConverter.getColumnWidth(sheet, c)));
        columnGroup.appendChild(col);
    }
    table.appendChild(columnGroup);
}

From source file:com.wangzhu.poi.ExcelToHtmlConverter.java

License:Apache License

/**
 * @return maximum 1-base index of column that were rendered, zero if none
 *///w  ww  . ja va 2s  .c  o m
protected int processRow(CellRangeAddress[][] mergedRanges, HSSFRow row, Element tableRowElement) {
    final HSSFSheet sheet = row.getSheet();
    final short maxColIx = row.getLastCellNum();
    if (maxColIx <= 0) {
        return 0;
    }

    final List emptyCells = new ArrayList(maxColIx);

    if (this.isOutputRowNumbers()) {
        Element tableRowNumberCellElement = this.htmlDocumentFacade.createTableHeaderCell();
        this.processRowNumber(row, tableRowNumberCellElement);
        emptyCells.add(tableRowNumberCellElement);
    }

    int maxRenderedColumn = 0;
    for (int colIx = 0; colIx < maxColIx; colIx++) {
        if (!this.isOutputHiddenColumns() && sheet.isColumnHidden(colIx)) {
            continue;
        }

        CellRangeAddress range = AbstractExcelUtils.getMergedRange(mergedRanges, row.getRowNum(), colIx);

        if ((range != null)
                && ((range.getFirstColumn() != colIx) || (range.getFirstRow() != row.getRowNum()))) {
            continue;
        }

        HSSFCell cell = row.getCell(colIx);

        int divWidthPx = 0;
        if (this.isUseDivsToSpan()) {
            divWidthPx = AbstractExcelConverter.getColumnWidth(sheet, colIx);

            boolean hasBreaks = false;
            for (int nextColumnIndex = colIx + 1; nextColumnIndex < maxColIx; nextColumnIndex++) {
                if (!this.isOutputHiddenColumns() && sheet.isColumnHidden(nextColumnIndex)) {
                    continue;
                }

                if ((row.getCell(nextColumnIndex) != null) && !this.isTextEmpty(row.getCell(nextColumnIndex))) {
                    hasBreaks = true;
                    break;
                }

                divWidthPx += AbstractExcelConverter.getColumnWidth(sheet, nextColumnIndex);
            }

            if (!hasBreaks) {
                divWidthPx = Integer.MAX_VALUE;
            }
        }

        Element tableCellElement = this.htmlDocumentFacade.createTableCell();

        if (range != null) {
            if (range.getFirstColumn() != range.getLastColumn()) {
                tableCellElement.setAttribute("colspan",
                        String.valueOf((range.getLastColumn() - range.getFirstColumn()) + 1));
            }
            if (range.getFirstRow() != range.getLastRow()) {
                tableCellElement.setAttribute("rowspan",
                        String.valueOf((range.getLastRow() - range.getFirstRow()) + 1));
            }
        }

        boolean emptyCell;
        if (cell != null) {
            emptyCell = this.processCell(cell, tableCellElement,
                    AbstractExcelConverter.getColumnWidth(sheet, colIx), divWidthPx, row.getHeight() / 20f);
        } else {
            emptyCell = true;
        }

        if (emptyCell) {
            emptyCells.add(tableCellElement);
        } else {
            for (Iterator iterator = emptyCells.iterator(); iterator.hasNext();) {
                Element emptyCellElement = (Element) iterator.next();
                tableRowElement.appendChild(emptyCellElement);
            }
            emptyCells.clear();

            tableRowElement.appendChild(tableCellElement);
            maxRenderedColumn = colIx;
        }
    }

    return maxRenderedColumn + 1;
}