Search in sources :

Example 56 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class RegionUtil method setTopBorderColor.

/**
     * Sets the top border color for a region of cells by manipulating the cell style of the individual
     * cells on the top
     * 
     * @param color The color of the border
     * @param region The region that should have the border
     * @param sheet The sheet that the region is on.
     * @since POI 3.15 beta 2
     */
public static void setTopBorderColor(int color, CellRangeAddress region, Sheet sheet) {
    int colStart = region.getFirstColumn();
    int colEnd = region.getLastColumn();
    int rowIndex = region.getFirstRow();
    CellPropertySetter cps = new CellPropertySetter(CellUtil.TOP_BORDER_COLOR, color);
    Row row = CellUtil.getRow(rowIndex, sheet);
    for (int i = colStart; i <= colEnd; i++) {
        cps.setProperty(row, i);
    }
}
Also used : Row(org.apache.poi.ss.usermodel.Row)

Example 57 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class RegionUtil method setBottomBorderColor.

/**
     * Sets the bottom border color for a region of cells by manipulating the cell style of the individual
     * cells on the bottom
     * 
     * @param color The color of the border
     * @param region The region that should have the border
     * @param sheet The sheet that the region is on.
     * @since POI 3.15 beta 2
     */
public static void setBottomBorderColor(int color, CellRangeAddress region, Sheet sheet) {
    int colStart = region.getFirstColumn();
    int colEnd = region.getLastColumn();
    int rowIndex = region.getLastRow();
    CellPropertySetter cps = new CellPropertySetter(CellUtil.BOTTOM_BORDER_COLOR, color);
    Row row = CellUtil.getRow(rowIndex, sheet);
    for (int i = colStart; i <= colEnd; i++) {
        cps.setProperty(row, i);
    }
}
Also used : Row(org.apache.poi.ss.usermodel.Row)

Example 58 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class RegionUtil method setBorderBottom.

/**
     * Sets the bottom border style for a region of cells by manipulating the cell style of the individual
     * cells on the bottom
     * 
     * @param border The new border
     * @param region The region that should have the border
     * @param sheet The sheet that the region is on.
     * @since POI 3.15 beta 2
     * @deprecated POI 3.16 beta 1. Use {@link #setBorderBottom(BorderStyle, CellRangeAddress, Sheet)}.
     */
@Removal(version = "3.18")
public static void setBorderBottom(int border, CellRangeAddress region, Sheet sheet) {
    int colStart = region.getFirstColumn();
    int colEnd = region.getLastColumn();
    int rowIndex = region.getLastRow();
    CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_BOTTOM, border);
    Row row = CellUtil.getRow(rowIndex, sheet);
    for (int i = colStart; i <= colEnd; i++) {
        cps.setProperty(row, i);
    }
}
Also used : Row(org.apache.poi.ss.usermodel.Row) Removal(org.apache.poi.util.Removal)

Example 59 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class RegionUtil method setBorderTop.

/**
     * Sets the top border style for a region of cells by manipulating the cell style of the individual
     * cells on the top
     * 
     * @param border The new border
     * @param region The region that should have the border
     * @param sheet The sheet that the region is on.
     * @since POI 3.16 beta 1
     */
public static void setBorderTop(BorderStyle border, CellRangeAddress region, Sheet sheet) {
    int colStart = region.getFirstColumn();
    int colEnd = region.getLastColumn();
    int rowIndex = region.getFirstRow();
    CellPropertySetter cps = new CellPropertySetter(CellUtil.BORDER_TOP, border);
    Row row = CellUtil.getRow(rowIndex, sheet);
    for (int i = colStart; i <= colEnd; i++) {
        cps.setProperty(row, i);
    }
}
Also used : Row(org.apache.poi.ss.usermodel.Row)

Example 60 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class SheetBuilder method build.

/**
     * Builds sheet from parent workbook and 2D array with cell
     * values. Creates rows anyway (even if row contains only null
     * cells), creates cells if either corresponding array value is not
     * null or createEmptyCells property is true.
     * The conversion is performed in the following way:
     * <p/>
     * <ul>
     * <li>Numbers become numeric cells.</li>
     * <li><code>java.util.Date</code> or <code>java.util.Calendar</code>
     * instances become date cells.</li>
     * <li>String with leading '=' char become formulas (leading '='
     * will be truncated).</li>
     * <li>Other objects become strings via <code>Object.toString()</code>
     * method call.</li>
     * </ul>
     *
     * @return newly created sheet
     */
public Sheet build() {
    Sheet sheet = (sheetName == null) ? workbook.createSheet() : workbook.createSheet(sheetName);
    Row currentRow = null;
    Cell currentCell = null;
    for (int rowIndex = 0; rowIndex < cells.length; ++rowIndex) {
        Object[] rowArray = cells[rowIndex];
        currentRow = sheet.createRow(rowIndex);
        for (int cellIndex = 0; cellIndex < rowArray.length; ++cellIndex) {
            Object cellValue = rowArray[cellIndex];
            if (cellValue != null || shouldCreateEmptyCells) {
                currentCell = currentRow.createCell(cellIndex);
                setCellValue(currentCell, cellValue);
            }
        }
    }
    return sheet;
}
Also used : Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

Row (org.apache.poi.ss.usermodel.Row)316 Cell (org.apache.poi.ss.usermodel.Cell)230 Sheet (org.apache.poi.ss.usermodel.Sheet)179 Workbook (org.apache.poi.ss.usermodel.Workbook)125 Test (org.junit.Test)116 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)55 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)44 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)35 CellStyle (org.apache.poi.ss.usermodel.CellStyle)27 CellReference (org.apache.poi.ss.util.CellReference)22 ArrayList (java.util.ArrayList)21 FileOutputStream (java.io.FileOutputStream)20 IOException (java.io.IOException)17 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)17 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)17 HashMap (java.util.HashMap)16 RichTextString (org.apache.poi.ss.usermodel.RichTextString)16 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)16 List (java.util.List)14 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)14