List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle setFont
@Override public void setFont(Font font)
From source file:rpt.GUI.ProgramStrategist.CyclePlans.CompareDialogController.java
private int writeRow(Workbook wb, Sheet sheet, Row row, TableVariant variant, Map<String, Map<String, String>> diffList, Boolean colorChanges, Boolean addOldSOP) { //Used for placing comment at the right position CreationHelper factory = wb.getCreationHelper(); Drawing drawing = sheet.createDrawingPatriarch(); ClientAnchor anchor = factory.createClientAnchor(); //Create new style XSSFCellStyle styleRed = (XSSFCellStyle) wb.createCellStyle(); XSSFCellStyle styleBlack = (XSSFCellStyle) wb.createCellStyle(); XSSFFont fontRed = (XSSFFont) wb.createFont(); fontRed.setColor(new XSSFColor(new java.awt.Color(255, 0, 0))); XSSFFont fontBlack = (XSSFFont) wb.createFont(); fontBlack.setColor(new XSSFColor(new java.awt.Color(0, 0, 0))); styleRed.setFont(fontRed); styleBlack.setFont(fontBlack);//from ww w . j a v a2 s .c om //xEtract differences to highlight Map<String, String> differences; if (diffList != null) { differences = diffList.get(variant.getVariantID()); } else { differences = new HashMap<String, String>(); } //Start with column 0 int cols = 0; //Create string with columns to print String[] columns = { "Plant", "Platform", "Vehicle", "Propulsion", "Denomination", "Fuel", "EngineFamily", "Generation", "EngineCode", "Displacement", "EnginePower", "ElMotorPower", "Torque", "TorqueOverBoost", "GearboxType", "Gears", "Gearbox", "Driveline", "TransmissionCode", "CertGroup", "EmissionClass", "StartOfProd", "EndOfProd" }; Cell cell; for (int i = 0; i < columns.length; i++) { cell = row.createCell(i); if (differences.containsKey(columns[i])) { cell.setCellStyle(styleRed); // position the comment anchor.setCol1(cell.getColumnIndex()); anchor.setCol2(cell.getColumnIndex() + 1); anchor.setRow1(row.getRowNum()); anchor.setRow2(row.getRowNum() + 3); // Create the comment and set the text+author Comment comment = drawing.createCellComment(anchor); RichTextString str = factory.createRichTextString(differences.get(columns[i])); comment.setString(str); comment.setAuthor("RPT"); // Assign the comment to the cell cell.setCellComment(comment); } else { cell.setCellStyle(styleBlack); } cell.setCellValue(variant.getValue(columns[i])); cols++; } if (addOldSOP) { cell = row.createCell(23); cell.setCellValue(variant.getOldSOP()); cols++; } if (addOldSOP) { cell = row.createCell(24); cell.setCellValue(variant.getOldEOP()); cols++; } return cols; }
From source file:ru.jeene.zapretparser.controller.XLSXReportController.java
public void WriteReport(FullReport rep, String timestamp_csv) { try (FileInputStream inp = new FileInputStream(shab_name)) { XSSFWorkbook wb = new XSSFWorkbook(inp); // Declare XSSF WorkBook XSSFSheet sheet = wb.getSheet(" "); XSSFCellStyle cs1 = wb.createCellStyle(); //cs1.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); cs1.setBorderBottom(XSSFCellStyle.BORDER_THIN); cs1.setBorderTop(XSSFCellStyle.BORDER_THIN); cs1.setBorderRight(XSSFCellStyle.BORDER_THIN); cs1.setBorderLeft(XSSFCellStyle.BORDER_THIN); cs1.setAlignment(XSSFCellStyle.ALIGN_CENTER); cs1.setWrapText(true);//from w w w. j a va 2 s . co m cs1.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); XSSFFont f = wb.createFont(); f.setBold(false); f.setFontName("Times New Roman"); f.setFontHeightInPoints((short) 14); cs1.setFont(f); int cnt = 0; XSSFRow row; XSSFCell cell; for (Model_FullReport m : rep.getList()) { int cnt_cell = 0; row = sheet.getRow(t1_start - 1 + cnt); if (row == null) { row = sheet.createRow(t1_start - 1 + cnt); } //? URL cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(m.getElement().getUrl()); cell.setCellStyle(cs1); cnt_cell++; // cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(m.getElement().getOrg()); cell.setCellStyle(cs1); cnt_cell++; //? cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(m.getElement().getDoc()); cell.setCellStyle(cs1); cnt_cell++; // cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(m.getElement().getDate()); cell.setCellStyle(cs1); cnt_cell++; // cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(m.getResult().name()); cell.setCellStyle(cs1); cnt_cell++; // (?) cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(m.getResult().getDesc()); cell.setCellStyle(cs1); cnt_cell++; // () cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(m.getResult().getCode()); cell.setCellStyle(cs1); cnt_cell++; cnt++; } // row = sheet.getRow(0); cell = row.getCell(0); cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(MAIN_ZAG_TEMPL + timestamp_csv); // HashMap<ResponseResult, Model_NumberReport> map = rep.reportCountBytype(); // ? sheet = wb.getSheet(""); // cnt = 0; for (Map.Entry<ResponseResult, Model_NumberReport> entry : map.entrySet()) { ResponseResult key = entry.getKey(); Model_NumberReport value = entry.getValue(); int cnt_cell = 0; row = sheet.getRow(t0_start - 1 + cnt); if (row == null) { row = sheet.createRow(t0_start - 1 + cnt); } /*// cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(key.name()); cell.setCellStyle(cs1); cnt_cell++;*/ // (?) cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(key.getDesc()); cell.setCellStyle(cs1); cnt_cell++; /*// () cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(key.getCode()); cell.setCellStyle(cs1); cnt_cell++;*/ // (?) cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(value.getNumber()); cell.setCellStyle(cs1); cnt_cell++; // () cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(FormatUtils.FormatDoubleD(value.getPercent())); cell.setCellStyle(cs1); cnt_cell++; cnt++; } // row = sheet.getRow(0); cell = row.getCell(0); cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(MAIN_ZAG_TEMPL + timestamp_csv); // HTTP map = rep.reportCountBytypeHTTP(); // ? sheet = wb.getSheet(" HTTP"); // cnt = 0; for (Map.Entry<ResponseResult, Model_NumberReport> entry : map.entrySet()) { ResponseResult key = entry.getKey(); Model_NumberReport value = entry.getValue(); int cnt_cell = 0; row = sheet.getRow(t0_start - 1 + cnt); if (row == null) { row = sheet.createRow(t0_start - 1 + cnt); } /*// cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(key.name()); cell.setCellStyle(cs1); cnt_cell++;*/ // (?) cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(key.getDesc()); cell.setCellStyle(cs1); cnt_cell++; /*// () cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(key.getCode()); cell.setCellStyle(cs1); cnt_cell++;*/ // (?) cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(value.getNumber()); cell.setCellStyle(cs1); cnt_cell++; // () cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(FormatUtils.FormatDoubleD(value.getPercent())); cell.setCellStyle(cs1); cnt_cell++; cnt++; } // row = sheet.getRow(0); cell = row.getCell(0); cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(MAIN_ZAG_TEMPL + timestamp_csv); // HTTPS map = rep.reportCountBytypeHTTPS(); // ? sheet = wb.getSheet(" HTTPS"); // cnt = 0; for (Map.Entry<ResponseResult, Model_NumberReport> entry : map.entrySet()) { ResponseResult key = entry.getKey(); Model_NumberReport value = entry.getValue(); int cnt_cell = 0; row = sheet.getRow(t0_start - 1 + cnt); if (row == null) { row = sheet.createRow(t0_start - 1 + cnt); } /*// cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(key.name()); cell.setCellStyle(cs1); cnt_cell++;*/ // (?) cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(key.getDesc()); cell.setCellStyle(cs1); cnt_cell++; /*// () cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(key.getCode()); cell.setCellStyle(cs1); cnt_cell++;*/ // (?) cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(value.getNumber()); cell.setCellStyle(cs1); cnt_cell++; // () cell = row.getCell(cnt_cell); if (cell == null) { cell = row.createCell(cnt_cell); } cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(FormatUtils.FormatDoubleD(value.getPercent())); cell.setCellStyle(cs1); cnt_cell++; cnt++; } // row = sheet.getRow(0); cell = row.getCell(0); cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(MAIN_ZAG_TEMPL + timestamp_csv); //? String tmp_out = StringUtils.replaceAll(report_name, "!dt!", DateUtils.DateToString(new Date(System.currentTimeMillis()), "ddMMyyyy_Hms")); try (FileOutputStream out = new FileOutputStream(tmp_out)) { wb.write(out); logger.info("Report file " + tmp_out + " created"); } } catch (Exception ex) { logger.error(ex); } }
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();//ww w . j a va2s.c o m font.setFontName(style.getFont()); font.setFontHeightInPoints(style.getFontSize()); font.setBold(style.isBold()); 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:Servelt.ExcelWriter.java
private void setMainCell(XSSFCell cell, String name) { XSSFCellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(HSSFColor.ORANGE.index); style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); style.setAlignment(XSSFCellStyle.ALIGN_CENTER); XSSFFont font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); cell.setCellValue(name);//w ww .j av a 2 s.co m cell.setCellStyle(style); }
From source file:Servelt.ExcelWriter.java
private void setAttrCell(XSSFCell cell, String name) { XSSFCellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(HSSFColor.YELLOW.index); style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); style.setAlignment(XSSFCellStyle.ALIGN_CENTER); XSSFFont font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); cell.setCellValue(name);//from ww w. ja va 2s . c o m cell.setCellStyle(style); }
From source file:Servelt.ExcelWriter.java
private void setDesCell(XSSFCell cell, String name) { XSSFCellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(HSSFColor.GREEN.index); style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); style.setAlignment(XSSFCellStyle.ALIGN_CENTER); XSSFFont font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); cell.setCellValue(name);/* ww w. j a v a 2 s. c o m*/ cell.setCellStyle(style); }
From source file:step.datapool.excel.StyleSyntax.java
License:Open Source License
/** * Analysiert den angegebenen Stil und setzt diesen excel-konform. * /*from ww w . ja v a 2 s .c o m*/ * @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 ww w. j a va 2 s . co m*/ // 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 www . j a v a 2s . com 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); } } } }
From source file:uk.co.certait.htmlexporter.writer.excel.ExcelStyleGenerator.java
License:Apache License
protected void applyFont(Cell cell, Style style, XSSFCellStyle cellStyle) { Font font = createFont(cell.getSheet().getWorkbook(), style); cellStyle.setFont(font); }