Example usage for org.apache.poi.ss.usermodel Cell setCellValue

List of usage examples for org.apache.poi.ss.usermodel Cell setCellValue

Introduction

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

Prototype

void setCellValue(boolean value);

Source Link

Document

Set a boolean value for the cell

Usage

From source file:com.github.jferard.spreadsheetwrapper.xls.poi.XlsPoiWriter.java

License:Open Source License

/** */
@Override// ww  w.ja  v a  2 s  . c o m
public String setText(final int r, final int c, final String text) {
    final Cell cell = this.getOrCreatePOICell(r, c);
    cell.setCellValue(text);
    return text;
}

From source file:com.github.luischavez.lat.excel.Excel.java

License:Open Source License

protected void createCell(int index, Row row, CellStyle style, String value) {
    Cell cell = row.createCell(index);
    if (null != style) {
        cell.setCellStyle(style);/* w  w w . j av  a 2s  . com*/
    }
    cell.setCellValue(value);
}

From source file:com.github.luischavez.lat.excel.Excel.java

License:Open Source License

protected void createNumber(int index, Row row, CellStyle style, double value) {
    Cell cell = row.createCell(index);
    if (null != style) {
        cell.setCellStyle(style);/*  w w  w .ja va  2s  . com*/
    }
    cell.setCellValue(value);
}

From source file:com.github.mutationmapper.MutationMapperResultViewController.java

License:Open Source License

private void writeResultsToExcel(final File f) throws IOException {
    final Service<Void> service = new Service<Void>() {
        @Override/*  w ww .  j  a v a 2s . co m*/
        protected Task<Void> createTask() {
            return new Task<Void>() {
                @Override
                protected Void call() throws IOException {
                    BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(f));
                    Workbook wb = new XSSFWorkbook();
                    //CellStyle hlink_style = wb.createCellStyle();
                    //Font hlink_font = wb.createFont();
                    //hlink_font.setUnderline(Font.U_SINGLE);
                    //hlink_font.setColor(IndexedColors.BLUE.getIndex());
                    //hlink_style.setFont(hlink_font);
                    //CreationHelper createHelper = wb.getCreationHelper();
                    Sheet sheet = wb.createSheet();
                    Row row = null;
                    int rowNo = 0;
                    row = sheet.createRow(rowNo++);
                    String header[] = { "#", "Symbol", "Gene", "Transcript", "Genomic Coordinate", "Ref", "Var",
                            "CDS", "Consequence", "CDS Consequence", "Protein Consequence", "Exon/Intron",
                            "Colocated Variants", "Polyphen", "Sift", "Seq Input" };
                    for (int col = 0; col < header.length; col++) {
                        Cell cell = row.createCell(col);
                        cell.setCellValue(header[col]);
                    }

                    updateMessage("Writing results . . .");
                    updateProgress(0, displayData.size());
                    int n = 0;
                    for (MutationMapperResult r : displayData) {
                        n++;
                        updateMessage("Writing result " + n + " . . .");
                        row = sheet.createRow(rowNo++);
                        int col = 0;
                        ArrayList<String> resultsToWrite = getResultArray(r);
                        for (String s : resultsToWrite) {
                            Cell cell = row.createCell(col++);
                            cell.setCellValue(s);
                        }
                        updateProgress(n, displayData.size());
                    }

                    updateMessage("Wrote " + displayData.size() + " results to file.");
                    wb.write(bo);
                    bo.close();
                    return null;
                }
            };
        }

    };

    service.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent e) {
            Alert alert = new Alert(AlertType.CONFIRMATION);
            alert.setTitle("File Saved");
            alert.setHeaderText("Displayed results saved to " + f.getName());
            alert.setContentText("Open this file now?");
            ButtonType yesButton = ButtonType.YES;
            ButtonType noButton = ButtonType.NO;
            alert.getButtonTypes().setAll(yesButton, noButton);
            Optional<ButtonType> response = alert.showAndWait();
            if (response.get() == yesButton) {
                try {
                    openFile(f);
                } catch (Exception ex) {
                    Alert openError = getExceptionDialog(ex);
                    openError.setTitle("Open Failed");
                    openError.setHeaderText("Could not open ouput file.");
                    openError.setContentText(
                            "Exception encountered when attempting to open " + "the saved file. See below:");
                    openError.showAndWait();
                }
            }
        }
    });
    service.setOnCancelled(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent e) {
            Alert writeCancelled = new Alert(AlertType.INFORMATION);
            writeCancelled.setTitle("Cancelled writing to file");
            writeCancelled.setHeaderText("User cancelled writing primers to file.");
            writeCancelled.showAndWait();
        }
    });
    service.setOnFailed(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent e) {
            Alert writeFailed = getExceptionDialog(e.getSource().getException());
            writeFailed.setTitle("Write Failed");
            writeFailed.setHeaderText("Could not write ouput file.");
            writeFailed.setContentText(
                    "Exception encountered when attempting to write " + "results to file. See below:");
            writeFailed.showAndWait();

        }
    });
    service.start();
}

From source file:com.github.pascalgn.jiracli.testutil.ExcelUtils.java

License:Apache License

/**
 * @param row 0-based index/*from   ww w.j  a  va 2  s.co m*/
 * @param column 0-based index
 */
public static void writeCell(Sheet sheet, int row, int column, String value) {
    Row r = sheet.getRow(row);
    if (r == null) {
        r = sheet.createRow(row);
    }
    Cell cell = r.getCell(column);
    if (cell == null) {
        cell = r.createCell(column, Cell.CELL_TYPE_STRING);
    }
    cell.setCellValue(value);
}

From source file:com.github.svrtm.xlreport.Cells.java

