Example usage for org.apache.poi.ss.usermodel Row setHeight

List of usage examples for org.apache.poi.ss.usermodel Row setHeight

Introduction

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

Prototype

void setHeight(short height);

Source Link

Document

Set the row's height or set to ff (-1) for undefined/default-height.

Usage

From source file:com.qihang.winter.poi.excel.export.base.ExcelExportBase.java

License:Apache License

/**
 * List??Cells/*  w  ww  .  j a va 2  s.  c om*/
 * 
 * @param styles
 */
public void createListCells(Drawing patriarch, int index, int cellNum, Object obj,
        List<com.qihang.winter.poi.excel.entity.params.ExcelExportEntity> excelParams, Sheet sheet,
        Workbook workbook) throws Exception {
    com.qihang.winter.poi.excel.entity.params.ExcelExportEntity entity;
    Row row;
    if (sheet.getRow(index) == null) {
        row = sheet.createRow(index);
        row.setHeight(getRowHeight(excelParams));
    } else {
        row = sheet.getRow(index);
    }
    for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
        entity = excelParams.get(k);
        Object value = getCellValue(entity, obj);
        if (entity.getType() == 1) {
            createStringCell(row, cellNum++, value == null ? "" : value.toString(),
                    row.getRowNum() % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity);
        } else {
            createImageCell(patriarch, entity, row, cellNum++, value == null ? "" : value.toString(), obj);
        }
    }
}

From source file:com.qihang.winter.poi.excel.export.template.ExcelExportOfTemplateUtil.java

License:Apache License

/**
 * foreach?//from w ww. j a va  2  s .c  o  m
 * @param cell 
 * @param map
 * @param oldString
 * @throws Exception 
 */
private void addListDataToExcel(Cell cell, Map<String, Object> map, String name) throws Exception {
    boolean isCreate = !name.contains(PoiElUtil.FOREACH_NOT_CREATE);
    boolean isShift = name.contains(PoiElUtil.FOREACH_AND_SHIFT);
    name = name.replace(PoiElUtil.FOREACH_NOT_CREATE, PoiElUtil.EMPTY)
            .replace(PoiElUtil.FOREACH_AND_SHIFT, PoiElUtil.EMPTY).replace(PoiElUtil.FOREACH, PoiElUtil.EMPTY)
            .replace(PoiElUtil.START_STR, PoiElUtil.EMPTY);
    String[] keys = name.replaceAll("\\s{1,}", " ").trim().split(" ");
    Collection<?> datas = (Collection<?>) com.qihang.winter.poi.util.PoiPublicUtil.getParamsValue(keys[0], map);
    List<com.qihang.winter.poi.excel.entity.params.ExcelTemplateParams> columns = getAllDataColumns(cell,
            name.replace(keys[0], PoiElUtil.EMPTY));
    if (datas == null) {
        return;
    }
    Iterator<?> its = datas.iterator();
    Row row;
    int rowIndex = cell.getRow().getRowNum() + 1;
    //??
    if (its.hasNext()) {
        Object t = its.next();
        cell.getRow().setHeight(columns.get(0).getHeight());
        setForEeachCellValue(isCreate, cell.getRow(), cell.getColumnIndex(), t, columns, map);
    }
    if (isShift) {
        cell.getRow().getSheet().shiftRows(cell.getRowIndex() + 1, cell.getRow().getSheet().getLastRowNum(),
                datas.size() - 1, true, true);
    }
    while (its.hasNext()) {
        Object t = its.next();
        if (isCreate) {
            row = cell.getRow().getSheet().createRow(rowIndex++);
        } else {
            row = cell.getRow().getSheet().getRow(rowIndex++);
            if (row == null) {
                row = cell.getRow().getSheet().createRow(rowIndex - 1);
            }
        }
        row.setHeight(columns.get(0).getHeight());
        setForEeachCellValue(isCreate, row, cell.getColumnIndex(), t, columns, map);
    }
}

From source file:com.respam.comniq.models.POIexcelExporter.java

License:Open Source License

