List of usage examples for org.apache.poi.xssf.usermodel XSSFFont setFontName
public void setFontName(String name)
From source file:se.inera.intyg.rehabstod.service.export.xlsx.XlsxExportServiceImpl.java
License:Open Source License
private XSSFFont buildFont(XSSFWorkbook wb, int heightInPoints, String fontName, boolean bold, boolean underline) { XSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) heightInPoints); font.setFontName(fontName); font.setColor(IndexedColors.BLACK.getIndex()); font.setBold(bold);//from ww w.j ava2s. co m font.setBoldweight(bold ? Font.BOLDWEIGHT_BOLD : Font.BOLDWEIGHT_NORMAL); font.setUnderline(underline ? XSSFFont.U_SINGLE : XSSFFont.U_NONE); return font; }
From source file:se.minstrel.tools.xssfbuilder.style.impl.StyleBuilderImpl.java
License:Open Source License
private XSSFCellStyle buildStyle() { XSSFWorkbook wb = support.getWorkbook(); XSSFFont font = wb.createFont(); font.setFontName(style.getFont()); font.setFontHeightInPoints(style.getFontSize()); font.setBold(style.isBold());/* w ww . jav a 2s .c o m*/ font.setItalic(style.isItalics()); if (style.getFgColor() != null) { font.setColor(new XSSFColor(style.getFgColor())); } XSSFCellStyle cs = support.getWorkbook().createCellStyle(); cs.setFont(font); if (style.getBgColor() != null) { cs.setFillForegroundColor(new XSSFColor(style.getBgColor())); cs.setFillPattern(FillPatternType.SOLID_FOREGROUND); } if (style.getFormat() != null) { cs.setDataFormat(support.getDataFormat().getFormat(style.getFormat())); } // style.getBgColor(); // style.getFgColor(); // style.isBold(); // style.isItalics(); return cs; }
From source file:step.datapool.excel.StyleSyntax.java
License:Open Source License
/** * Analysiert den angegebenen Stil und setzt diesen excel-konform. * /* www .ja v a 2s . com*/ * @param strStyle strStyle * @param _wb _wb * @return XSSFCellStyle */ public static XSSFCellStyle composeStyle(String strStyle, Workbook _wb) { if (_wb instanceof XSSFWorkbook) { XSSFWorkbook wb = (XSSFWorkbook) _wb; if (strStyle == null || strStyle.isEmpty()) return null; XSSFCellStyle style = wb.createCellStyle(); XSSFFont font = wb.createFont(); strStyle = replaceColors(strStyle); /* Unterteilung der verschiedenen Stilangaben: Schriftschnitt, Vordergrund/Hintergrundfarbe, Schriftgroesse, Schriftsatz */ String[] arr = strStyle.split(","); for (String str : arr) { /* Abhandlung des Schriftschnitts. Diese koennen alle zusammen auftreten und schliessen sich nicht aus */ if (str.matches("( *bold *| *italic *| *underline *| *strikeout *)*")) { if (str.contains("bold")) { font.setBoldweight(Font.BOLDWEIGHT_BOLD); } if (str.contains("italic")) { font.setItalic(true); } if (str.contains("underline")) { font.setUnderline(Font.U_SINGLE); } if (str.contains("strikeout")) { font.setStrikeout(true); } continue; } /* Abhandlung der Farben */ if (str.contains("/") && !str.contains(":")) { continue; } if (str.contains(":")) { String[] fgBg; /* Vordergrund / Hintergrund */ if (str.contains("/")) { fgBg = str.split("/"); } else { /* Verkuerzte Angabe ohne / (nur Vordergrund) */ fgBg = new String[1]; fgBg[0] = str; } for (int i = 0; i < fgBg.length; i++) { fgBg[i] = fgBg[i].trim(); if (!fgBg[i].isEmpty()) { String[] clr = fgBg[i].split(":"); if (clr.length != 3) { return null; } int red = Integer.parseInt(clr[0].trim()); int green = Integer.parseInt(clr[1].trim()); int blue = Integer.parseInt(clr[2].trim()); if (i == 0) { /* Schriftfarbe * ------------------------------------------------------------- * | ACHTUNG: poi hat einen Fehler beim Setzen der Schriftfarbe! | * ------------------------------------------------------------- * Weiss und Schwarz sind verwechselt worden! Gilt NUR fuer * font.setColor! * Deshalb wird hier einfach Weiss auf Schwarz korrigiert und * umgekehrt. */ if (red == 0 && green == 0 && blue == 0) { red = 255; green = 255; blue = 255; } else if (red == 255 && green == 255 && blue == 255) { red = 0; green = 0; blue = 0; } XSSFColor xssfColor = new XSSFColor(new Color(red, green, blue)); font.setColor(xssfColor); } else { // Vordergrund/Hintergrundfarbe der Zelle XSSFColor xssfColor = new XSSFColor(new Color(red, green, blue)); style.setFillForegroundColor(xssfColor); style.setFillBackgroundColor(xssfColor); style.setFillPattern(CellStyle.SOLID_FOREGROUND); } } } continue; } /* Abhandlung der Schriftgroesse */ if (str.matches(" *[1-9][0-9]* *")) { short fontHeightInPoints = Short.parseShort(str.trim()); font.setFontHeightInPoints(fontHeightInPoints); continue; } /* Abhandlung der Schriftart */ if (!str.isEmpty()) { font.setFontName(str); continue; } } style.setFont(font); return style; } else { return null; } }
From source file:tools.IOHelper.java
public static void plate1ResultSheet(ANAPlate plate, File outputFolder) throws IOException { File outputFile = new File(outputFolder, plate.getPlateId() + "_" + TIME + ".xlsx"); Workbook excelFile = null;/*from w w w . j ava 2 s .c om*/ // if (outputFile.exists()) { // try { // excelFile = WorkbookFactory.create(outputFile); // } catch (EncryptedDocumentException ex) { // System.out.println("file with assigned name already exists but is encrypted..."); // Logger.getLogger(IOHelper.class.getName()).log(Level.SEVERE, null, ex); // } catch (InvalidFormatException ex) { // Logger.getLogger(IOHelper.class.getName()).log(Level.SEVERE, null, ex); // } // } else { // outputFile.createNewFile(); // excelFile = new XSSFWorkbook(); // } 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; 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("Result"); totalCol++; // column = row.createCell(colIndex++); // column.setCellValue("Positivity 0.3P"); // totalCol++; // column = row.createCell(colIndex++); // column.setCellValue("Positivity0.275P+0.5N"); // totalCol++; column = row.createCell(colIndex++); column.setCellValue("Signal"); 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++); 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.positivity30 == null) { // column.setCellValue("Null Result"); // } else { // if (ANA_Result.POSITIVE.equals(result.positivity30)) { //// pos++; // } else if (ANA_Result.NEGATIVE.equals(result.positivity30)) { //// neg++; // } //// all++; // column.setCellValue(result.positivity30.name()); // } //make sure all fis has not-null pn result // column = row.createCell(colIndex++); // if (result.positivityCombined == null) { // column.setCellValue("Null Result"); // } else { // if (ANA_Result.POSITIVE.equals(result.positivityCombined)) { //// pos++; // } else if (ANA_Result.NEGATIVE.equals(result.positivityCombined)) { //// neg++; // } //// all++; // column.setCellValue(result.positivityCombined.name()); // } //make sure all fis has not-null pn result column = row.createCell(colIndex++); column.setCellValue(result.getFirstPlateSignal()); // if(result.getFirstPlateSignal()<0){ // column.setCellValue("ROI exception: unable to get signal for this sample"); // }else{ // column.setCellValue(result.getFirstPlateSignal()); // } 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); column = row.createCell(colIndex++); column = row.createCell(colIndex++); column = row.createCell(colIndex++); column.setCellValue("PosCtrl"); column = row.createCell(colIndex++); column.setCellValue(plate.getPosCtrl().getFirstPlateSignal()); column = row.createCell(colIndex++); column.setCellValue("NegCtrl"); column = row.createCell(colIndex++); column.setCellValue(plate.getNegCtrlSignal()); 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); } } } }
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 w w . ja v a 2s. co 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); } } } }