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:au.gov.ansto.bragg.quokka.experiment.util.ExperimentModelUtils.java

License:Open Source License

private static int saveAcquisitionToExcel(Acquisition acquisition, Sheet sheet, int rowCounter) {
    // 1st header
    Row row = sheet.createRow(rowCounter++);
    int colIndex = 5;
    for (InstrumentConfig config : acquisition.getExperiment().getInstrumentConfigs()) {
        Cell cell = row.createCell(colIndex);
        cell = row.createCell(colIndex);
        cell.setCellValue(config.getName());
        colIndex += 5;/*  w  w  w  .j  a v  a2s  .  c  om*/
    }

    // 2nd header
    row = sheet.createRow(rowCounter++);
    Cell cell = row.createCell(0);
    cell.setCellValue("Sequence");
    cell = row.createCell(1);
    cell.setCellValue("Position");
    cell = row.createCell(2);
    cell.setCellValue("Sample Name");
    cell = row.createCell(3);
    cell.setCellValue("Thickness");
    colIndex = 4;
    for (InstrumentConfig config : acquisition.getExperiment().getInstrumentConfigs()) {
        cell = row.createCell(colIndex++);
        cell = row.createCell(colIndex++);
        cell.setCellValue("Transmission");
        cell = row.createCell(colIndex++);
        cell = row.createCell(colIndex++);
        cell.setCellValue("Scattering");
        cell = row.createCell(colIndex++);
        cell.setCellValue("Preset (sec)");
    }

    // Content
    int sequence = 1;
    for (AcquisitionEntry entry : acquisition.getEntries()) {
        row = sheet.createRow(rowCounter++);
        cell = row.createCell(0);
        cell.setCellValue(sequence);
        cell = row.createCell(1);
        cell.setCellValue(entry.getSample().getPosition());
        cell = row.createCell(2);
        cell.setCellValue(entry.getSample().getName());
        cell = row.createCell(3);
        cell.setCellValue(entry.getSample().getThickness());
        colIndex = 4;
        for (InstrumentConfig config : acquisition.getExperiment().getInstrumentConfigs()) {
            AcquisitionSetting setting = entry.getConfigSettings().get(config);
            cell = row.createCell(colIndex++);
            if (setting.isRunTransmission()) {
                cell.setCellValue("X");
            }
            cell = row.createCell(colIndex++);
            cell.setCellValue(setting.getTransmissionDataFile());
            cell = row.createCell(colIndex++);
            if (setting.isRunScattering()) {
                cell.setCellValue("X");
            }
            cell = row.createCell(colIndex++);
            cell.setCellValue(setting.getScatteringDataFile());
            cell = row.createCell(colIndex++);
            cell.setCellValue(setting.getPreset());
        }
        sequence++;
    }
    return ++rowCounter;
}

From source file:automatedhgl.AutomatedHGL.java

