List of usage examples for org.apache.poi.xssf.usermodel XSSFRichTextString XSSFRichTextString
public XSSFRichTextString()
From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.BaseXLS.java
License:Open Source License
/** * This method writes string founded value into a specific cell * /* ww w . j av a 2s . co m*/ * @param sheet is the sheet where you want to add information into. * @param value is the specific information to be written. * @param terms terms to compare the string. */ public void writeSearchString(Sheet sheet, String text, String[] terms) { this.prepareCell(sheet); StringTokenizer tokens; String token; int begin = 0; XSSFRichTextString richText = new XSSFRichTextString(); if (text == null) { cell.setCellValue(""); } else { // tokens = new StringTokenizer(text); while (tokens.hasMoreTokens()) { token = tokens.nextToken().toLowerCase(); richText.append(token); begin = richText.length() - token.length(); for (Point point : this.auxiliarRichText(token, terms)) { richText.applyFont(begin + point.x, begin + point.y + 1, this.richTextFont); } richText.append(" "); } if (text.toString().length() > 30) { sheet.setColumnWidth(columnCounter, 12000); } cell.setCellValue(richText); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.BaseXLS.java
License:Open Source License
/** * This method writes the title box into the given sheet. * // ww w .j a va2 s.c o m * @param sheet is the sheet where you want to write the title box. * @param text is the title of the report. */ public void writeTitleBox(Sheet sheet, String text) { XSSFDrawing draw = (XSSFDrawing) sheet.createDrawingPatriarch(); XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 1, 1, 1, 1, 3, 6); anchor.setAnchorType(2); XSSFTextBox textbox = draw.createTextbox(anchor); textbox.setFillColor(TEXTBOX_BACKGROUND_COLOR_RGB.getRed(), TEXTBOX_BACKGROUND_COLOR_RGB.getGreen(), TEXTBOX_BACKGROUND_COLOR_RGB.getBlue()); textbox.setVerticalAlignment(VerticalAlignment.CENTER); XSSFRichTextString stringX = new XSSFRichTextString(); Font font = workbook.createFont(); font.setFontHeightInPoints((short) 20); font.setFontName("Tahoma"); font.setColor(TEXTBOX_FONT_COLOR_INDEX); stringX.append(text); stringX.applyFont(font); textbox.setText(stringX); }
From source file:se.inera.intyg.rehabstod.service.export.xlsx.XlsxExportServiceImpl.java
License:Open Source License
private XSSFRichTextString diagnosKapitelFormat(String diagnosKapitelId) { StringBuilder buf = new StringBuilder(); buf.append(diagnosKapitelId).append(StringUtils.isNotEmpty(diagnosKapitelId) ? ": " : ""); // Add the description text for the code buf.append(diagnosKapitelService.getDiagnosKapitel(diagnosKapitelId).getName()); XSSFRichTextString richTextString = new XSSFRichTextString(); richTextString.setString(buf.toString()); richTextString.applyFont(defaultFont12); richTextString.applyFont(0, diagnosKapitelId.length(), boldFont12); return richTextString; }
From source file:se.inera.intyg.rehabstod.service.export.xlsx.XlsxExportServiceImpl.java
License:Open Source License
private XSSFRichTextString buildPersonnummerRichText(Patient patient) { String value = patient.getId(); XSSFRichTextString richTextString = new XSSFRichTextString(); richTextString.setString(value);/*w w w. ja v a 2s.c om*/ richTextString.applyFont(defaultFont11); return richTextString; }
From source file:se.inera.intyg.rehabstod.service.export.xlsx.XlsxExportServiceImpl.java
License:Open Source License
private XSSFRichTextString buildGraderRichText(SjukfallEnhet sf) { if (sf.getGrader() == null || sf.getGrader().isEmpty()) { return new XSSFRichTextString(); }/*w w w. ja va 2 s.c om*/ StringBuilder buf = new StringBuilder(); Pair aktivIndicies = null; boolean first = true; for (Integer grad : sf.getGrader()) { if (!first) { buf.append(UNICODE_RIGHT_ARROW_SYMBOL).append(" "); } int currentIndex = buf.length(); // Store indicies for the aktiv grad so we can make its text bold later. if (grad == sf.getAktivGrad()) { aktivIndicies = new Pair(currentIndex, currentIndex + ("" + grad + "%").length()); } buf.append("").append(grad).append("% "); first = false; } buf.setLength(buf.length() - 1); XSSFRichTextString richTextString = new XSSFRichTextString(); richTextString.setString(buf.toString()); richTextString.applyFont(defaultFont11); // Uses stored indicies to make the correct part of the rich string bold. if (aktivIndicies != null) { richTextString.applyFont(aktivIndicies.getI1(), aktivIndicies.getI2(), boldFont11); } return richTextString; }