List of usage examples for org.apache.poi.xssf.usermodel XSSFRichTextString append
public void append(String text)
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 * /*from w w w .java 2 s . c o 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. * /*from w w w . ja v a 2 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); }