List of usage examples for org.apache.poi.xssf.usermodel XSSFFont setFontHeightInPoints
public void setFontHeightInPoints(short height)
From source file:tools.IOHelper.java
public static void plate2ResultSheet(ANAPlate plate, File outputFolder) throws IOException { File outputFile = new File(outputFolder, plate.getPlateId() + "_" + TIME + ".xlsx"); Workbook excelFile = null;/*from w ww. j a v a2 s. c o m*/ if (outputFile.exists()) { outputFile.delete(); } outputFile.createNewFile(); excelFile = new XSSFWorkbook(); if (excelFile == null) { throw new RuntimeException("fail to create the xlsx file"); } int rowCount = plate.getSampleNumber(); //not including the 2 control samples + "_"+time String sheetName = plate.getPlateId(); //create a working sheet Sheet sheet = excelFile.createSheet(sheetName); //starting row & col int rowIndex = 0; int colIndex = 0; int totalCol = 0; int pos = 0, neg = 0, all = 0; XSSFFont fontTitle = (XSSFFont) excelFile.createFont(); fontTitle.setFontHeightInPoints((short) 10); fontTitle.setFontName("Arial"); fontTitle.setColor(IndexedColors.GREEN.getIndex()); fontTitle.setBold(true); fontTitle.setItalic(false); XSSFCellStyle styleTitle = (XSSFCellStyle) excelFile.createCellStyle(); styleTitle.setAlignment(CellStyle.ALIGN_CENTER); styleTitle.setFont(fontTitle); Cell cell0 = sheet.createRow(rowIndex++).createCell(0); cell0.setCellValue(plate.getPlateId() + " Summary"); //title cell0.setCellStyle(styleTitle); // //optional set Cell Style // CellStyle styleTitle = null; // CellStyle style = null; // add column:Sample,Chip Location,Signal,Positivity,sample titer,plate titer, pattern, No of Cells, enableWatershed,comment Row row = sheet.createRow(rowIndex++); //names Cell column = row.createCell(colIndex++); column.setCellValue("Sample ID"); totalCol++; column = row.createCell(colIndex++); column.setCellValue("Chip Location"); totalCol++; column = row.createCell(colIndex++); column.setCellValue("Signal"); totalCol++; column = row.createCell(colIndex++); column.setCellValue("Positivity"); totalCol++; column = row.createCell(colIndex++); column.setCellValue("Sample Titer"); totalCol++; column = row.createCell(colIndex++); column.setCellValue("Plate Titer"); totalCol++; column = row.createCell(colIndex++); column.setCellValue("Pattern"); totalCol++; column = row.createCell(colIndex++); column.setCellValue("Number of Cells"); totalCol++; column = row.createCell(colIndex++); column.setCellValue("Comments"); totalCol++; for (ANATestResult result : plate.getTestResultList()) { row = sheet.createRow(rowIndex++); //data colIndex = 0; column = row.createCell(colIndex++); column.setCellValue(result.getJulien_barcode()); column = row.createCell(colIndex++); column.setCellValue(result.getPillarPosition()); column = row.createCell(colIndex++); column.setCellValue(result.getSecondPlateSignal()); column = row.createCell(colIndex++); if (result.getPositivity() == null) { column.setCellValue("Null Result"); } else { if (ANA_Result.POSITIVE.equals(result.getPositivity())) { pos++; } else if (ANA_Result.NEGATIVE.equals(result.getPositivity())) { neg++; } all++; column.setCellValue(result.getPositivity().name()); } //make sure all fis has not-null pn result column = row.createCell(colIndex++); if (result.getTiter() != null) { column.setCellValue(result.getTiter().name()); } column = row.createCell(colIndex++); if (plate.getPosCtrl().getTiter() != null) { column.setCellValue(plate.getPosCtrl().getTiter().name()); } //pattern, No of Cells, enableWatershed,comment column = row.createCell(colIndex++); if (result.getPattern() != null) { column.setCellValue(result.getPattern().name()); } column = row.createCell(colIndex++); column.setCellValue(result.cellCount()); column = row.createCell(colIndex++); //warning msg concat mthd; merge plateErr to sampErr column.setCellValue(result.concatWarningMsgs()); } if (rowIndex - rowCount == 2) { for (int i = 0; i < totalCol; i++) { sheet.autoSizeColumn(i); } } else { System.out .println((rowIndex - 2) + " records are writen into file while " + rowCount + " are expected"); } row = sheet.createRow(rowIndex++); //total colIndex = 0; column = row.createCell(colIndex++); column.setCellValue("all samples"); column = row.createCell(colIndex++); column.setCellValue(all); column = row.createCell(colIndex++); column.setCellValue("positive samples"); column = row.createCell(colIndex++); column.setCellValue(pos); column = row.createCell(colIndex++); column.setCellValue("negative samples"); column = row.createCell(colIndex++); column.setCellValue(neg); FileOutputStream fos = null; try { fos = new FileOutputStream(outputFile.getAbsolutePath());//,true excelFile.write(fos); } catch (FileNotFoundException ex) { Logger.getLogger(IOHelper.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(IOHelper.class.getName()).log(Level.SEVERE, null, ex); } finally { if (fos != null) { try { fos.close(); } catch (IOException ex) { Logger.getLogger(IOHelper.class.getName()).log(Level.SEVERE, null, ex); } } } }