Example usage for org.apache.poi.xssf.usermodel XSSFCell setCellValue

List of usage examples for org.apache.poi.xssf.usermodel XSSFCell setCellValue

Introduction

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

Prototype

@Override
public void setCellValue(boolean value) 

Source Link

Document

Set a boolean value for the cell

Usage

From source file:dias.Save.java

public void save(Matrix matrice, String filename) throws FileNotFoundException, IOException { ///It is working
    String dirPath = DIAS.excelFilePath + File.separator + filepath;
    setupDirectory(dirPath);//from w  ww .j a  va  2 s .co m
    String fileName = dirPath + File.separator + filename + ".xlsx";
    System.out.println("Using filepath " + filepath + ", saving to address: " + fileName);
    try {
        FileOutputStream fileOut = new FileOutputStream(fileName);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet worksheet = workbook.createSheet("POI Worksheet");

        int lastvaluex = matrice.getRowDimension();
        int lastvaluey = matrice.getColumnDimension();
        int ih = 0;
        int jh = 0;

        while (ih < lastvaluex) {

            XSSFRow row = worksheet.createRow(ih);
            ih++;
            while (jh < lastvaluey) {
                XSSFCell cell = row.createCell(jh);
                jh++;
                cell.setCellValue(matrice.get(ih - 1, jh - 1));
            }
            jh = 0;
        }
        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:dias.Save.java

public void savedouble(double matrice, String filename) throws FileNotFoundException, IOException { ///It is working
    String dirPath = DIAS.excelFilePath + File.separator + filepath;
    setupDirectory(dirPath);/*  ww  w .j av a  2s  .  c  om*/
    String fileName = dirPath + File.separator + filename + ".xlsx";
    try {
        FileOutputStream fileOut = new FileOutputStream(fileName);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet worksheet = workbook.createSheet("POI Worksheet");

        int lastvaluex = 1;
        int lastvaluey = 1;
        int ih = 0;
        int jh = 0;

        while (ih < lastvaluex) {

            XSSFRow row = worksheet.createRow(ih);
            ih++;
            while (jh < lastvaluey) {
                XSSFCell cell = row.createCell(jh);
                jh++;
                cell.setCellValue(matrice);
            }
            jh = 0;
        }
        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:dias.Save.java

public void save3D(Matrix matrice, String filename, int kj) throws FileNotFoundException, IOException { ///It is working
    String dirPath = DIAS.excelFilePath + File.separator + filepath;
    setupDirectory(dirPath);// w w  w .  j  ava  2s  .co  m
    String fileName = dirPath + File.separator + filename + kj + ".xlsx";
    try {
        FileOutputStream fileOut = new FileOutputStream(fileName);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet worksheet = workbook.createSheet("POI Worksheet");

        int lastvaluex = matrice.getRowDimension();
        int lastvaluey = matrice.getColumnDimension();
        int ih = 0;
        int jh = 0;

        while (ih < lastvaluex) {
            XSSFRow row = worksheet.createRow(ih);
            while (jh < lastvaluey) {
                XSSFCell cell = row.createCell(jh);
                cell.setCellValue(matrice.get(ih, jh));
                jh++;
            }
            ih++;
            jh = 0;
        }
        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:dias.Save.java

public void saveString(String[] matrice, String filename) throws FileNotFoundException, IOException { ///It is working
    String dirPath = DIAS.excelFilePath + File.separator + filepath;
    setupDirectory(dirPath);/*w w w .j  a  va2s  .  c om*/
    String fileName = dirPath + File.separator + filename + ".xlsx";
    try {
        FileOutputStream fileOut = new FileOutputStream(fileName);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet worksheet = workbook.createSheet("POI Worksheet");

        int lastvaluex = matrice.length;
        int lastvaluey = 1;
        int ih = 0;
        int jh = 0;

        while (ih < lastvaluex) {
            XSSFRow row = worksheet.createRow(ih);

            while (jh < lastvaluey) {
                XSSFCell cell = row.createCell(jh);
                cell.setCellValue(matrice[ih]);
                jh++;
            }
            ih++;
            jh = 0;
        }
        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:edu.cmu.emfta.actions.CutSet.java

License:Open Source License

public XSSFWorkbook toSingleSheetWorkbook() {
    XSSFWorkbook workbook = new XSSFWorkbook();
    int cutSetIdentifier = 0;
    double cutsetProbability;

    XSSFSheet sheet = workbook.createSheet();

    XSSFTable table = sheet.createTable();
    table.setDisplayName("Cutsets");
    CTTable cttable = table.getCTTable();

    // Set which area the table should be placed in
    AreaReference reference = new AreaReference(new CellReference(0, 0), new CellReference(2, 2));
    cttable.setRef(reference.formatAsString());
    cttable.setId((long) 1);
    cttable.setName("Cutsets");
    cttable.setTotalsRowCount((long) 1);

    CTTableColumns columns = cttable.addNewTableColumns();
    columns.setCount((long) 3);
    CTTableColumn column;//from  w w w. j av a  2s . com
    XSSFRow row;
    XSSFCell cell;

    column = columns.addNewTableColumn();

    // Create row
    row = sheet.createRow(0);
    CellStyle headingCellStyle = workbook.createCellStyle();
    XSSFFont headingFont = workbook.createFont();
    headingFont.setBold(true);
    headingCellStyle.setFont(headingFont);
    row.setRowStyle(headingCellStyle);

    CellStyle normalCellStyle = workbook.createCellStyle();
    XSSFFont normalFont = workbook.createFont();
    normalFont.setBold(false);
    normalCellStyle.setFont(normalFont);

    for (int j = 0; j < 3; j++) {
        // Create cell
        cell = row.createCell(j);

        switch (j) {
        case 0: {
            cell.setCellValue("Identifier");
            break;
        }
        case 1: {
            cell.setCellValue("Description");
            break;
        }
        case 2: {
            cell.setCellValue("Probability");
            break;
        }

        }
    }

    int rowId = 1;

    for (List<Event> events : cutset) {
        row = sheet.createRow(rowId++);
        row = sheet.createRow(rowId++);
        row.setRowStyle(normalCellStyle);

        cell = row.createCell(0);
        cell.setCellValue("Cutset #" + cutSetIdentifier);

        cutsetProbability = 1;
        for (int i = 0; i < events.size(); i++) {
            cutsetProbability = cutsetProbability * events.get(i).getProbability();
        }

        cell = row.createCell(2);
        if (cutsetProbability != 1) {
            cell.setCellValue("" + cutsetProbability);
        } else {
            cell.setCellValue("" + cutsetProbability);
        }
        //         System.out.println("[CutSet] cutset id=" + cutSetIdentifier);

        for (int i = 0; i < events.size(); i++) {
            Event e = events.get(i);

            //            System.out.println("[CutSet] event name=" + e.getName());

            // Create row
            row = sheet.createRow(rowId++);
            row.setRowStyle(normalCellStyle);
            for (int j = 0; j < 3; j++) {
                // Create cell
                cell = row.createCell(j);

                switch (j) {
                case 0: {
                    cell.setCellValue(e.getName());
                    break;
                }
                case 1: {
                    cell.setCellValue(e.getDescription());
                    break;
                }
                case 2: {
                    cell.setCellValue(e.getProbability());
                    break;
                }

                }
            }
        }
        cutSetIdentifier = cutSetIdentifier + 1;
    }

    return workbook;

}

From source file:edu.cmu.emfta.actions.CutSet.java

License:Open Source License

public XSSFWorkbook toMultiSheetsWorkbook() {
    XSSFWorkbook workbook = new XSSFWorkbook();
    int cutSetIdentifier = 0;
    double cutsetProbability;

    for (List<Event> events : cutset) {

        cutsetProbability = 1;/*from  w ww  .  j a  v  a  2s  .c o  m*/
        for (int i = 0; i < events.size(); i++) {
            cutsetProbability = cutsetProbability * events.get(i).getProbability();
        }

        //         System.out.println("[CutSet] cutset id=" + cutSetIdentifier);
        XSSFSheet sheet = workbook.createSheet();

        XSSFTable table = sheet.createTable();
        table.setDisplayName("Cutset");
        CTTable cttable = table.getCTTable();

        // Set which area the table should be placed in
        AreaReference reference = new AreaReference(new CellReference(0, 0), new CellReference(2, 2));
        cttable.setRef(reference.formatAsString());
        cttable.setId((long) 1);
        cttable.setName("Cutset " + cutSetIdentifier);
        cttable.setTotalsRowCount((long) 1);

        CTTableColumns columns = cttable.addNewTableColumns();
        columns.setCount((long) 3);
        CTTableColumn column;
        XSSFRow row;
        XSSFCell cell;

        column = columns.addNewTableColumn();

        // Create row
        row = sheet.createRow(0);
        CellStyle headingCellStyle = workbook.createCellStyle();
        XSSFFont headingFont = workbook.createFont();
        headingFont.setBold(true);
        headingCellStyle.setFont(headingFont);
        row.setRowStyle(headingCellStyle);

        CellStyle normalCellStyle = workbook.createCellStyle();
        XSSFFont normalFont = workbook.createFont();
        normalFont.setBold(false);
        normalCellStyle.setFont(normalFont);

        for (int j = 0; j < 3; j++) {
            // Create cell
            cell = row.createCell(j);

            switch (j) {
            case 0: {
                cell.setCellValue("Identifier");
                break;
            }
            case 1: {
                cell.setCellValue("Description");
                break;
            }
            case 2: {
                if (cutsetProbability == 1) {
                    cell.setCellValue("Probability");
                } else {
                    cell.setCellValue("Probability (" + cutsetProbability + ")");
                }
                break;
            }

            }
        }

        for (int i = 0; i < events.size(); i++) {
            Event e = events.get(i);

            System.out.println("[CutSet] event name=" + e.getName());
            // Create column
            column = columns.addNewTableColumn();
            column.setName("Column");
            column.setId((long) i + 1);
            // Create row
            row = sheet.createRow(i + 1);
            row.setRowStyle(normalCellStyle);
            for (int j = 0; j < 3; j++) {
                // Create cell
                cell = row.createCell(j);

                switch (j) {
                case 0: {
                    cell.setCellValue(e.getName());
                    break;
                }
                case 1: {
                    cell.setCellValue(e.getDescription());
                    break;
                }
                case 2: {
                    cell.setCellValue(e.getProbability());
                    break;
                }

                }
            }
        }
        cutSetIdentifier = cutSetIdentifier + 1;
    }

    return workbook;

}

From source file:egovframework.rte.fdl.excel.util.AbstractPOIExcelView.java

License:Apache License

/**
 * Convenient method to set a String as text content in a cell.
 * //from   w w  w  .  j a v a  2 s . co m
 * @param cell the cell in which the text must be put
 * @param text the text to put in the cell
 */
protected void setText(XSSFCell cell, String text) {
    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
    cell.setCellValue(text);
}

From source file:es.SSII2.manager.ExcelManagerAccount.java

public void actualizarCuentas(ArrayList<String> cuentas, ArrayList<String> cuentasCorrectas,
        ArrayList<String> arrayIban, ArrayList<String> pos) throws IOException, ParseException {

    int row, col;
    String originalCuenta, nuevaCuenta, iban, posicion, entidad, oficina, dc, numCuenta;
    String[] a;/*w  ww .j a v a  2s  .  c  om*/

    FileInputStream file;
    file = new FileInputStream(new File(excel));

    FileOutputStream outFile;

    XSSFWorkbook workbook = new XSSFWorkbook(file);
    XSSFSheet sheet = workbook.getSheetAt(0);
    XSSFRow rowIban;
    XSSFCell cellIban;
    Cell cellCuenta;

    //sacar las cuentas
    for (int i = 0; i < cuentas.size(); i++) {

        originalCuenta = cuentas.get(i);//se coje la cuenta original
        nuevaCuenta = cuentasCorrectas.get(i);//se coje la cuenta actualizada   
        iban = arrayIban.get(i);// cojer el iban

        posicion = pos.get(i);//se coje la posicion
        a = posicion.split("-");//split del string "1-3" de las posiciones que estan el el arraylist
        row = Integer.parseInt(a[0]);//fila "1"
        col = Integer.parseInt(a[1]);//columna "3"

        //insertar el iban
        rowIban = sheet.getRow(row);//coje la fila
        cellIban = rowIban.createCell(1 + col);//crea la celda
        cellIban.setCellValue(iban);

        //2096 0056 16 3231500000
        entidad = nuevaCuenta.substring(0, 4);
        oficina = nuevaCuenta.substring(4, 8);
        dc = nuevaCuenta.substring(8, 10);
        numCuenta = nuevaCuenta.substring(10);

        //actualizar la cuenta si esta mal el cc
        if (!originalCuenta.equals(nuevaCuenta)) {

            cellCuenta = sheet.getRow(row).getCell(col); //obtiene la fila y columna
            DecimalFormat df = new DecimalFormat("#");
            Number cuenta = df.parse(nuevaCuenta);
            cellCuenta.setCellValue(cuenta.doubleValue());

            System.out.println(
                    "Cuenta actualizada: " + iban + "-" + entidad + "-" + oficina + "-" + dc + "-" + numCuenta);

        } else {

            System.out.println(
                    "Cuenta correcta:    " + iban + "-" + entidad + "-" + oficina + "-" + dc + "-" + numCuenta);

        }

    } //for

    outFile = new FileOutputStream(new File(excel));
    //escribe en el excel
    workbook.write(outFile);
    outFile.close();

    file.close();//cierra el archivo  

}

From source file:es.SSII2.manager.ExcelManagerMail.java

public void actualizarDnis() throws IOException {

    int row;//from   ww  w  . j  a  v  a2  s  .  c  om
    int col = 15;

    FileInputStream file;
    file = new FileInputStream(new File(excel));

    XSSFWorkbook workbook = new XSSFWorkbook(file);
    XSSFSheet sheet = workbook.getSheetAt(0);

    for (int i = 0; i < arrayWorkers.size(); i++) {

        row = i;
        XSSFRow rowEmail = sheet.getRow(row + 1); //coje la fila
        XSSFCell cellEmail = rowEmail.createCell(col); //crea la celda
        cellEmail.setCellValue(arrayWorkers.get(i).getEmail());

        //escribe en el excel
        try (FileOutputStream outFile = new FileOutputStream(new File(excel))) {
            workbook.write(outFile);

        }

    } //for
}

From source file:es.upm.oeg.tools.rdfshapes.libdemo.ApachePoiDemo.java

License:Apache License

public static void main(String[] args) throws Exception {

    String filename = "test.xls";

    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet("Cardinality");

    //iterating r number of rows
    for (int r = 0; r < 5; r++) {
        XSSFRow row = sheet.createRow(r);

        //iterating c number of columns
        for (int c = 0; c < 5; c++) {
            XSSFCell cell = row.createCell(c);

            cell.setCellValue("Cell " + r + " " + c);
        }/*from  w w  w  . j  ava  2s . c  o m*/
    }

    FileOutputStream fileOut = new FileOutputStream(filename);
    wb.write(fileOut);
    fileOut.close();

}