List of usage examples for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD
short BOLDWEIGHT_BOLD
To view the source code for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD.
Click Source Link
From source file:teamdash.wbs.excel.StyleKey.java
License:Open Source License
public void configure(HSSFFont font) { if (color != BLACK) font.setColor(color);//w w w. ja v a2 s . co m if (bold) font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); if (italic) font.setItalic(true); }
From source file:test.poi.MyExcelDemo.java
License:Apache License
/** * Create a library of cell styles// w w w . j av a 2s . c om */ private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 18); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(titleFont); styles.put("title", style); Font headerFont = wb.createFont(); headerFont.setFontHeightInPoints((short) 11); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerFont.setColor(IndexedColors.BLACK.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); // style.setWrapText(true); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); styles.put("header", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setWrapText(true); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); styles.put("cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula_2", style); return styles; }
From source file:ua.com.ecotep.unianalysis.export.XLSDataExport.java
@Override public void exportData(String selectedFile, AnProperties props, ObservableList<ObservableList<Object>> exportData, List<String> columnTitles) throws Exception { if (selectedFile == null) { return;//ww w.j a v a2 s.c o m } System.setProperty("java.awt.headless", "true"); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Sheet1"); HSSFPrintSetup ps = sheet.getPrintSetup(); ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE); ps.setLandscape(true); HSSFCellStyle cellStyleT = wb.createCellStyle(); HSSFFont font1 = wb.createFont(); font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font1.setFontHeightInPoints((short) 8); cellStyleT.setFont(font1); int rnumber = 0; HSSFRow row = sheet.createRow(0); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10)); HSSFCell cell = row.createCell(0); cell.setCellValue( new HSSFRichTextString(" ??? ??? - " + DateConverters.getDateToStr(LocalDate.now()))); cell.setCellStyle(cellStyleT); rnumber++; if (props != null) { String val = " : " + DateConverters.getDateToStr(props.getDateFrom()) + " " + DateConverters.getDateToStr(props.getDateTo()); createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; //---------- if (props.isSalMode()) { String type = props.getSalSalerType() == AnProperties.SALER_TYPES.PROFILE ? " " : " "; val = "? " + type + "| " + props.getSaler().getNameSaler(); createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; if (props.getSalSalerType() == AnProperties.SALER_TYPES.SALER) { type = props.isSalDirectSales() ? "? " : " "; val = " : " + type; createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; if (props.isSalFixedDepartment()) { val = " : "; createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } } } if (props.isGoodMode()) { if (props.getGoodClassLev0() != null) { val = "? 1: " + props.getGoodClassLev0().getName(); createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; if (props.getGoodClassLev1() != null) { val = "? 2: " + props.getGoodClassLev1().getName(); createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; if (props.getGoodClassLev2() != null) { val = "? 3: " + props.getGoodClassLev2().getName(); createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; if (props.getGoodClassLev3() != null) { val = "? 4: " + props.getGoodClassLev3().getName(); createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } } } if (props.getGoodCustomSearch() != null && !props.getGoodCustomSearch().isEmpty()) { val = " : " + props.getGoodCustomSearch(); createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } if (props.isGoodPeriodAnalysis() && props.getGoodsIndateLst().size() == 2) { val = " : " + DateConverters.getDateToStr(props.getGoodsIndateLst().get(0)); createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; val = " : " + DateConverters.getDateToStr(props.getGoodsIndateLst().get(1)); createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } if (!props.isGoodPeriodAnalysis() && props.getGoodsIndateLst().size() > 0) { val = "+: "; for (LocalDate ld : props.getGoodsIndateLst()) { val += DateConverters.getDateToStr(ld) + "; "; } createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } } } if (!props.getClLst().isEmpty()) { if (props.isClIncluded()) { val = " : "; createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } else { val = " : "; createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } val = "+: "; for (ClientBean cb : props.getClLst()) { val += cb.getClientCl() + "; "; } createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } if (!props.getVLst().isEmpty()) { if (props.isVIncluded()) { val = " : "; createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } else { val = " : "; createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } val = ""; for (String v : props.getVLst()) { val += v + "; "; } createHeaderCell(sheet, rnumber, val, cellStyleT); rnumber++; } } //---------- HSSFCellStyle cellStyleH = wb.createCellStyle(); HSSFFont font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyleH.setFont(font); cellStyleH.setWrapText(true); cellStyleH.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyleH.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyleH.setBorderLeft((short) 1); cellStyleH.setBorderRight((short) 1); cellStyleH.setBorderTop((short) 1); cellStyleH.setBorderBottom((short) 1); HSSFCellStyle cellStyleHh = wb.createCellStyle(); font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyleHh.setFont(font); cellStyleHh.setWrapText(true); cellStyleHh.setAlignment(HSSFCellStyle.ALIGN_RIGHT); cellStyleHh.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyleHh.setBorderLeft((short) 1); cellStyleHh.setBorderRight((short) 1); cellStyleHh.setBorderTop((short) 1); cellStyleHh.setBorderBottom((short) 1); //filling table HSSFCellStyle cellStyleN = wb.createCellStyle(); cellStyleN.setAlignment(HSSFCellStyle.ALIGN_LEFT); cellStyleN.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyleN.setBorderLeft((short) 1); cellStyleN.setBorderRight((short) 1); cellStyleN.setBorderTop((short) 1); cellStyleN.setBorderBottom((short) 1); HSSFCellStyle cellStyleI = wb.createCellStyle(); cellStyleI.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyleI.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyleI.setBorderLeft((short) 1); cellStyleI.setBorderRight((short) 1); cellStyleI.setBorderTop((short) 1); cellStyleI.setBorderBottom((short) 1); HSSFCellStyle cellStyleD = wb.createCellStyle(); cellStyleD.setAlignment(HSSFCellStyle.ALIGN_RIGHT); cellStyleD.setVerticalAlignment(HSSFCellStyle.ALIGN_RIGHT); HSSFDataFormat df = wb.createDataFormat(); cellStyleD.setDataFormat(df.getFormat("#,##0.0")); cellStyleD.setBorderLeft((short) 1); cellStyleD.setBorderRight((short) 1); cellStyleD.setBorderTop((short) 1); cellStyleD.setBorderBottom((short) 1); HSSFCellStyle cellStyleP = wb.createCellStyle(); cellStyleP.setAlignment(HSSFCellStyle.ALIGN_RIGHT); cellStyleP.setVerticalAlignment(HSSFCellStyle.ALIGN_RIGHT); cellStyleP.setDataFormat(df.getFormat("0.0\\%")); cellStyleP.setBorderLeft((short) 1); cellStyleP.setBorderRight((short) 1); cellStyleP.setBorderTop((short) 1); cellStyleP.setBorderBottom((short) 1); // filling column headers row = sheet.createRow(rnumber); String rowTitle = null; row = sheet.createRow(rnumber); row.setHeightInPoints(40); cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString("?")); cell.setCellStyle(cellStyleH); for (int t = 0; t < columnTitles.size(); t++) { cell = row.createCell(t + 1); cell.setCellValue(new HSSFRichTextString(columnTitles.get(t))); cell.setCellStyle(cellStyleH); } // filling table with data rnumber++; for (ObservableList<Object> line : exportData) { row = sheet.createRow(rnumber); cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString((String) line.get(0))); cell.setCellStyle(cellStyleN); for (int i = 1; i < line.size(); i++) { Double val = (Double) line.get(i); cell = row.createCell(i); cell.setCellStyle(cellStyleD); cell.setCellValue(val); } rnumber++; } for (int t = 0; t < columnTitles.size(); t++) { sheet.autoSizeColumn((short) t); } saveWorkBook(wb, selectedFile); execute(selectedFile); }
From source file:ubic.pubmedgate.interactions.evaluation.CreateInteractionSpreadsheet.java
License:Apache License
public void populate(Collection<NormalizedConnection> pairsNormalized) throws Exception { int row = 1;/*from w w w .ja v a2 s.c o m*/ boolean unseenSetup = SLReader.isUnseenSetup(); HSSFFont textFont = workbook.createFont(); textFont.setUnderline(HSSFFont.U_SINGLE); textFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); Map<String, String> pairToPMID = XMLReader.getPairIDToPMID(); Map<String, Double> scores = SLReader.getScores(); List<String> positivePredictions = SLReader.getPositivePredictions(); List<String> positiveAnnotations = SLReader.getPositives(); LoadInteractionSpreadsheet allSpreadSheet = AllCuratorsCombined.getFinal2000Results(); Set<String> previousAccepts = allSpreadSheet.getAcceptedPairs(); Collection<String> previousEvaluated = allSpreadSheet.getAllPairs(); for (NormalizedConnection nc : pairsNormalized) { String pair = nc.pairID; if (row > 65000) { save(); init(); filename += "overflow.xls"; row = 1; } HSSFRow r = spreadsheet.getRow(row); if (r == null) { r = spreadsheet.createRow(row); } int col = schema.getPosition("sentence"); HSSFCell c = r.createCell(col); c.setCellType(HSSFCell.CELL_TYPE_STRING); HSSFRichTextString richString = XMLReader.getRichStringSentence(pair, textFont); c.setCellValue(richString); String pmid = pairToPMID.get(pair); ExcelUtil.setValue(spreadsheet, row, schema.getPosition("PMID"), pmid); ExcelUtil.setValue(spreadsheet, row, schema.getPosition("PairID"), pair); String partnerAText = XMLReader.getPartnerAText(pair); String partnerBText = XMLReader.getPartnerBText(pair); ExcelUtil.setValue(spreadsheet, row, schema.getPosition("RegionAName"), partnerAText); ExcelUtil.setValue(spreadsheet, row, schema.getPosition("RegionBName"), partnerBText); ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Score"), scores.get(pair)); ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Prediction"), "" + positivePredictions.contains(pair)); if (!unseenSetup) { ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Previous Annotation"), "" + positiveAnnotations.contains(pair)); } else { ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Previous Annotation"), "none"); } // if it was normalized if (nc.regionA != null) { ExcelUtil.setValue(spreadsheet, row, schema.getPosition("RegionAResolve"), nc.regionA); // check for exact match if (nc.regionA.equalsIgnoreCase(partnerAText)) { ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Resolve Evaluation A"), "Accept"); } } if (nc.regionB != null) { ExcelUtil.setValue(spreadsheet, row, schema.getPosition("RegionBResolve"), nc.regionB); // check for exact match if (nc.regionB.equalsIgnoreCase(partnerBText)) { ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Resolve Evaluation B"), "Accept"); } } String acceptString; if (previousEvaluated.contains(pair)) { if (previousAccepts.contains(pair)) { acceptString = "Accept"; } else { acceptString = "Reject"; } } else { acceptString = "Not done"; } ExcelUtil.setValue(spreadsheet, row, schema.getPosition("Previous Annotation"), acceptString); ExcelUtil.setFormula(spreadsheet, row, schema.getPosition("LinkToAbstract"), "HYPERLINK(\"http://www.ncbi.nlm.nih.gov/pubmed/" + pmid + "\", \"PubMed\")"); row++; } }
From source file:uk.ac.manchester.cs.owl.semspreadsheets.model.hssf.impl.CellHSSFImpl.java
License:BSD License
public void setBold(boolean b) { HSSFCellStyle cellStyle = theCell.getCellStyle(); if (cellStyle == null) { cellStyle = getWorkbook().createCellStyle(); theCell.setCellStyle(cellStyle); }/*from ww w . j a va2 s . c om*/ HSSFFont font = cellStyle.getFont(getWorkbook()); if (font == null) { font = getWorkbook().createFont(); cellStyle.setFont(font); } if (b) { font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); } else { font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); } fontCache.clear(); }
From source file:uk.ac.manchester.cs.owl.semspreadsheets.model.hssf.impl.CellHSSFImpl.java
License:BSD License
private Font getFont(HSSFFont hssfFont) { Font font = fontCache.get(hssfFont); if (font == null) { String name = hssfFont.getFontName(); int size = hssfFont.getFontHeightInPoints(); int style = Font.PLAIN; if (hssfFont.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) { style = Font.BOLD;/*from ww w .j a v a2 s .c om*/ if (hssfFont.getItalic()) { style = style | Font.ITALIC; } } else if (hssfFont.getItalic()) { style = Font.ITALIC; } font = new Font(name, style, size); fontCache.put(hssfFont, font); } return font; }
From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java
private void saveReportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveReportBtnActionPerformed try {// ww w .java 2 s. c om HSSFWorkbook fWorkbook = new HSSFWorkbook(); HSSFSheet fSheet = fWorkbook.createSheet("new Sheet"); HSSFFont sheetTitleFont = fWorkbook.createFont(); File file = new File("C:\\Users\\Reshmi\\OneDrive\\Documents\\reports.xls"); HSSFCellStyle cellStyle = fWorkbook.createCellStyle(); sheetTitleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //sheetTitleFont.setColor(); TableModel model = vitalSignjTable.getModel(); TableColumnModel tcm = vitalSignjTable.getColumnModel(); HSSFRow fRow1 = fSheet.createRow((short) 0); for (int j = 0; j < tcm.getColumnCount(); j++) { HSSFCell cell = fRow1.createCell((short) j); cell.setCellValue(tcm.getColumn(j).getHeaderValue().toString()); } for (int i = 0; i < model.getRowCount(); i++) { HSSFRow fRow = fSheet.createRow((short) i + 1); for (int j = 0; j < model.getColumnCount(); j++) { HSSFCell cell = fRow.createCell((short) j); cell.setCellValue(tcm.getColumn(j).getHeaderValue().toString()); cell.setCellValue(model.getValueAt(i, j).toString()); cell.setCellStyle(cellStyle); } } FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream); fWorkbook.write(bos); bos.close(); fileOutputStream.close(); JOptionPane.showMessageDialog(null, "File saved as reports.xls ", "Export", JOptionPane.INFORMATION_MESSAGE); // Runtime run = Runtime.getRuntime(); // run.exec("cmd.exetart " + file); } catch (Exception e) { JOptionPane.showMessageDialog(null, "File not saved", "Export", JOptionPane.INFORMATION_MESSAGE); } }
From source file:utilesBD.servidoresDatos.JServerServidorDatosExcel.java
public static void guardar(JListDatos poList, File poFile, boolean pbCabezera) throws Throwable { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(poList.msTabla); int lHoja = 1; HSSFCellStyle style = workbook.createCellStyle(); // style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setWrapText(true);// w ww . j ava 2 s. c o m HSSFFont font = workbook.createFont(); font.setFontHeightInPoints((short) 10); font.setFontName("Courier New"); font.setItalic(true); // font.setStrikeout(true); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //font.setColor(Short.parseShort("#ffffff")); style.setFont(font); int lFila = 0; if (pbCabezera) { lFila++; crearCabecera(poList, sheet, style, lFila); } if (poList.moveFirst()) { do { lFila++; toExcel(poList, workbook, lFila, sheet); if (lFila > 65524) { lFila = 0; if (pbCabezera) { lFila++; crearCabecera(poList, sheet, style, lFila); } lHoja++; sheet = workbook.createSheet(poList.msTabla + String.valueOf(lHoja)); } } while (poList.moveNext()); } // Escribir el fichero. OutputStream fileOut = new FileOutputStream(poFile); try { workbook.write(fileOut); } finally { fileOut.close(); } }
From source file:Utility.TestReports.java
public void setHeaderCellStyle(org.apache.poi.hssf.usermodel.HSSFSheet sheet, org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.hssf.usermodel.HSSFWorkbook wb) { CellStyle s = null;//from w w w .java 2s .c o m s = sheet.getWorkbook().createCellStyle(); cell.setCellStyle(s); HSSFFont font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); s.setFont(font); s.setAlignment(CellStyle.ALIGN_GENERAL); s.setBorderBottom(CellStyle.BORDER_THIN); s.setBorderLeft(CellStyle.BORDER_THIN); s.setBorderRight(CellStyle.BORDER_THIN); s.setBorderTop(CellStyle.BORDER_THIN); s.setVerticalAlignment(CellStyle.VERTICAL_CENTER); s.setAlignment(CellStyle.ALIGN_LEFT); s.setFont(font); }