public static void main(String[] args) {

    try {//from w  w  w .  j av  a2s.c  o m

        FileInputStream excelFile = new FileInputStream(new File(INFILE_NAME));

        //create workbook instance holding reference to .xlsx file
        XSSFWorkbook workbook = new XSSFWorkbook(excelFile);

        //get first desired sheet from the workbook
        XSSFSheet sheet = workbook.getSheetAt(0);

        //create workbook instance to output excel file
        XSSFWorkbook workbookHGL = new XSSFWorkbook();

        //create sheet in output excel file
        XSSFSheet sheetHGL = workbookHGL.createSheet("HGL");

        //iterate through each row one by one
        Iterator<Row> rowiterator = sheet.iterator();

        while (rowiterator.hasNext()) {
            Row row = rowiterator.next();

            //for each row, iterate through all the columns
            Iterator<Cell> cellIterator = row.cellIterator();

            while (cellIterator.hasNext()) {

                Cell cell = cellIterator.next();

                if (row.getRowNum() > 7 && count < 23) //to filter column headings
                {

                    //check the cell type and format accordingly
                    switch (cell.getCellType()) {
                    case Cell.CELL_TYPE_NUMERIC:
                        count++;

                        //assign get value to correct variable
                        if (count == 1) {
                            InletStr = cell.getNumericCellValue();
                        } else if (count == 2) {
                            OutWSE = cell.getNumericCellValue();
                        }

                        System.out.print(cell.getNumericCellValue() + " (" + count + ") ");
                        break;

                    case Cell.CELL_TYPE_STRING:
                        count++;

                        /*//assign get value to correct variable
                        if( count == 1 ){InletStr = cell.getStringCellValue();}*/

                        System.out.print(cell.getStringCellValue() + " (" + count + ") ");
                        break;

                    case Cell.CELL_TYPE_FORMULA:
                        count++;

                        /*//assign get value to correct variable
                        if( count == 1 ){InletStr = cell.getCachedFormulaResultType();}*/

                        System.out.print(cell.getCachedFormulaResultType() + " (" + count + ") ");
                        break;
                    }
                }

                else {
                    count = 0; //reset the count at the end of the row
                }

            }

            System.out.println("return");
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //Output Excel file

    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("Datatypes in Java");
    Object[][] datatypes = { { "Datatype", "Type", "Size(in bytes)" }, { "int", "Primitive", 2 },
            { "float", "Primitive", 4 }, { "double", "Primitive", 8 }, { "char", "Primitive", 1 },
            { "String", "Non-Primitive", "No fixed size" } };

    int rowNum = 0;
    System.out.println("Creating excel");

    for (Object[] datatype : datatypes) {
        Row row = sheet.createRow(rowNum++);
        int colNum = 0;
        for (Object field : datatype) {
            Cell cell = row.createCell(colNum++);
            if (field instanceof String) {
                cell.setCellValue((String) field);
            } else if (field instanceof Integer) {
                cell.setCellValue((Integer) field);
            }
        }
    }

    try {
        FileOutputStream outputStream = new FileOutputStream(FILE_NAME);
        workbook.write(outputStream);
        workbook.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print(InletStr + " ");
    System.out.print(OutWSE + " ");
    System.out.println("HGL Done");

}

From source file:b01.officeLink.excel.ExcelRefiller.java

License:Apache License

public void fillGroupContent(String groupStr, FocObject object) {
    ExcelGroupDefinition grpDef = getGroupDefinition(groupStr);
    Sheet srcSheet = getSourceSheet();//from   w  w  w  .  j  a va  2  s  .  co m
    Sheet tarSheet = getTargetSheet();
    if (grpDef != null) {
        for (int i = 0; i < grpDef.getRowCount(); i++) {
            int rowIdx = grpDef.getRowAt(i);
            Row sRow = srcSheet.getRow(rowIdx);
            if (sRow != null) {
                Row tRow = tarSheet.getRow(currentRow);
                if (tRow == null) {
                    tRow = tarSheet.createRow(currentRow);
                }
                if (tRow != null) {
                    tRow.setHeight(sRow.getHeight());
                    for (int c = 0; c < 20; c++) {
                        Cell sCell = sRow.getCell(c + 1);
                        if (sCell != null) {
                            Cell tCell = tRow.getCell(c);
                            if (tCell == null) {
                                tCell = tRow.createCell(c);
                            }
                            if (tCell != null) {
                                tCell.setCellStyle(sCell.getCellStyle());

                                String str = "";
                                if (sCell.getCellType() == Cell.CELL_TYPE_STRING) {
                                    RichTextString rts = sCell.getRichStringCellValue();
                                    str = rts.getString();
                                    str = analyseContent(str, object);
                                } else if (sCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                    str = String.valueOf(sCell.getNumericCellValue());
                                }

                                if (str != null && !str.isEmpty()) {
                                    int iVal = convertString2Integer(str);
                                    double dVal = convertString2Double(str);
                                    if (iVal != Integer.MAX_VALUE) {
                                        tCell.setCellValue(iVal);
                                    } else if (!Double.isNaN(dVal)) {
                                        tCell.setCellValue(dVal);
                                    } else {
                                        if (getFocExcelDocument() != null
                                                && getFocExcelDocument().getWorkbook() != null) {
                                            tCell.setCellValue(getFocExcelDocument().getWorkbook()
                                                    .getCreationHelper().createRichTextString(str));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                currentRow++;
            }
        }
    }
}

From source file:b01.officeLink.excel.FocExcelDocument.java

License:Apache License

public void exportLocally(FocObject object) {
    try {/*from ww w .j  ava2 s  .  c  o m*/
        Sheet sheet = workbook.getSheetAt(0);
        // Iterate over each row in the sheet
        Iterator rows = sheet.rowIterator();
        while (rows.hasNext()) {
            Row row = (Row) rows.next();
            System.out.println("Row #" + row.getRowNum());
            // Iterate over each cell in the row and print out the cell's content
            Iterator cells = row.cellIterator();
            while (cells.hasNext()) {
                Cell cell = (Cell) cells.next();
                System.out.println("Cell #" + cell.getColumnIndex());
                /* System.out.println(String.valueOf(cell.getRichStringCellValue())); */
                String str = null;
                try {
                    str = String.valueOf(cell.getRichStringCellValue());
                } catch (Exception e) {
                    Globals.logExceptionWithoutPopup(e);
                    str = "";
                }
                String result = analyseContent(str, object);
                if (result != null) {

                    if (getWorkbook() != null) {
                        cell.setCellValue(getWorkbook().getCreationHelper().createRichTextString(result));
                    }
                }
                /*
                 * switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_NUMERIC:
                 * System.out.println(cell.getNumericCellValue()); String result =
                 * analyseContent(String.valueOf(cell.getNumericCellValue()), object);
                 * if (result != null){ cell.setCellValue(Double.valueOf(result)); }
                 * break; case HSSFCell.CELL_TYPE_STRING:
                 * System.out.println(cell.getRichStringCellValue()); result =
                 * analyseContent(String.valueOf(cell.getRichStringCellValue()),
                 * object); if (result != null){ cell.setCellValue(new
                 * HSSFRichTextString(result)); } break; default:
                 * System.out.println("unsuported cell type"); break; }
                 */}
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:b01.officeLink.excel.FocExcelSheet.java

License:Apache License

public void set(int coord0, int coord1, Double dVal) {
    Row row = sheet.getRow(coord0);//from w  w  w . j av a  2  s .  c  om
    Cell cell = null;

    if (row != null) {
        cell = row.getCell(coord1);
        if (cell == null)
            cell = row.createCell((short) coord1);
    }

    if (cell != null) {
        // cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        cell.setCellValue(dVal);
    }
}

From source file:b01.officeLink.excel.FocExcelSheet.java

License:Apache License

public void set(int coord0, int coord1, String sVal) {
    Row row = sheet.getRow(coord0);// w w w  . ja  va2  s .c o  m
    Cell cell = row != null ? row.getCell(coord1) : null;

    if (cell != null && sVal != null) {
        cell.setCellType(Cell.CELL_TYPE_STRING);
        if (sheet.getWorkbook() != null) {
            RichTextString textString = sheet.getWorkbook().getCreationHelper().createRichTextString(sVal);
            cell.setCellValue(textString);
        }
    }
}

From source file:bad.robot.excel.cell.BooleanCell.java

License:Apache License

@Override
public void update(org.apache.poi.ss.usermodel.Cell cell, Workbook workbook) {
    this.getStyle().applyTo(cell, workbook);
    cell.setCellValue(value);
}

From source file:bad.robot.excel.cell.DateCell.java

License:Apache License

@Override
public void update(org.apache.poi.ss.usermodel.Cell cell, Workbook workbook) {
    this.getStyle().applyTo(cell, workbook);
    if (!isCellDateFormatted(cell))
        overrideAsDateFormatting(workbook, cell);
    cell.setCellValue(date);
}

From source file:bad.robot.excel.cell.DoubleCell.java

License:Apache License

@Override
public void update(org.apache.poi.ss.usermodel.Cell cell, Workbook workbook) {
    this.getStyle().applyTo(cell, workbook);
    cell.setCellValue(number);
}

From source file:bad.robot.excel.cell.HyperlinkCell.java

License:Apache License

@Override
public void update(org.apache.poi.ss.usermodel.Cell cell, Workbook workbook) {
    this.getStyle().applyTo(cell, workbook);
    cell.setCellValue(text);
    cell.setHyperlink(createHyperlink(workbook));
}