public void excelWriter(JSONObject parsedObj, int rownum) throws IOException {
    String path = System.getProperty("user.home") + File.separator + "comniq" + File.separator + "output";
    File file = new File(path + File.separator + "POImovieInfo.xlsx");

    String thumbnailPath = System.getProperty("user.home") + File.separator + "comniq" + File.separator
            + "output" + File.separator + "thumbnails";
    File posterFile = new File(thumbnailPath + File.separator + parsedObj.get("Title") + ".jpg");

    if (!file.exists()) {
        createFile();//from   w ww.  j ava2  s.  c o m
    }

    if (file.exists() && checked.equals(false)) {
        findLastRow();
    }

    try {
        FileInputStream fis = new FileInputStream(file);
        XSSFWorkbook workbook = new XSSFWorkbook(fis);

        XSSFSheet sheet = workbook.getSheet("Movies");

        Map<String, Object[]> label = new TreeMap<>();
        label.put("1",
                new Object[] { "", parsedObj.get("Title"), parsedObj.get("Released"),
                        parsedObj.get("Metascore"), parsedObj.get("imdbRating"), parsedObj.get("Plot"),
                        parsedObj.get("imdbID"), parsedObj.get("Genre"), parsedObj.get("Director"),
                        parsedObj.get("Actors"), parsedObj.get("Rated"), parsedObj.get("Runtime") });

        Set<String> keyset = label.keySet();

        // Setting Style for the Label Row

        XSSFCellStyle contentStyle = workbook.createCellStyle();
        contentStyle.setWrapText(true);
        contentStyle.setVerticalAlignment(VerticalAlignment.TOP);

        rownum = rownum + lastRow;

        if (posterFile.exists()) {
            InputStream imageStream = new FileInputStream(
                    thumbnailPath + File.separator + parsedObj.get("Title") + ".jpg");
            byte[] imageBytes = IOUtils.toByteArray(imageStream);
            pictureureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG);
            imageStream.close();

            CreationHelper helper = workbook.getCreationHelper();
            drawing = sheet.createDrawingPatriarch();
            anchor = helper.createClientAnchor();

        }

        for (String key : keyset) {

            Row row = sheet.createRow(rownum++);
            row.setHeight((short) 2000);
            Object[] objArr = label.get(key);
            int cellnum = 0;
            for (Object obj : objArr) {
                Cell cell = row.createCell(cellnum++);
                cell.setCellStyle(contentStyle);
                cell.setCellValue((String) obj);
            }
            if (posterFile.exists()) {
                anchor.setCol1(0);
                anchor.setRow1(rownum - 1);
                anchor.setCol2(0);
                anchor.setRow2(rownum - 1);
                Picture pict = drawing.createPicture(anchor, pictureureIdx);
                pict.resize(1, 1);
            }
        }
        FileOutputStream out = new FileOutputStream(file);
        workbook.write(out);
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.runwaysdk.dataaccess.io.excel.ErrorSheet.java

License:Open Source License

public void addRow(Row _row) {
    Row row = this.errorSheet.createRow(count++);
    row.setZeroHeight(_row.getZeroHeight());
    row.setHeight(_row.getHeight());

    CellStyle style = _row.getRowStyle();

    if (style != null) {
        Workbook workbook = row.getSheet().getWorkbook();

        CellStyle clone = workbook.createCellStyle();
        clone.cloneStyleFrom(style);//w  ww.ja  v a  2 s . co  m

        row.setRowStyle(clone);
    }

    Iterator<Cell> cellIterator = _row.cellIterator();
    while (cellIterator.hasNext()) {
        Cell oldCell = cellIterator.next();
        Cell newCell = row.createCell(oldCell.getColumnIndex());

        int cellType = oldCell.getCellType();

        if (cellType == Cell.CELL_TYPE_FORMULA) {
            cellType = oldCell.getCachedFormulaResultType();
        }

        switch (cellType) {
        case Cell.CELL_TYPE_BOOLEAN:
            newCell.setCellValue(oldCell.getBooleanCellValue());
            break;
        case Cell.CELL_TYPE_NUMERIC:
            newCell.setCellValue(oldCell.getNumericCellValue());
            break;
        case Cell.CELL_TYPE_STRING:
            newCell.setCellValue(oldCell.getRichStringCellValue());
            break;
        }
    }
}

From source file:com.sany.appbom.service.AppBomServiceImpl.java

License:Open Source License

public void setExcelData(Workbook workbook, boolean is2003, List<AppBom> beans) {
    try {//from  w w  w .  j ava 2s . c  o  m
        Sheet sheet = null;
        CellStyle cellStyle = null;
        Font font = null;
        if (is2003) {
            sheet = (HSSFSheet) workbook.getSheetAt(0);

        } else {
            sheet = (XSSFSheet) workbook.getSheetAt(0);
            cellStyle = (XSSFCellStyle) workbook.createCellStyle();
        }
        for (int i = 0; i < beans.size(); i++) {
            AppBom bom = beans.get(i);
            Row row = null;
            row = sheet.createRow(i + 2);
            row.setHeight((short) 450);
            row.createCell(0).setCellValue(bom.getBm());
            row.createCell(1).setCellValue(bom.getApp_name_en());
            row.createCell(2).setCellValue(bom.getApply_domain());
            row.createCell(3).setCellValue(bom.getApp_name());
            row.createCell(4).setCellValue(bom.getDescription());
            row.createCell(5).setCellValue(getSoftLevel(bom.getSoft_level()));
            row.createCell(6).setCellValue(bom.getSupplier());
            row.createCell(7).setCellValue(bom.getStart_year());
            row.createCell(8).setCellValue(getState(bom.getState()));
            row.createCell(9).setCellValue(getRdType(bom.getRd_type()));
            row.createCell(10).setCellValue(bom.getVersion_no());
            row.createCell(11).setCellValue(bom.getDomain_url());
            row.createCell(12).setCellValue(bom.getStruct_mode());
            row.createCell(13).setCellValue(bom.getSoft_language());
            row.createCell(14).setCellValue(bom.getDevelop_tool());
            row.createCell(15).setCellValue(bom.getDb_type());
            row.createCell(16).setCellValue(bom.getDepartment_develop());
            row.createCell(17).setCellValue(bom.getProduct_manager());
            row.createCell(18).setCellValue(bom.getDepartment_maintain());
            row.createCell(19).setCellValue(bom.getSys_manager());
            row.createCell(20).setCellValue(getPlanType(bom.getPlan_type()));
            row.createCell(21).setCellValue(bom.getEvolve_strategy());
            row.createCell(22).setCellValue(bom.getEvolve_plan());
            row.createCell(23).setCellValue(bom.getEvolve_depart());
            row.createCell(24).setCellValue(getManageScope(bom.getManage_scope()));
            row.createCell(25).setCellValue(bom.getMain_description());
        }
    } catch (Exception e) {
        e.printStackTrace();

    } finally {

    }
}

From source file:com.sec.ose.osi.report.standard.BillOfMaterialsSheetTemplate.java

License:Open Source License

protected void createTitle() {
    // Title/*from  ww w  .  j  a  v  a2 s .  c  om*/
    Row row = sheet.createRow(ROW_1);
    row.setHeight((short) (43 * BASE_HEIGHT));

    sheet.addMergedRegion(CellRangeAddress.valueOf("A1:F1"));

    Cell cell = row.createCell(COL_A);
    cell.setCellValue(sheet.getSheetName());
    cell.setCellStyle(titleStyle);
}

From source file:com.sec.ose.osi.report.standard.BillOfMaterialsSheetTemplate.java

License:Open Source License

protected void createTable() {

    short mainItemThickness = (short) (24 * BASE_HEIGHT);
    short subItemThickness = (short) (18 * BASE_HEIGHT);
    CellStyle styleMainItem = getCellStyle(ROYAL_BLUE, getFont(FONT_WHITE, (short) 12, true));

    //  ROW_2/*from w w  w  .j  ava  2  s.c o m*/
    Row row = sheet.createRow(ROW_2);
    row.setHeight(mainItemThickness);

    sheet.addMergedRegion(CellRangeAddress.valueOf("A2:F2"));

    Cell cell = row.createCell(COL_A);
    cell.setCellValue("Open source License Verification Result ");
    cell.setCellStyle(styleMainItem);

    row.createCell(COL_B).setCellStyle(styleMainItem);
    row.createCell(COL_C).setCellStyle(styleMainItem);
    row.createCell(COL_D).setCellStyle(styleMainItem);
    row.createCell(COL_E).setCellStyle(styleMainItem);
    row.createCell(COL_F).setCellStyle(styleMainItem);

    //  ROW_3
    row = sheet.createRow(ROW_3);
    row.setHeight(subItemThickness);

    CellStyle style = getCellStyle(PALE_BLUE, getFont(FONT_BLACK, (short) 10, false));

    cell = row.createCell(COL_A);
    cell.setCellValue("Category");
    cell.setCellStyle(style);

    cell = row.createCell(COL_B);
    cell.setCellValue("Files");
    cell.setCellStyle(style);

    cell = row.createCell(COL_C);
    cell.setCellValue("Files #");
    cell.setCellStyle(style);

    cell = row.createCell(COL_D);
    cell.setCellValue("Component");
    cell.setCellStyle(style);

    cell = row.createCell(COL_E);
    cell.setCellValue("License");
    cell.setCellStyle(style);

    cell = row.createCell(COL_F);
    cell.setCellValue("Remark");
    cell.setCellStyle(style);

}

From source file:com.sec.ose.osi.report.standard.CoverSheetTemplate.java

License:Open Source License

protected void createTitle() {
    short lineThickness = (short) (6 * BASE_HEIGHT);

    // Top Line/*from   w  ww.ja  v a  2s.c  o  m*/
    Row row = sheet.createRow(ROW_4);
    row.setHeight(lineThickness);

    XSSFCellStyle style = wb.createCellStyle();
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    setDummyTitleStyle(row, style);

    // Title
    row = sheet.createRow(ROW_5);
    row.setHeightInPoints(100);
    sheet.addMergedRegion(CellRangeAddress.valueOf("B5:G5"));

    Font font = wb.createFont();
    font.setFontHeightInPoints((short) 28);
    font.setFontName("Trebuchet MS");
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();
    style.setFont(font);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    setDummyTitleStyle(row, style);
    row.getCell(COL_B).setCellValue("Open Source License Verification Report");

    // Bottom Line
    row = sheet.createRow(ROW_6);
    row.setHeight(lineThickness);

    style = wb.createCellStyle();
    style.setFillForegroundColor(DARK_BLUE);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    setDummyTitleStyle(row, style);
}

From source file:com.sec.ose.osi.report.standard.CoverSheetTemplate.java

License:Open Source License

protected void createTable() {

    Font fontBold = getFont(FONT_BLACK, (short) 11, true);
    Font fontNormal = getFont(FONT_BLACK, (short) 11, false);

    short tableThickness = (short) (37 * BASE_HEIGHT);
    short toolThickness = (short) (55 * BASE_HEIGHT);

    //  ROW_10/*from w w  w  .  j a v a 2  s . c  o m*/
    Row row = sheet.createRow(ROW_10);
    row.setHeight(tableThickness);

    XSSFCellStyle style = getCellStyle(BORDER_LEFT | BORDER_TOP, fontBold);
    Cell cell = row.createCell(COL_C);
    cell.setCellValue("Project Name");
    cell.setCellStyle(style);

    style = getCellStyle(BORDER_TOP, fontNormal);
    row.createCell(COL_D).setCellStyle(style);

    style = getCellStyle(BORDER_TOP, fontBold);
    cell = row.createCell(COL_E);
    cell.setCellValue("Date");
    cell.setCellStyle(style);

    style = getCellStyle(BORDER_RIGHT | BORDER_TOP, fontNormal);
    row.createCell(COL_F).setCellStyle(style);

    //  ROW_11
    row = sheet.createRow(ROW_11);
    row.setHeight(tableThickness);

    sheet.addMergedRegion(CellRangeAddress.valueOf("D11:F11"));

    style = getCellStyle(BORDER_LEFT, fontBold);
    cell = row.createCell(COL_C);
    cell.setCellValue("Author");
    cell.setCellStyle(style);

    style = getCellStyle(0, fontNormal);
    row.createCell(COL_D).setCellStyle(style);
    row.createCell(COL_E).setCellStyle(style);

    style = getCellStyle(BORDER_RIGHT, fontNormal);
    row.createCell(COL_F).setCellStyle(style);

    //  ROW_12
    row = sheet.createRow(ROW_12);
    row.setHeight(tableThickness);

    sheet.addMergedRegion(CellRangeAddress.valueOf("D12:F12"));

    style = getCellStyle(BORDER_LEFT, fontBold);
    cell = row.createCell(COL_C);
    cell.setCellValue("Team");
    cell.setCellStyle(style);

    style = getCellStyle(0, fontNormal);
    row.createCell(COL_D).setCellStyle(style);
    row.createCell(COL_E).setCellStyle(style);

    style = getCellStyle(BORDER_RIGHT, fontNormal);
    row.createCell(COL_F).setCellStyle(style);

    //  ROW_13
    row = sheet.createRow(ROW_13);
    row.setHeight(toolThickness);

    sheet.addMergedRegion(CellRangeAddress.valueOf("D13:F13"));

    style = getCellStyle(BORDER_BOTTOM | BORDER_LEFT, fontBold);
    cell = row.createCell(COL_C);
    cell.setCellValue("Tool");
    cell.setCellStyle(style);

    style = getCellStyle(BORDER_BOTTOM, fontNormal);
    row.createCell(COL_D).setCellStyle(style);
    row.createCell(COL_E).setCellStyle(style);

    style = getCellStyle(BORDER_BOTTOM | BORDER_RIGHT, fontNormal);
    row.createCell(COL_F).setCellStyle(style);

}

From source file:com.sec.ose.osi.report.standard.IdentifiedFilesSheetTemplate.java

License:Open Source License

protected void createTitle() {
    // Title/*from   www.  java  2 s .c om*/
    Row row = sheet.createRow(ROW_1);
    row.setHeight((short) (43 * BASE_HEIGHT));

    sheet.addMergedRegion(CellRangeAddress.valueOf("A1:G1"));

    Cell cell = row.createCell(COL_A);
    cell.setCellValue("Identified Files");
    cell.setCellStyle(titleStyle);
}