本文整理汇总了Java中org.apache.poi.ss.usermodel.RichTextString类的典型用法代码示例。如果您正苦于以下问题:Java RichTextString类的具体用法?Java RichTextString怎么用?Java RichTextString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RichTextString类属于org.apache.poi.ss.usermodel包,在下文中一共展示了RichTextString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setComment
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* See the comment for the given cell
*
* @param cell
* the cell
* @param message
* the comment message
*/
public static void setComment(HSSFCell cell, String message) {
Drawing drawing = cell.getSheet().createDrawingPatriarch();
CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
// When the comment box is visible, have it show in a 1x3 space
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + 1);
anchor.setRow1(cell.getRowIndex());
anchor.setRow2(cell.getRowIndex() + 1);
anchor.setDx1(100);
anchor.setDx2(1000);
anchor.setDy1(100);
anchor.setDy2(1000);
// Create the comment and set the text+author
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString(message);
comment.setString(str);
comment.setAuthor("TURNUS");
// Assign the comment to the cell
cell.setCellComment(comment);
}
示例2: set
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
@Override
public Cell set(RichText s) {
s = getWorkbook().cache(s);
Object old = get();
RichTextString richText = getWorkbook().createRichTextString(s.toString());
for (Run run : s) {
PoiFont font = getWorkbook().getPoiFont(getCellStyle().getFont(), run.getAttributes());
richText.applyFont(run.getStart(), run.getEnd(), font.getPoiFont());
}
poiCell.setCellValue(richText);
updateRow();
valueChanged(old, s);
return this;
}
示例3: createCellComment
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
private Comment createCellComment(String author, String comment) {
// comments only supported for XLSX
if (data.sheet instanceof XSSFSheet) {
CreationHelper factory = data.wb.getCreationHelper();
Drawing drawing = data.sheet.createDrawingPatriarch();
ClientAnchor anchor = factory.createClientAnchor();
Comment cmt = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString(comment);
cmt.setString(str);
cmt.setAuthor(author);
return cmt;
}
return null;
}
示例4: validateAttributes
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Validates the attributes for this <code>Tag</code>. This tag must have a
* body.
*/
@SuppressWarnings("unchecked")
public void validateAttributes() throws TagParseException
{
super.validateAttributes();
if (isBodiless())
throw new TagParseException("Group tags must have a body.");
TagContext context = getContext();
Map<String, Object> beans = context.getBeans();
Map<String, RichTextString> attributes = getAttributes();
String groupDir = AttributeUtil.evaluateStringSpecificValues(attributes.get(ATTR_GROUP_DIR), beans, ATTR_GROUP_DIR,
Arrays.asList(GROUP_DIR_ROWS, GROUP_DIR_COLS, GROUP_DIR_NONE), GROUP_DIR_ROWS);
if (GROUP_DIR_ROWS.equals(groupDir))
myGroupDir = Block.Direction.VERTICAL;
else if (GROUP_DIR_COLS.equals(groupDir))
myGroupDir = Block.Direction.HORIZONTAL;
else if (GROUP_DIR_NONE.equals(groupDir))
myGroupDir = Block.Direction.NONE;
amICollapsed = AttributeUtil.evaluateBoolean(attributes.get(ATTR_COLLAPSE), beans, false);
}
示例5: validateAttributes
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Validates the attributes for this <code>Tag</code>. This tag must be
* bodiless. The type must be valid.
*/
@SuppressWarnings("unchecked")
public void validateAttributes() throws TagParseException
{
super.validateAttributes();
if (!isBodiless())
throw new TagParseException("Hyperlink tags must not have a body.");
TagContext context = getContext();
Map<String, Object> beans = context.getBeans();
Map<String, RichTextString> attributes = getAttributes();
String type = AttributeUtil.evaluateStringSpecificValues(attributes.get(ATTR_TYPE), beans, ATTR_TYPE,
Arrays.asList(TYPE_URL, TYPE_EMAIL, TYPE_FILE, TYPE_DOC), TYPE_URL);
if (TYPE_URL.equals(type))
myLinkType = Hyperlink.LINK_URL;
else if (TYPE_EMAIL.equals(type))
myLinkType = Hyperlink.LINK_EMAIL;
else if (TYPE_FILE.equals(type))
myLinkType = Hyperlink.LINK_FILE;
else if (TYPE_DOC.equals(type))
myLinkType = Hyperlink.LINK_DOCUMENT;
myAddress = AttributeUtil.evaluateStringNotNull(attributes.get(ATTR_ADDRESS), beans, ATTR_ADDRESS, null);
myValue = attributes.get(ATTR_VALUE);
}
示例6: validateAttributes
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Validates the attributes for this <code>Tag</code>. Some optional
* attributes are only valid for bodiless tags, and others are only valid
* for tags without bodies.
*/
public void validateAttributes()
{
super.validateAttributes();
TagContext context = getContext();
Map<String, Object> beans = context.getBeans();
Map<String, RichTextString> attributes = getAttributes();
Block block = context.getBlock();
if (!isBodiless())
throw new TagParseException("SpanTag: Must be bodiless");
myValue = attributes.get(ATTR_VALUE);
List<RichTextString> atLeastOne = Arrays.asList(attributes.get(ATTR_FACTOR), attributes.get(ATTR_ADJUST));
AttributeUtil.ensureAtLeastOneExists(atLeastOne, Arrays.asList(ATTR_FACTOR, ATTR_ADJUST));
myFactor = AttributeUtil.evaluateNonNegativeInt(attributes.get(ATTR_FACTOR), beans, ATTR_FACTOR, 1);
myAdjust = AttributeUtil.evaluateInt(attributes.get(ATTR_ADJUST), beans, ATTR_ADJUST, 0);
boolean explicitlyExpandingRight = AttributeUtil.evaluateBoolean(attributes.get(ATTR_EXPAND_RIGHT), beans, false);
if (explicitlyExpandingRight)
block.setDirection(Block.Direction.HORIZONTAL);
else
block.setDirection(Block.Direction.VERTICAL);
}
示例7: validateAttributes
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Validates the attributes for this <code>Tag</code>. Some optional
* attributes are only valid for bodiless tags, and others are only valid
* for tags without bodies.
*/
public void validateAttributes()
{
super.validateAttributes();
TagContext context = getContext();
Map<String, Object> beans = context.getBeans();
Map<String, RichTextString> attributes = getAttributes();
Block block = context.getBlock();
String elseAction = AttributeUtil.evaluateStringSpecificValues(attributes.get(ATTR_ELSE_ACTION), beans,
ATTR_ELSE_ACTION,
Arrays.asList(ELSE_ACTION_SHIFT_UP, ELSE_ACTION_SHIFT_LEFT, ELSE_ACTION_CLEAR, ELSE_ACTION_REMOVE),
ELSE_ACTION_SHIFT_UP);
if (elseAction != null)
{
if (ELSE_ACTION_SHIFT_UP.equalsIgnoreCase(elseAction))
block.setDirection(Block.Direction.VERTICAL);
else if (ELSE_ACTION_SHIFT_LEFT.equalsIgnoreCase(elseAction))
block.setDirection(Block.Direction.HORIZONTAL);
else if (ELSE_ACTION_CLEAR.equalsIgnoreCase(elseAction) ||
ELSE_ACTION_REMOVE.equalsIgnoreCase(elseAction))
block.setDirection(Block.Direction.NONE);
myElseAction = elseAction;
}
}
示例8: validateAttributes
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Validates the attributes for this <code>Tag</code>. The "start", "end",
* and "step" attributes must evaluate to <code>int</code>s. If "step" is
* not present, then it defaults to <code>1</code>. The "step" must not be
* zero. It is possible for no loops to be processed if "step" is positive
* and "start" is greater than "end", or if "step" is negative and "start"
* is less than "end".
*/
@Override
public void validateAttributes() throws TagParseException
{
super.validateAttributes();
if (isBodiless())
throw new TagParseException("For tags must have a body.");
TagContext context = getContext();
Map<String, Object> beans = context.getBeans();
Map<String, RichTextString> attributes = getAttributes();
myVarName = AttributeUtil.evaluateString(attributes.get(ATTR_VAR), beans, null);
myStart = AttributeUtil.evaluateInt(attributes.get(ATTR_START), beans, ATTR_START, 0);
myEnd = AttributeUtil.evaluateInt(attributes.get(ATTR_END), beans, ATTR_END, 0);
myStep = AttributeUtil.evaluateNonZeroInt(attributes.get(ATTR_STEP), beans, ATTR_STEP, 1);
}
示例9: validateAttributes
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Validates the attributes for this <code>Tag</code>. The "items"
* attribute must be a <code>List</code>. The "parallel" attribute must be
* a positive integer (defaults to 1). The "value" attribute must be a
* valid <code>Aggregator</code> specification string. The "total" tag must
* not have a body.
*/
@SuppressWarnings("unchecked")
public void validateAttributes() throws TagParseException
{
super.validateAttributes();
if (!isBodiless())
throw new TagParseException("Total tags must not have a body.");
TagContext context = getContext();
Map<String, Object> beans = context.getBeans();
Map<String, RichTextString> attributes = getAttributes();
myList = AttributeUtil.evaluateObject(attributes.get(ATTR_ITEMS), beans, ATTR_ITEMS, List.class,
new ArrayList<Object>(0));
myParallelism = AttributeUtil.evaluatePositiveInt(attributes.get(ATTR_PARALLEL), beans, ATTR_PARALLEL, 1);
String aggSpec = AttributeUtil.evaluateString(attributes.get(ATTR_VALUE), beans, null);
myAggregator = Aggregator.getAggregator(aggSpec);
}
示例10: 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);
}
}
示例11: replaceExpressions
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Replace all expressions with their evaluated results. This attempts to
* preserve any formatting within the <code>RichTextString</code>.
* @param richTextString The entire string, with possibly many expressions
* and possibly embedded formatting.
* @param helper A <code>CreationHelper</code> that can create the proper
* <code>RichTextString</code>.
* @param expressions A <code>List</code> of <code>Expressions</code>.
* @param beans A <code>Map</code> of beans to provide context for the
* <code>Expressions</code>.
* @return A <code>RichTextString</code> with all expressions replaced with
* their evaluated results, and formatted preserved as best as possible.
*/
private static RichTextString replaceExpressions(RichTextString richTextString,
CreationHelper helper, List<Expression> expressions, Map<String, Object> beans)
{
ArrayList<String> exprStrings = new ArrayList<String>(expressions.size());
ArrayList<String> exprValues = new ArrayList<String>(expressions.size());
for (Expression expr : expressions)
{
exprStrings.add(BEGIN_EXPR + expr.myExpression + END_EXPR);
Object result = expr.evaluate(beans);
if (result != null)
exprValues.add(result.toString());
else
exprValues.add("");
}
return RichTextStringUtil.replaceValues(richTextString, helper, exprStrings, exprValues);
}
示例12: evaluateInt
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Evaluates the given text, which may have embedded
* <code>Expressions</code>, and attempts to extract an integer value from
* the result, calling <code>toString()</code> on the result and parsing it
* if necessary. If the text is null, then the result defaults to the given
* default integer value.
* @param text Text which may have embedded <code>Expressions</code>.
* @param beans A <code>Map</code> of bean names to bean values.
* @param attrName The attribute name. This is only used when constructing
* an exception message.
* @param def The default value if the text is null.
* @return The integer result.
* @throws TagParseException If the result of the evaluation of the text is
* not a number.
*/
public static int evaluateInt(RichTextString text, Map<String, Object> beans, String attrName, int def)
{
int result;
if (text == null)
return def;
Object obj = Expression.evaluateString(text.toString(), beans);
if (obj instanceof Number)
{
result = ((Number) obj).intValue();
}
else
{
try
{
result = Integer.parseInt(obj.toString());
}
catch (NumberFormatException e)
{
throw new TagParseException("The \"" + attrName + "\" attribute must be an integer: " + text);
}
}
return result;
}
示例13: evaluateDouble
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Evaluates the given text, which may have embedded
* <code>Expressions</code>, and attempts to extract a double value from
* the result, calling <code>toString()</code> on the result and parsing it
* if necessary.
* @param text Text which may have embedded <code>Expressions</code>.
* @param beans A <code>Map</code> of bean names to bean values.
* @param attrName The attribute name. This is only used when constructing
* an exception message.
* @param def The default value if the text is null.
* @return The double result.
* @throws TagParseException If the result of the evaluation of the text is
* not a number.
*/
public static double evaluateDouble(RichTextString text, Map<String, Object> beans, String attrName, double def)
{
double result;
if (text == null)
return def;
Object obj = Expression.evaluateString(text.toString(), beans);
if (obj instanceof Number)
{
result = ((Number) obj).doubleValue();
}
else
{
try
{
result = Double.parseDouble(obj.toString());
}
catch (NumberFormatException e)
{
throw new TagParseException("The \"" + attrName + "\" attribute must be a number: " + text);
}
}
return result;
}
示例14: evaluateList
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Evaluates the given text, which may have embedded
* <code>Expressions</code>, and attempts to extract a <code>List</code> out
* of the result, parsing a delimited list to create a list if necessary.
* @param text Text which may have embedded <code>Expressions</code>.
* @param beans A <code>Map</code> of bean names to bean values.
* @param def The default value if the text is null.
* @return A <code>List</code>.
*/
public static List<String> evaluateList(RichTextString text, Map<String, Object> beans, List<String> def)
{
List<String> result;
if (text == null)
return def;
Object obj = Expression.evaluateString(text.toString(), beans);
if (obj instanceof List)
{
List list = (List) obj;
result = new ArrayList<String>(list.size());
for (Object item : list)
result.add(item.toString());
}
else
{
String[] items = obj.toString().split(SPEC_SEP);
result = Arrays.asList(items);
}
return result;
}
示例15: ensureExactlyOneExists
import org.apache.poi.ss.usermodel.RichTextString; //导入依赖的package包/类
/**
* Ensures that exactly one of the given attribute values exists.
* @param attrValues A <code>List</code> of attribute values.
* @param attrNames A <code>List</code> of attribute names.
* @throws TagParseException If none of the attribute values is not null, or
* if more than one attribute value is not null.
*/
public static void ensureExactlyOneExists(List<RichTextString> attrValues, List<String> attrNames)
{
int exists = 0;
for (RichTextString text : attrValues)
{
if (text != null)
{
exists++;
if (exists > 1)
{
throw new TagParseException("Exactly one attribute must be specified: " + attrNames.toString());
}
}
}
if (exists != 1)
{
throw new TagParseException("Exactly one attribute must be specified: " + attrNames.toString());
}
}