public class RichTextStringUtil
extends java.lang.Object
RichTextStringUtil
utility class provides methods for
RichTextString manipulation.Constructor | Description |
---|---|
RichTextStringUtil() |
Modifier and Type | Method | Description |
---|---|---|
static void |
applyFont(org.apache.poi.ss.usermodel.RichTextString richTextString,
org.apache.poi.ss.usermodel.Cell cell,
CellStyleCache cellStyleCache,
FontCache fontCache) |
Take the first
Font from the given
RichTextString and apply it to the given Cell's
CellStyle . |
static org.apache.poi.ss.usermodel.RichTextString |
createFormattedString(int numFormattingRuns,
org.apache.poi.ss.usermodel.CreationHelper helper,
java.lang.String value,
java.util.List<net.sf.jett.util.FormattingRun> formattingRuns) |
Construct a
RichTextString of the same type as
richTextString , format it, and return it. |
static java.util.List<net.sf.jett.util.FormattingRun> |
determineFormattingRunStats(org.apache.poi.ss.usermodel.RichTextString richTextString) |
Determine formatting run statistics for the given
RichTextString . |
static void |
formatString(org.apache.poi.ss.usermodel.RichTextString string,
int numFormattingRuns,
java.util.List<net.sf.jett.util.FormattingRun> formattingRuns) |
Format a
RichTextString that has already been created. |
static java.lang.Object |
getFontAtIndex(org.apache.poi.ss.usermodel.RichTextString richTextString,
int fmtIndex) |
Gets the font index of the
Font in use at the specified
position in the given RichTextString . |
static org.apache.poi.ss.usermodel.RichTextString |
performEscaping(org.apache.poi.ss.usermodel.RichTextString richTextString,
org.apache.poi.ss.usermodel.CreationHelper helper) |
Performs escaping.
|
static org.apache.poi.ss.usermodel.RichTextString |
replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString,
org.apache.poi.ss.usermodel.CreationHelper helper,
java.lang.String target,
java.lang.String replacement) |
Replaces all occurrences of the given target string with the replacement
string.
|
static org.apache.poi.ss.usermodel.RichTextString |
replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString,
org.apache.poi.ss.usermodel.CreationHelper helper,
java.lang.String target,
java.lang.String replacement,
boolean firstOnly) |
Replaces all occurrences of the given target string with the replacement
string.
|
static org.apache.poi.ss.usermodel.RichTextString |
replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString,
org.apache.poi.ss.usermodel.CreationHelper helper,
java.lang.String target,
java.lang.String replacement,
boolean firstOnly,
int startIdx) |
Replaces all occurrences of the given target string with the replacement
string.
|
static org.apache.poi.ss.usermodel.RichTextString |
replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString,
org.apache.poi.ss.usermodel.CreationHelper helper,
java.lang.String target,
java.lang.String replacement,
boolean firstOnly,
int startIdx,
boolean identifierMode) |
Replaces all occurrences of the given target string with the replacement
string.
|
static org.apache.poi.ss.usermodel.RichTextString |
replaceValues(org.apache.poi.ss.usermodel.RichTextString richTextString,
org.apache.poi.ss.usermodel.CreationHelper helper,
java.util.List<java.lang.String> targets,
java.util.List<java.lang.String> replacements,
boolean replaceAll) |
Replaces all strings in the given
List of strings to replace
with the corresponding replacement string in the given List . |
static org.apache.poi.ss.usermodel.RichTextString |
substring(org.apache.poi.ss.usermodel.RichTextString richTextString,
org.apache.poi.ss.usermodel.CreationHelper helper,
int beginIndex,
int endIndex) |
Extracts a substring of a
RichTextString as another
RichTextString . |
public static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.String target, java.lang.String replacement)
richTextString
- The RichTextString
to manipulate.helper
- A CreationHelper
that can create the proper
RichTextString
.target
- The string to replace.replacement
- The replacement string.RichTextString
with replaced values, or the
same RichTextString
if replace
is
null
or empty.public static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.String target, java.lang.String replacement, boolean firstOnly)
richTextString
- The RichTextString
to manipulate.helper
- A CreationHelper
that can create the proper
RichTextString
.target
- The string to replace.replacement
- The replacement string.firstOnly
- Whether to stop after replacing the first found instance
of target
.RichTextString
with replaced values, or the
same RichTextString
if replace
is
null
or empty.public static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.String target, java.lang.String replacement, boolean firstOnly, int startIdx)
richTextString
- The RichTextString
to manipulate.helper
- A CreationHelper
that can create the proper
RichTextString
.target
- The string to replace.replacement
- The replacement string.firstOnly
- Whether to stop after replacing the first found instance
of target
.startIdx
- Start replacing after this 0-based index into the
richTextString
.RichTextString
with replaced values, or the
same RichTextString
if replace
is
null
or empty.public static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.String target, java.lang.String replacement, boolean firstOnly, int startIdx, boolean identifierMode)
richTextString
- The RichTextString
to manipulate.helper
- A CreationHelper
that can create the proper
RichTextString
.target
- The string to replace.replacement
- The replacement string.firstOnly
- Whether to stop after replacing the first found instance
of target
.startIdx
- Start replacing after this 0-based index into the
richTextString
.identifierMode
- If true, makes sure that the target
is
NOT replaced if the target string is part of a larger identifier.
E.g. if target
is "activity"
, don't replace
the "activity"
substring within "activityDay"
.
Only replace the target if found within expressions.RichTextString
with replaced values, or the
same RichTextString
if replace
is
null
or empty.public static org.apache.poi.ss.usermodel.RichTextString replaceValues(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, java.util.List<java.lang.String> targets, java.util.List<java.lang.String> replacements, boolean replaceAll)
List
of strings to replace
with the corresponding replacement string in the given List
.
Preserves rich text formatting as much as possible.richTextString
- The RichTextString
to manipulate.helper
- A CreationHelper
that can create the proper
RichTextString
.targets
- The List
of strings to replace.replacements
- The corresponding List
of replacement
strings.replaceAll
- If true
replace all occurrences, else only
replace the first occurrence.RichTextString
with replaced values, or the
same RichTextString
if replace
is
null
or empty.public static org.apache.poi.ss.usermodel.RichTextString substring(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, int beginIndex, int endIndex)
RichTextString
as another
RichTextString
. Preserves the formatting that is in place
from the given string.richTextString
- The RichTextString
of which to take a
substring.helper
- A CreationHelper
that can create the proper
RichTextString
.beginIndex
- The beginning index, inclusive.endIndex
- The ending index, exclusive.RichTextString
, with
the original formatting from the original string intact.public static java.util.List<net.sf.jett.util.FormattingRun> determineFormattingRunStats(org.apache.poi.ss.usermodel.RichTextString richTextString)
RichTextString
. Adds elements to the arrays.richTextString
- The RichTextString
.List
of all FormattingRun
s found.public static org.apache.poi.ss.usermodel.RichTextString createFormattedString(int numFormattingRuns, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.String value, java.util.List<net.sf.jett.util.FormattingRun> formattingRuns)
RichTextString
of the same type as
richTextString
, format it, and return it.numFormattingRuns
- The number of formatting runs.value
- The new string value of the new RichTextString
to construct.helper
- A CreationHelper
that can create the proper
RichTextString
.formattingRuns
- A List
of FormattingRuns
.RichTextString
, the same type as
richTextString
, with value
as it contents,
formatted as specified.public static void formatString(org.apache.poi.ss.usermodel.RichTextString string, int numFormattingRuns, java.util.List<net.sf.jett.util.FormattingRun> formattingRuns)
RichTextString
that has already been created.string
- A RichTextString
.numFormattingRuns
- The number of formatting runs.formattingRuns
- A List
of FormattingRuns
.public static java.lang.Object getFontAtIndex(org.apache.poi.ss.usermodel.RichTextString richTextString, int fmtIndex)
Font
in use at the specified
position in the given RichTextString
.richTextString
- The RichTextString
.fmtIndex
- The 0-based index of the formatting run.short
. If XSSF, an
XSSFFont
.public static void applyFont(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.Cell cell, CellStyleCache cellStyleCache, FontCache fontCache)
Font
from the given
RichTextString
and apply it to the given Cell's
CellStyle
.cell
- The Cell
.richTextString
- The RichTextString
that contains the
desired Font
.cellStyleCache
- The CellStyleCache
in which to look
for another CellStyle
.fontCache
- The FontCache
in which to look for another
Font
.public static org.apache.poi.ss.usermodel.RichTextString performEscaping(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper)
Performs escaping. Preserves rich text formatting as much as possible. The following escape sequences are recognized:
\"
=> "
\'
=> '
\\
=> \
\b
=> (backspace)
\f
=> (form feed)
\n
=> (newline)
\r
=> (carriage return)
\t
=> (tab)
richTextString
- The RichTextString
to manipulate.helper
- A CreationHelper
that can create the proper
RichTextString
.RichTextString
with escape sequences replaced
with the actual characters.Copyright © 2012–2018 Jett Team. All rights reserved.