Example usage for org.apache.poi.xssf.usermodel XSSFRichTextString length

List of usage examples for org.apache.poi.xssf.usermodel XSSFRichTextString length

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFRichTextString length.

Prototype

public int length() 

Source Link

Document

Returns the number of characters in this string.

Usage

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   ww  w .j a v  a2 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);
    }

}