License:Apache License

/**
 * Finalization of the implementation <code>Cells</code>.
 *
 * @return an instance of the implementation <code>Row</code>
 * @see com.github.svrtm.xlreport.Row#addCells(int)
 * @see com.github.svrtm.xlreport.Row#addCells(int...)
 *///from   w w  w .  j  av a2  s.c  om
@SuppressWarnings("unchecked")
public TR configureCells() {
    if (columnWidth == -1 && incrementValue == -1 && cellStyle == null)
        return (TR) row;

    int increment = incrementValue;
    for (final int i : indexesCells) {
        if (row.cells.get(i) == null)
            row.prepareNewCell(i).createCell();

        final org.apache.poi.ss.usermodel.Row poiRow = row.poiRow;
        final Cell poiCell = poiRow.getCell(i);
        if (poiCell == null)
            throw new ReportBuilderException(
                    format("A cell of number %d [row:%d] can't be found. Please, create a cell before using it",
                            i, poiRow.getRowNum()));

        if (columnWidth != -1)
            poiCell.getSheet().setColumnWidth(i, columnWidth);
        if (incrementValue != -1)
            poiCell.setCellValue(increment++);
        if (enableAutoSize)
            setAutoSizeColumn(poiCell);

        if (cellStyle != null)
            if (row.cells.get(i).cellStyle == null) {
                // Apply a style to the cell
                final CellStyle poiStyle = cellStyle.getStyle();
                poiCell.setCellStyle(poiStyle);

                final List<Cell> mergedCells = findMergedCells(poiCell);
                if (mergedCells != null)
                    for (final Cell mergedCell : mergedCells)
                        mergedCell.setCellStyle(poiStyle);
            }
    }

    return (TR) row;
}

From source file:com.github.ukase.toolkit.xlsx.RenderingTable.java

License:Open Source License

private void processCell(Row row, Element td) {
    TableCellBox cellBox = (TableCellBox) (box.getElementBoxes(td)).get(0);
    CellStyle style = prepareCellStyle(cellBox.getStyle());

    mergedCells.stream().filter(merge -> merge.isApplicable(row)).forEach(merge -> merge.fillRow(row));

    int cellNumber = row.getPhysicalNumberOfCells();
    Cell cell = row.createCell(cellNumber);
    cell.setCellValue(td.getTextContent());
    cell.setCellStyle(style);//from  ww  w .jav a 2s.  co  m

    mergeCells(row, td, cellNumber, style);
    calculateColumnWidth(cellNumber, cellBox.getStyle());
}

From source file:com.github.wnameless.workbookaccessor.WorkbookWriter.java

License:Apache License

/**
 * Adds a row to the sheet.//from www .  jav  a2s.  c  om
 * 
 * @param fields
 *          an Iterable of Object
 * @return this {@link WorkbookWriter}
 */
public WorkbookWriter addRow(Iterable<? extends Object> fields) {
    Row row;
    if (sheet.getLastRowNum() == 0 && sheet.getPhysicalNumberOfRows() == 0)
        row = sheet.createRow(0);
    else
        row = sheet.createRow(sheet.getLastRowNum() + 1);

    int i = 0;
    for (Object o : fields) {
        Cell cell = row.createCell(i);
        if (o != null) {
            if (o instanceof Boolean)
                cell.setCellValue((Boolean) o);
            else if (o instanceof Calendar)
                cell.setCellValue((Calendar) o);
            else if (o instanceof Date)
                cell.setCellValue((Date) o);
            else if (o instanceof Double)
                cell.setCellValue((Double) o);
            else if (o instanceof RichTextString)
                if ((o instanceof HSSFRichTextString && workbook instanceof HSSFWorkbook)
                        || (o instanceof XSSFRichTextString && workbook instanceof XSSFWorkbook)) {
                    cell.setCellValue((RichTextString) o);
                } else {
                    cell.setCellValue(o.toString());
                }
            else if (o instanceof Hyperlink)
                cell.setHyperlink((Hyperlink) o);
            else if (o instanceof Number)
                cell.setCellValue(((Number) o).doubleValue());
            else
                cell.setCellValue(o.toString());
        }
        i++;
    }
    return this;
}

From source file:com.globalsight.everest.qachecks.DITAQAChecker.java

License:Apache License

private void addTitle(Workbook p_workBook, Sheet p_sheet) throws Exception {
    Font titleFont = p_workBook.createFont();
    titleFont.setUnderline(Font.U_NONE);
    titleFont.setFontName("Times");
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    CellStyle cs = p_workBook.createCellStyle();
    cs.setFont(titleFont);/*from   ww w  .jav  a 2  s .  c o m*/

    Row titleRow = getRow(p_sheet, 0);
    Cell titleCell = getCell(titleRow, 0);
    titleCell.setCellValue("DITA QA Report");
    titleCell.setCellStyle(cs);
}

From source file:com.globalsight.everest.qachecks.DITAQAChecker.java

License:Apache License

private void addLanguageHeader(Workbook p_workBook, Sheet p_sheet) throws Exception {
    int col = 0;//from w w  w .  j  av  a2s . co  m
    int row = LANGUAGE_HEADER_ROW;

    Row langRow = getRow(p_sheet, row);
    Cell srcLangCell = getCell(langRow, col);
    srcLangCell.setCellValue(m_bundle.getString("lb_source_language"));
    srcLangCell.setCellStyle(getHeaderStyle(p_workBook));
    col++;

    Cell trgLangCell = getCell(langRow, col);
    trgLangCell.setCellValue(m_bundle.getString("lb_target_language"));
    trgLangCell.setCellStyle(getHeaderStyle(p_workBook));
}