本文整理汇总了Java中org.apache.poi.ss.usermodel.RichTextString.getString方法的典型用法代码示例。如果您正苦于以下问题:Java RichTextString.getString方法的具体用法?Java RichTextString.getString怎么用?Java RichTextString.getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.RichTextString
的用法示例。
在下文中一共展示了RichTextString.getString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateString
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Find any <code>Expressions</code> embedded in the given string, evaluate
* them, and replace the expressions with the resulting values. If the
* entire string consists of one <code>Expression</code>, then the returned
* value may be any <code>Object</code>.
*
* @param richTextString The rich text string, with possibly embedded
* expressions.
* @param helper A <code>CreationHelper</code> that can create the proper
* <code>RichTextString</code>.
* @param beans A <code>Map</code> mapping strings to objects.
* @return A new string, with any embedded expressions replaced with the
* expression string values.
*/
public static Object evaluateString(RichTextString richTextString,
CreationHelper helper, Map<String, Object> beans)
{
String value = richTextString.getString();
List<Expression> expressions = getExpressions(value);
if (value.startsWith(Expression.BEGIN_EXPR) && value.endsWith(Expression.END_EXPR) && expressions.size() == 1)
{
Expression expression = new Expression(value.substring(2, value.length() - 1));
Object result = expression.evaluate(beans);
if (result instanceof String)
{
return RichTextStringUtil.replaceAll(richTextString, helper, value, (String) result, true);
}
else
{
return result;
}
}
else
{
return replaceExpressions(richTextString, helper, expressions, beans);
}
}
示例2: getFontAtIndex
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Gets the font index of the <code>Font</code> in use at the specified
* position in the given <code>RichTextString</code>.
* @param richTextString The <code>RichTextString</code>.
* @param fmtIndex The 0-based index of the formatting run.
* @return The font index: If HSSF, a <code>short</code>. If XSSF, an
* <code>XSSFFont</code>.
*/
public static Object getFontAtIndex(RichTextString richTextString, int fmtIndex)
{
if (richTextString instanceof HSSFRichTextString)
{
// Returns a short.
return ((HSSFRichTextString) richTextString).getFontAtIndex(fmtIndex);
}
else if (richTextString instanceof XSSFRichTextString)
{
try
{
// Instead of returning null, getFontAtIndex (eventually) throws a
// NullPointerException. It extracts a "CTRElt" from an array, and
// it extracts a "CTRPrElt" from the "CTRElt". The "CTRprElt" can
// be null if there is no font at the formatting run. Then, when
// creating a "CTFont", it calls a method on the null "CTRPrElt".
// Return an XSSFFont.
return ((XSSFRichTextString) richTextString).getFontAtIndex(fmtIndex);
}
catch (NullPointerException e)
{
// Detect this case and return null.
if (DEBUG)
System.err.println(" NullPointerException caught!");
return null;
}
}
else
throw new IllegalArgumentException("Unexpected RichTextString type: " +
richTextString.getClass().getName() + ": " + richTextString.getString());
}
示例3: toRichText
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
public RichText toRichText(RichTextString rts) {
String text = rts.getString();
// TODO: properly process tabs
text = text.replace('\t', ' '); // tab
text = text.replace((char) 160, ' '); // non-breaking space
RichTextBuilder rtb = new RichTextBuilder();
int start = 0;
for (int i = 0; i < rts.numFormattingRuns(); i++) {
start = rts.getIndexOfFormattingRun(i);
int end = i + 1 < rts.numFormattingRuns() ? rts.getIndexOfFormattingRun(i + 1) : rts.length();
if (start == end) {
// skip empty
continue;
}
Map<String, Object> properties = new HashMap<>();
// apply font attributes for formatting run
Font runFont = getFontForFormattingRun(rts, i);
properties.put(TextAttributes.FONT_FAMILY, runFont.getFamily());
properties.put(TextAttributes.FONT_SIZE, runFont.getSizeInPoints() + "pt");
properties.put(TextAttributes.COLOR, runFont.getColor().toString());
if (runFont.isBold()) {
properties.put(TextAttributes.FONT_WEIGHT, "bold");
}
if (runFont.isItalic()) {
properties.put(TextAttributes.FONT_STYLE, "italic");
}
if (runFont.isUnderlined()) {
properties.put(TextAttributes.TEXT_DECORATION, "underline");
}
if (runFont.isStrikeThrough()) {
properties.put(TextAttributes.TEXT_DECORATION, "line-through");
}
properties.put(TextAttributes.COLOR, runFont.getColor());
Style attr = Style.create("style", properties);
push(rtb, TextAttributes.STYLE_START_RUN, attr );
rtb.append(text, start, end);
push(rtb, TextAttributes.STYLE_END_RUN, attr );
start = end;
}
rtb.append(text, start, text.length());
return rtb.toRichText();
}
示例4: getDoubleCellValue
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Gets the Double value of a cell
*
* @param cell
* @return
*/
private static Double getDoubleCellValue(Cell cell, Locale locale) throws ExcelImportInvalidCellValueException {
Double doubleValue = null;
int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_NUMERIC) {
double numericValue = cell.getNumericCellValue();
try {
doubleValue = new Double(numericValue);
} catch (Exception e) {
throw new ExcelImportInvalidCellValueException(String.valueOf(numericValue));
}
} else {
if (cellType == Cell.CELL_TYPE_STRING) {
RichTextString richTextString = cell.getRichStringCellValue();
if (richTextString != null) {
String stringValue = richTextString.getString();
if (stringValue != null) {
stringValue = stringValue.trim();
if (!"".equals(stringValue)) {
doubleValue = DoubleNumberFormatUtil.getInstance().parseGUI(stringValue, locale);
if (doubleValue == null) {
doubleValue = DoubleNumberFormatUtil.parseISO(stringValue);
if (doubleValue == null) {
throw new ExcelImportInvalidCellValueException(stringValue);
}
}
}
}
}
} else {
throw new ExcelImportInvalidCellValueException(getStringCellValue(cell));
}
}
return doubleValue;
}
示例5: getDateCellValue
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Gets the Double value of a cell
*
* @param cell
* @return
*/
private static Date getDateCellValue(Cell cell, Locale locale) throws ExcelImportInvalidCellValueException {
Date dateValue = null;
int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_NUMERIC) {
try {
dateValue = cell.getDateCellValue();
} catch (Exception e) {
throw new ExcelImportInvalidCellValueException(String.valueOf(cell.getNumericCellValue()));
}
} else {
if (cellType == Cell.CELL_TYPE_STRING) {
RichTextString richTextString = cell.getRichStringCellValue();
if (richTextString != null) {
String stringValue = richTextString.getString();
if (stringValue != null) {
stringValue = stringValue.trim();
if (!"".equals(stringValue)) {
dateValue = DateTimeUtils.getInstance().parseGUIDate(stringValue, locale);
if (dateValue == null) {
dateValue = DateTimeUtils.getInstance().parseShortDate(stringValue, locale);
if (dateValue == null) {
dateValue = DateTimeUtils.getInstance().parseISODate(stringValue);
if (dateValue == null) {
throw new ExcelImportInvalidCellValueException(stringValue);
}
}
}
}
}
}
} else {
throw new ExcelImportInvalidCellValueException(getStringCellValue(cell));
}
}
return dateValue;
}
示例6: getDateTimeCellValue
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Gets the Double value of a cell
*
* @param cell
* @return
*/
private static Date getDateTimeCellValue(Cell cell, Locale locale) throws ExcelImportInvalidCellValueException {
Date dateValue = null;
int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_NUMERIC) {
try {
dateValue = cell.getDateCellValue();
} catch (Exception e) {
throw new ExcelImportInvalidCellValueException(String.valueOf(cell.getNumericCellValue()));
}
} else {
if (cellType == Cell.CELL_TYPE_STRING) {
RichTextString richTextString = cell.getRichStringCellValue();
if (richTextString != null) {
String stringValue = richTextString.getString();
if (stringValue != null) {
stringValue = stringValue.trim();
if (!"".equals(stringValue)) {
dateValue = DateTimeUtils.getInstance().parseGUIDateTime(stringValue, locale);
if (dateValue == null) {
dateValue = DateTimeUtils.getInstance().parseShortDateTime(stringValue, locale);
if (dateValue == null) {
dateValue = DateTimeUtils.getInstance().parseISODateTime(stringValue);
}
}
}
}
}
} else {
throw new ExcelImportInvalidCellValueException(getStringCellValue(cell));
}
}
return dateValue;
}
示例7: getBooleanCellValue
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Gets the Double value of a cell
*
* @param cell
* @return
*/
private static Boolean getBooleanCellValue(Cell cell) throws ExcelImportInvalidCellValueException {
Boolean booleanValue = null;
int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_BOOLEAN) {
boolean boolCellValue = cell.getBooleanCellValue();
booleanValue = new Boolean(boolCellValue);
} else {
if (cellType == Cell.CELL_TYPE_STRING) {
RichTextString richTextString = cell.getRichStringCellValue();
if (richTextString != null) {
String stringValue = richTextString.getString();
if (stringValue != null) {
stringValue = stringValue.trim();
if (!"".equals(stringValue)) {
if ("true".equalsIgnoreCase(stringValue) || BooleanFields.TRUE_VALUE.equalsIgnoreCase(stringValue)) {
booleanValue = new Boolean(true);
} else {
if ("false".equalsIgnoreCase(stringValue) || BooleanFields.FALSE_VALUE.equalsIgnoreCase(stringValue)) {
booleanValue = new Boolean(false);
} else {
if (stringValue != null && !"".equals(stringValue.trim())) {
throw new ExcelImportInvalidCellValueException(stringValue);
}
}
}
}
}
}
} else {
throw new ExcelImportInvalidCellValueException(getStringCellValue(cell));
}
}
return booleanValue;
}
示例8: getCommentTopic
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
public Topic getCommentTopic(Cell cell, TopicMap tm) throws TopicMapException {
Comment comment = cell.getCellComment();
if(comment != null) {
RichTextString rts = comment.getString();
String str = rts.getString();
String basename = str.replace('\n', ' ');
basename = basename.replace('\r', ' ');
basename = basename.replace('\t', ' ');
Topic topic=getOrCreateTopic(tm, EXCEL_COMMENT_SI_PREFIX+"/"+urlEncode(basename), basename);
topic.setData(getCommentTypeTopic(tm), tm.getTopic(XTMPSI.getLang(DEFAULT_LANG)), str);
topic.addType(getCommentTypeTopic(tm));
return topic;
}
return null;
}
示例9: validateAttributes
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Validates the attributes for this <code>Tag</code>. This tag must be
* bodiless.
*/
@SuppressWarnings("unchecked")
public void validateAttributes() throws TagParseException
{
super.validateAttributes();
if (!isBodiless())
throw new TagParseException("Formula tags must not have a body.");
TagContext context = getContext();
Map<String, Object> beans = context.getBeans();
Map<String, RichTextString> attributes = getAttributes();
RichTextString formulaBean = attributes.get(ATTR_BEAN);
RichTextString formulaText = attributes.get(ATTR_TEXT);
AttributeUtil.ensureExactlyOneExists(Arrays.asList(formulaBean, formulaText), Arrays.asList(ATTR_BEAN, ATTR_TEXT));
if (formulaBean != null)
{
myFormulaExpression = Expression.evaluateString("${" + formulaBean.toString() + "}", beans).toString();
}
else if (formulaText != null)
{
myFormulaExpression = attributes.get(ATTR_TEXT).getString();
}
if (DEBUG)
System.err.println("myFormulaExpression = " + myFormulaExpression);
RichTextString rtsIfError = attributes.get(ATTR_IF_ERROR);
myIfErrorExpression = (rtsIfError != null) ? rtsIfError.getString() : null;
}
示例10: validateAttributes
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Validates the attributes for this <code>Tag</code>. This tag must be
* bodiless.
*/
@SuppressWarnings("unchecked")
public void validateAttributes() throws TagParseException
{
super.validateAttributes();
if (!isBodiless())
throw new TagParseException("Comment tags must not have a body.");
TagContext context = getContext();
Map<String, Object> beans = context.getBeans();
Map<String, RichTextString> attributes = getAttributes();
myValue = attributes.get(ATTR_VALUE);
myAuthor = attributes.get(ATTR_AUTHOR).getString();
myComment = attributes.get(ATTR_COMMENT);
RichTextString rtsVisible = attributes.get(ATTR_VISIBLE);
String attrVisible = (rtsVisible != null) ? rtsVisible.getString() : null;
if (attrVisible != null)
{
Object test = Expression.evaluateString(attrVisible, beans);
if (test instanceof Boolean)
amIVisible = (Boolean) test;
else
amIVisible = Boolean.parseBoolean(test.toString());
}
}
示例11: formatString
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Format a <code>RichTextString</code> that has already been created.
* @param string A <code>RichTextString</code>.
* @param numFormattingRuns The number of formatting runs.
* @param formattingRuns A <code>List</code> of <code>FormattingRuns</code>.
*/
public static void formatString(RichTextString string, int numFormattingRuns,
List<FormattingRun> formattingRuns)
{
// Apply the formatting runs.
for (int i = 0; i < numFormattingRuns; i++)
{
FormattingRun run = formattingRuns.get(i);
int begin = run.getBegin();
int end = begin + run.getLength();
Object font = run.getFont();
if (DEBUG)
{
System.err.println(" RTSU.cFS: Applying format (" + i + "): begin=" +
begin + ", length=" + run.getLength() + ", font=" + font +
" to string \"" + string.getString() + "\".");
}
if (string instanceof HSSFRichTextString)
string.applyFont(begin, end, (Short) font);
else if (string instanceof XSSFRichTextString)
{
if (font != null)
string.applyFont(begin, end, (XSSFFont) font);
}
else throw new IllegalArgumentException("Unexpected RichTextString type: " +
string.getClass().getName() + ": " + string.getString());
}
}
示例12: getFontOfFormattingRun
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Gets the font index of the specified formatting run in the given
* <code>RichTextString</code>.
* @param richTextString The <code>RichTextString</code>.
* @param fmtIndex The 0-based index of the formatting run.
* @return The font index. If HSSF, a <code>short</code>. If XSSF, an
* <code>XSSFFont</code>.
*/
private static Object getFontOfFormattingRun(RichTextString richTextString, int fmtIndex)
{
if (richTextString instanceof HSSFRichTextString)
{
return ((HSSFRichTextString) richTextString).getFontOfFormattingRun(fmtIndex);
}
else if (richTextString instanceof XSSFRichTextString)
{
try
{
// Instead of returning null, getFontOfFormattingRun (eventually)
// throws a NullPointerException. It extracts a "CTRElt" from an
// array, and it extracts a "CTRPrElt" from the "CTRElt". The
// "CTRprElt" can be null if there is no font at the formatting
// run. Then, when creating a "CTFont", it calls a method on the
// null "CTRPrElt".
// Return the XSSFFont.
return ((XSSFRichTextString) richTextString).getFontOfFormattingRun(fmtIndex);
}
catch (NullPointerException e)
{
// Detect this case and return null.
if (DEBUG)
System.err.println(" NullPointerException caught!");
return null;
}
}
else
throw new IllegalArgumentException("Unexpected RichTextString type: " +
richTextString.getClass().getName() + ": " + richTextString.getString());
}
示例13: get
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
@Override
public Object get(Column column, Cell cell, Comment comment) {
RichTextString rich = comment.getString();
return rich.getString();
}
示例14: getStringCellValue
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
public String getStringCellValue() {
RichTextString str = getRichStringCellValue();
return str == null ? null : str.getString();
}
示例15: substring
import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
* Extracts a substring of a <code>RichTextString</code> as another
* <code>RichTextString</code>. Preserves the formatting that is in place
* from the given string.
* @param richTextString The <code>RichTextString</code> of which to take a
* substring.
* @param helper A <code>CreationHelper</code> that can create the proper
* <code>RichTextString</code>.
* @param beginIndex The beginning index, inclusive.
* @param endIndex The ending index, exclusive.
* @return The specified substring as a <code>RichTextString</code>, with
* the original formatting from the original string intact.
* @since 0.2.0
*/
public static RichTextString substring(RichTextString richTextString,
CreationHelper helper, int beginIndex, int endIndex)
{
int numFormattingRuns = richTextString.numFormattingRuns();
String value = richTextString.getString();
if (DEBUG)
System.err.println("RTSU.substring: \"" + value + "\" (" + value.length() +
"): numFormattingRuns=" + numFormattingRuns + ", beginIndex: " + beginIndex +
", endIndex: " + endIndex);
List<FormattingRun> formattingRuns = determineFormattingRunStats(richTextString);
// Determine which runs apply in the new substring's range.
List<FormattingRun> substrFormattingRuns = new ArrayList<FormattingRun>();
int begin, end;
for (int i = 0; i < numFormattingRuns; i++)
{
FormattingRun run = formattingRuns.get(i);
begin = run.getBegin();
end = begin + run.getLength();
if ((begin < beginIndex && end < beginIndex) ||
(begin >= endIndex && end >= endIndex))
{
// Not copied to the new substring.
continue;
}
if (begin < beginIndex && end >= beginIndex)
{
// Partial cover at beginning.
begin = beginIndex;
}
if (begin < endIndex && end >= endIndex)
{
// Partial cover at end.
end = endIndex;
}
substrFormattingRuns.add(new FormattingRun(begin - beginIndex, end - begin, run.getFont()));
}
return createFormattedString(substrFormattingRuns.size(), helper, value.substring(beginIndex, endIndex),
substrFormattingRuns);
}