List of usage examples for org.apache.poi.ss.usermodel Row createCell
Cell createCell(int column, CellType type);
From source file:ar.edu.unrc.gametictactoe.performanceandtraining.configurations.StatisticExperiment.java
License:Open Source License
/** * * @param filePath//from w w w. j av a2 s .c o m * @param backupFiles * @param resultsPerFile * @param resultsRandom * @param randomPerceptronFile <p> * @throws IOException * @throws InvalidFormatException */ public void exportToExcel(String filePath, List<File> backupFiles, Map<File, StatisticForCalc> resultsPerFile, Map<File, StatisticForCalc> resultsRandom, File randomPerceptronFile) throws IOException, InvalidFormatException { InputStream inputXLSX = this.getClass() .getResourceAsStream("/ar/edu/unrc/gametictactoe/resources/EstadisticasTicTacToe.xlsx"); Workbook wb = WorkbookFactory.create(inputXLSX); try (FileOutputStream outputXLSX = new FileOutputStream( filePath + "_" + dateFormater.format(dateForFileName) + "_STATISTICS" + ".xlsx")) { //============= imptimimos en la hoja de % Of Games Won =================== Sheet sheet = wb.getSheetAt(0); //Estilo par los titulos de las tablas int rowStartTitle = 0; int colStartTitle = 2; int rowStart = 1; int colStart = 3; Row rowPlayer1; Row rowPlayer2; Row rowDraw; // Luego creamos el objeto que se encargar de aplicar el estilo a la celda Font fontCellTitle = wb.createFont(); fontCellTitle.setFontHeightInPoints((short) 10); fontCellTitle.setFontName("Arial"); fontCellTitle.setBoldweight(Font.BOLDWEIGHT_BOLD); CellStyle CellStyleTitle = wb.createCellStyle(); CellStyleTitle.setWrapText(true); CellStyleTitle.setAlignment(CellStyle.ALIGN_CENTER); CellStyleTitle.setVerticalAlignment(CellStyle.VERTICAL_TOP); CellStyleTitle.setFont(fontCellTitle); // Establecemos el tipo de sombreado de nuestra celda CellStyleTitle.setFillBackgroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); CellStyleTitle.setFillPattern(CellStyle.SOLID_FOREGROUND); loadTitle(rowStartTitle, colStartTitle, sheet, backupFiles.size(), CellStyleTitle); //estilo titulo finalizado //Estilo de celdas con los valores de las estadisticas CellStyle cellStyle = wb.createCellStyle(); cellStyle.setWrapText(true); /* We are now ready to set borders for this style */ /* Draw a thin left border */ cellStyle.setBorderLeft(CellStyle.BORDER_THIN); /* Add medium right border */ cellStyle.setBorderRight(CellStyle.BORDER_THIN); /* Add dashed top border */ cellStyle.setBorderTop(CellStyle.BORDER_THIN); /* Add dotted bottom border */ cellStyle.setBorderBottom(CellStyle.BORDER_THIN); //estilo celdas finalizado //loadTitle(rowStartTitle, colStartTitle, sheet, backupFiles.size(), CellStyleTitle); rowPlayer1 = sheet.getRow(rowStart); rowPlayer2 = sheet.getRow(rowStart + 1); rowDraw = sheet.getRow(rowStart + 2); for (int file = 0; file < backupFiles.size(); file++) { Cell cellPlayer1 = rowPlayer1.createCell(file + colStart, Cell.CELL_TYPE_NUMERIC); Cell cellPlayer2 = rowPlayer2.createCell(file + colStart, Cell.CELL_TYPE_NUMERIC); Cell cellDraw = rowDraw.createCell(file + colStart, Cell.CELL_TYPE_NUMERIC); cellPlayer1.setCellStyle(cellStyle); cellPlayer2.setCellStyle(cellStyle); cellDraw.setCellStyle(cellStyle); Double cellValuePlayer1 = resultsPerFile.get(backupFiles.get(file)).getWinRatePlayer1(); Double cellValuePlayer2 = resultsPerFile.get(backupFiles.get(file)).getWinRatePlayer2(); Double cellValueDraw = resultsPerFile.get(backupFiles.get(file)).getDrawRate(); assert cellValuePlayer1 <= 100 && cellValuePlayer1 >= 0; assert cellValuePlayer2 <= 100 && cellValuePlayer2 >= 0; assert cellValueDraw <= 100 && cellValueDraw >= 0; //assert cellValueDraw + cellValuePlayer1 + cellValuePlayer2 == 100; cellDraw.setCellValue(cellValueDraw); cellPlayer1.setCellValue(cellValuePlayer1); cellPlayer2.setCellValue(cellValuePlayer2); } if (!resultsRandom.isEmpty()) { int file = 0;//hay que ir a buscar el randomfile Cell cellDraw = rowDraw.createCell(file + colStart - 1, Cell.CELL_TYPE_NUMERIC); Cell cellPlayer1 = rowPlayer1.createCell(file + colStart - 1, Cell.CELL_TYPE_NUMERIC); Cell cellPlayer2 = rowPlayer2.createCell(file + colStart - 1, Cell.CELL_TYPE_NUMERIC); cellDraw.setCellStyle(cellStyle); cellPlayer1.setCellStyle(cellStyle); cellPlayer2.setCellStyle(cellStyle); // StatisticForCalc get = resultsRandom.get(randomPerceptronFile); // Double cellValuePlayer1 = get.getWinRatePlayer1(); Double cellValuePlayer1 = resultsRandom.get(randomPerceptronFile).getWinRatePlayer1(); Double cellValuePlayer2 = resultsRandom.get(randomPerceptronFile).getWinRatePlayer2(); Double cellValueDraw = resultsRandom.get(randomPerceptronFile).getDrawRate(); //assert cellValueDraw + cellValuePlayer1 + cellValuePlayer2 == 100; cellPlayer1.setCellValue(cellValuePlayer1); cellPlayer2.setCellValue(cellValuePlayer2); cellDraw.setCellValue(cellValueDraw); } wb.write(outputXLSX); } }
From source file:ar.edu.unrc.gametictactoe.performanceandtraining.configurations.StatisticExperiment.java
License:Open Source License
/** * * @param rowStartTitle//from ww w . j a v a 2 s. c o m * @param colStartTitle * @param sheet * @param backupFilesSize * @param CellStyleTitle */ public void loadTitle(int rowStartTitle, int colStartTitle, Sheet sheet, int backupFilesSize, CellStyle CellStyleTitle) { int total_juegos = saveBackupEvery; Row row1 = sheet.getRow(rowStartTitle); for (int file = 1; file <= backupFilesSize; file++) { Cell cell = row1.createCell(file + colStartTitle, Cell.CELL_TYPE_NUMERIC); cell.setCellStyle(CellStyleTitle); Integer value = total_juegos * file; String valueStr = value.toString(); String cellV = valueStr; if (valueStr.length() > 3) { cellV = valueStr.substring(0, valueStr.length() - 3) + "K"; } cell.setCellValue(cellV); } }
From source file:bad.robot.excel.cell.BlankCell.java
License:Apache License
@Override public void addTo(Row row, ColumnIndex column, Workbook workbook) { Cell cell = row.createCell(column.value(), CELL_TYPE_BLANK); this.getStyle().applyTo(cell, workbook); }
From source file:bad.robot.excel.cell.BooleanCell.java
License:Apache License
@Override public void addTo(Row row, ColumnIndex column, Workbook workbook) { org.apache.poi.ss.usermodel.Cell cell = row.createCell(column.value(), CELL_TYPE_BOOLEAN); update(cell, workbook);/*from ww w.ja v a 2s . c om*/ }
From source file:bad.robot.excel.cell.DateCell.java
License:Apache License
@Override public void addTo(Row row, ColumnIndex column, Workbook workbook) { org.apache.poi.ss.usermodel.Cell cell = row.createCell(column.value(), CELL_TYPE_NUMERIC); update(cell, workbook);// w w w. j av a 2 s . c o m }
From source file:bad.robot.excel.cell.ErrorCell.java
License:Apache License
@Override public void addTo(Row row, ColumnIndex column, Workbook workbook) { org.apache.poi.ss.usermodel.Cell cell = row.createCell(column.value(), CELL_TYPE_ERROR); update(cell, workbook);/*w ww .ja v a 2 s.co m*/ }
From source file:bad.robot.excel.cell.FormulaCell.java
License:Apache License
@Override public void addTo(Row row, ColumnIndex column, Workbook workbook) { org.apache.poi.ss.usermodel.Cell cell = row.createCell(column.value(), CELL_TYPE_FORMULA); update(cell, workbook);/*w w w . j ava 2s .c o m*/ }
From source file:bad.robot.excel.cell.HyperlinkCell.java
License:Apache License
@Override public void addTo(Row row, ColumnIndex column, Workbook workbook) { org.apache.poi.ss.usermodel.Cell cell = row.createCell(column.value(), CELL_TYPE_STRING); update(cell, workbook);/* w ww . jav a2 s . com*/ }
From source file:cn.afterturn.easypoi.util.PoiSheetUtil.java
License:Apache License
/** * Given a sheet, this method deletes a column from a sheet and moves * all the columns to the right of it to the left one cell. * // www.ja v a 2s .c o m * Note, this method will not update any formula references. * * @param sheet * @param columnToDelete */ public static void deleteColumn(Sheet sheet, int columnToDelete) { int maxColumn = 0; for (int r = 0; r < sheet.getLastRowNum() + 1; r++) { Row row = sheet.getRow(r); // if no row exists here; then nothing to do; next! if (row == null) { continue; } // if the row doesn't have this many columns then we are good; next! int lastColumn = row.getLastCellNum(); if (lastColumn > maxColumn) { maxColumn = lastColumn; } if (lastColumn < columnToDelete) { continue; } for (int x = columnToDelete + 1; x < lastColumn + 1; x++) { Cell oldCell = row.getCell(x - 1); if (oldCell != null) { row.removeCell(oldCell); } Cell nextCell = row.getCell(x); if (nextCell != null) { Cell newCell = row.createCell(x - 1, nextCell.getCellType()); cloneCell(newCell, nextCell); } } } // Adjust the column widths for (int c = columnToDelete; c < maxColumn; c++) { sheet.setColumnWidth(c, sheet.getColumnWidth(c + 1)); } }
From source file:cn.edu.zjnu.acm.judge.util.excel.ExcelUtil.java
License:Apache License
private static void create(Stream<?> stream, Row row) { AtomicInteger counter = new AtomicInteger(); stream.forEach(value -> {/*from ww w . j av a 2 s. c o m*/ if (value != null) { if (value instanceof String) { row.createCell(counter.getAndIncrement(), CellType.STRING).setCellValue((String) value); } else if (value instanceof Number) { row.createCell(counter.getAndIncrement(), CellType.NUMERIC) .setCellValue(((Number) value).doubleValue()); } else if (value instanceof Boolean) { row.createCell(counter.getAndIncrement(), CellType.BOOLEAN).setCellValue((Boolean) value); } else if (value instanceof Date) { row.createCell(counter.getAndIncrement(), CellType.NUMERIC).setCellValue((Date) value); } else if (value instanceof Calendar) { row.createCell(counter.getAndIncrement(), CellType.NUMERIC).setCellValue((Calendar) value); } else { row.createCell(counter.getAndIncrement(), CellType.ERROR); } } else { row.createCell(counter.getAndIncrement(), CellType.BLANK); } }); }