gpt4 book ai didi

org.apache.poi.xslf.usermodel.XSLFTextRun类的使用及代码示例

转载 作者:知者 更新时间:2024-03-22 08:09:05 30 4
gpt4 key购买 nike

本文整理了Java中org.apache.poi.xslf.usermodel.XSLFTextRun类的一些代码示例,展示了XSLFTextRun类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XSLFTextRun类的具体详情如下:
包路径:org.apache.poi.xslf.usermodel.XSLFTextRun
类名称:XSLFTextRun

XSLFTextRun介绍

[英]Represents a run of text within the containing text body. The run element is the lowest level text separation mechanism within a text body.
[中]表示包含文本正文中的一段文本。run元素是文本体中最低级别的文本分离机制。

代码示例

代码示例来源:origin: org.apache.poi/poi-ooxml

void copy(XSLFTextRun r){
  String srcFontFamily = r.getFontFamily();
  if(srcFontFamily != null && !srcFontFamily.equals(getFontFamily())){
    setFontFamily(srcFontFamily);
  PaintStyle srcFontColor = r.getFontColor();
  if(srcFontColor != null && !srcFontColor.equals(getFontColor())){
    setFontColor(srcFontColor);
  Double srcFontSize = r.getFontSize();
  if (srcFontSize == null) {
    if (getFontSize() != null) setFontSize(null);
  } else if(!srcFontSize.equals(getFontSize())) {
    setFontSize(srcFontSize);
  boolean bold = r.isBold();
  if(bold != isBold()) {
    setBold(bold);
  boolean italic = r.isItalic();
  if(italic != isItalic()) {
    setItalic(italic);
  boolean underline = r.isUnderlined();
  if(underline != isUnderlined()) {
    setUnderlined(underline);
  boolean strike = r.isStrikethrough();
  if(strike != isStrikethrough()) {
    setStrikethrough(strike);

代码示例来源:origin: org.apache.poi/poi-ooxml

@Override
public String toString(){
  return "[" + getClass() + "]" + getRawText();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

firstPara = !newParagraph;
para = _paragraphs.get(_paragraphs.size() - 1);
CTTextParagraph ctp = para.getXmlObject();
otherPPr = ctp.getPPr();
List<XSLFTextRun> runs = para.getTextRuns();
if (!runs.isEmpty()) {
  XSLFTextRun r0 = runs.get(runs.size() - 1);
  otherRPr = r0.getRPr(false);
  if (otherRPr == null) {
    otherRPr = ctp.getEndParaRPr();
if (!firstPara) {
  if (para != null) {
    CTTextParagraph ctp = para.getXmlObject();
    CTTextCharacterProperties unexpectedRPr = ctp.getEndParaRPr();
    if (unexpectedRPr != null && unexpectedRPr != otherRPr) {
  run = para.addNewTextRun();
  run.setText(runText);
  if (otherRPr != null) {
    run.getRPr(true).set(otherRPr);

代码示例来源:origin: stackoverflow.com

Color fontColor = null;
String fontFamily = null;
double fontSize = 0.0;
boolean italic = false;
boolean bold = false;
boolean underline = false;
for (XSLFTextParagraph paragraph : autoShape.getTextParagraphs()) {
  for (XSLFTextRun text : paragraph.getTextRuns()) {
    fontColor = text.getFontColor();
    fontFamily = text.getFontFamily();
    fontSize = text.getFontSize();
    italic = text.isItalic();
    bold = text.isBold();
    underline = text.isUnderline();
  }
}
autoShape.clearText();
XSLFTextParagraph addNewTextParagraph = autoShape.addNewTextParagraph();

XSLFTextRun addNewTextRun = addNewTextParagraph.addNewTextRun();
addNewTextRun.setText(values.get(0)[1]);
addNewTextRun.setFontColor(fontColor);
addNewTextRun.setFontFamily(fontFamily);
addNewTextRun.setFontSize(fontSize);
addNewTextRun.setItalic(italic);
addNewTextRun.setBold(bold);
addNewTextRun.setUnderline(underline);

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

void copy(XSLFTextRun r){
    String srcFontFamily = r.getFontFamily();
    if(srcFontFamily != null && !srcFontFamily.equals(getFontFamily())){
      setFontFamily(srcFontFamily);
    }

    Color srcFontColor = r.getFontColor();
    if(srcFontColor != null && !srcFontColor.equals(getFontColor())){
      setFontColor(srcFontColor);
    }

    double srcFontSize = r.getFontSize();
    if(srcFontSize  != getFontSize()){
      setFontSize(srcFontSize);
    }

    boolean bold = r.isBold();
    if(bold != isBold()) setBold(bold);

    boolean italic = r.isItalic();
    if(italic != isItalic()) setItalic(italic);

    boolean underline = r.isUnderline();
    if(underline != isUnderline()) setUnderline(underline);

    boolean strike = r.isStrikethrough();
    if(strike != isStrikethrough()) setStrikethrough(strike);
  }
}

代码示例来源:origin: org.apache.poi/poi-examples

XSLFTextShape tsh = (XSLFTextShape) shape;
for (XSLFTextParagraph p : tsh) {
  System.out.println("Paragraph level: " + p.getIndentLevel());
  for (XSLFTextRun r : p) {
    System.out.println(r.getRawText());
    System.out.println("  bold: " + r.isBold());
    System.out.println("  italic: " + r.isItalic());
    System.out.println("  underline: " + r.isUnderlined());
    System.out.println("  font.family: " + r.getFontFamily());
    System.out.println("  font.size: " + r.getFontSize());
    System.out.println("  font.color: " + r.getFontColor());

代码示例来源:origin: stackoverflow.com

XSLFTableRow titleRow = tbl.addRow();
titleRow.setHeight(50);
XSLFTableCell titleCell1 = titleRow.addCell();
XSLFTextParagraph p1 = titleCell1.addNewTextParagraph();
p1.setTextAlign(TextAlign.CENTER);
XSLFTextRun r1 = p1.addNewTextRun();
r1.setText("Column title");
r1.setBold(true);
r1.setFontColor(new Color(0, 104, 145));
titleCell1.setFillColor(new Color(190, 230, 245));
r1.setFontSize(25.0);
titleCell1.setVerticalAlignment(VerticalAlignment.MIDDLE);

代码示例来源:origin: org.apache.poi/poi-examples

p1.setIndentLevel(0);
p1.setBullet(true);
XSLFTextRun r1 = p1.addNewTextRun();
r1.setText("Bullet1");
p2.setIndentLevel(1);
XSLFTextRun r2 = p2.addNewTextRun();
r2.setText("Bullet2");
p3.setIndentLevel(2);
XSLFTextRun r3 = p3.addNewTextRun();
r3.setText("Numbered List Item - 1");
p4.setIndentLevel(2);
XSLFTextRun r4 = p4.addNewTextRun();
r4.setText("Numbered List Item - 2");
p5.setIndentLevel(2);
XSLFTextRun r5 = p5.addNewTextRun();
r5.setText("Numbered List Item - 3");

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

int length = run.getRenderableText().length();
if(length == 0) {
string.addAttribute(TextAttribute.FOREGROUND, run.getFontColor(), startIndex, endIndex);
String fontFamily = run.getFontFamily();
if(fontHandler != null) {
  fontFamily = fontHandler.getRendererableFont(fontFamily, run.getPitchAndFamily());
float fontSz = (float)run.getFontSize();
string.addAttribute(TextAttribute.SIZE, fontSz , startIndex, endIndex);
if(run.isBold()) {
  string.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIndex, endIndex);
if(run.isItalic()) {
  string.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIndex, endIndex);
if(run.isUnderline()) {
  string.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, startIndex, endIndex);
  string.addAttribute(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_TWO_PIXEL, startIndex, endIndex);
if(run.isStrikethrough()) {
  string.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, startIndex, endIndex);
if(run.isSubscript()) {
  string.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB, startIndex, endIndex);
if(run.isSuperscript()) {

代码示例来源:origin: stackoverflow.com

XSLFTextParagraph par = tb.addNewTextParagraph();
tb.setVerticalAlignment(VerticalAlignment.DISTRIBUTED);
par.setTextAlign(TextAlign.CENTER);
XSLFTextRun run = par.addNewTextRun();
run.setText("unicode ->\u30B4\u30DF\u7BB1<-");
run.setFontFamily("GE Inspira");
run.setFontSize(12.0);
return ss;

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

if(_runs.size() == 0) ensureNotEmpty();
String text = getRenderableText();
if(text.length() == 0) return _lines;
AttributedString at = getAttributedString(graphics);
AttributedCharacterIterator it = at.getIterator();
LineBreakMeasurer measurer = new LineBreakMeasurer(it, graphics.getFontRenderContext())  ;
  String buCharacter = getBulletCharacter();
  String buFont = getBulletFont();
  if(buFont == null) buFont = getTextRuns().get(0).getFontFamily();
  if(buCharacter != null && buFont != null && _lines.size() > 0) {
    AttributedString str = new AttributedString(buCharacter);

代码示例来源:origin: org.apache.poi/poi-examples

XSLFTextRun r1 = p1.addNewTextRun();
r1.setText("Paragraph Formatting");
r1.setFontSize(24d);
r1.setFontColor(new Color(85, 142, 213));
p2.setSpaceBefore(-20d); // 20 pt from the previous paragraph
p2.setSpaceAfter(300d); // 3 lines after the paragraph
XSLFTextRun r2 = p2.addNewTextRun();
r2.setText("Paragraph  properties apply to all text residing within the corresponding paragraph.");
r2.setFontSize(16d);
XSLFTextRun r3 = p3.addNewTextRun();
r3.setText("Run Formatting");
r3.setFontSize(24d);
r3.setFontColor(new Color(85, 142, 213));
p4.setSpaceAfter(300d); // 3 lines after the paragraph
XSLFTextRun r4 = p4.addNewTextRun();
r4.setFontSize(16d);
r4.setText(
    "Run level formatting is the most granular property level and allows " +
        "for the specifying of all low level text properties. The text run is " +

代码示例来源:origin: stackoverflow.com

XSLFTextRun run1 = p.addNewTextRun(); 
   run1.setText("This is test"); 
   run1.setFontFamily(HSSFFont.FONT_ARIAL);
   run1.setFontColor(Color.red);    
   run1.setFontSize(24);

代码示例来源:origin: apache/tika

for (XSLFTextParagraph p : txt.getTextParagraphs()) {
  xhtml.startElement("p");
  if (! config.getIncludeHeadersAndFooters() && p.isHeaderOrFooter()) {
    continue;
  for (XSLFTextRun run : p.getTextRuns()) {
    Hyperlink hyperlink = run.getHyperlink();
      inHyperlink = true;
    xhtml.characters(run.getRawText());
    if (inHyperlink == true) {
      xhtml.endElement("a");

代码示例来源:origin: stackoverflow.com

textShape.clearText();
XSLFTextParagraph p = textShape.addNewTextParagraph();
XSLFTextRun r1 = p.addNewTextRun();
r1.setText("The");
r1.setFontColor(Color.blue);
r1.setFontSize(24.);

代码示例来源:origin: stackoverflow.com

XSLFTextShape[] phs = slide[i].getPlaceholders();
for (XSLFTextShape ts : phs) {
 java.util.List<XSLFTextParagraph> tpl = ts.getTextParagraphs();
 for(XSLFTextParagraph tp: tpl) {
  java.util.List<XSLFTextRun> trs = tp.getTextRuns();
  for(XSLFTextRun tr: trs) {
   logger.info(tr.getFontFamily());
   tr.setFontFamily("SimSun");
  }
 }
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 *  ensure that the paragraph contains at least one character.
 *  We need this trick to correctly measure text
 */
private void ensureNotEmpty(){
  XSLFTextRun r = addNewTextRun();
  r.setText(" ");
  CTTextCharacterProperties endPr = _p.getEndParaRPr();
  if(endPr != null) {
    if(endPr.isSetSz()) r.setFontSize(endPr.getSz() / 100);
  }
}

代码示例来源:origin: stackoverflow.com

XSLFTableRow headerRow = table.addRow();
 for(int i = 0; i < 3; i++) {
   XSLFTableCell th = headerRow.addCell();
   XSLFTextParagraph p = th.addNewTextParagraph();
   XSLFTextRun r = p.addNewTextRun();
   r.setText("Text");
 }

代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-parsers

xhtml.startElement("p");
for (XSLFTextRun run : p.getTextRuns()) {
  Hyperlink hyperlink = run.getHyperlink();
    inHyperlink = true;
  xhtml.characters(run.getRawText());
  if (inHyperlink == true) {
    xhtml.endElement("a");

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * Replace a tab with the effective number of white spaces.
 *
 * @return
 */
private String tab2space(){
  AttributedString string = new AttributedString(" ");
  // user can pass an object to convert fonts via a rendering hint
  string.addAttribute(TextAttribute.FAMILY, getFontFamily());
  string.addAttribute(TextAttribute.SIZE, (float)getFontSize());
  TextLayout l = new TextLayout(string.getIterator(), new FontRenderContext(null, true, true));
  double wspace = l.getAdvance();
  double tabSz = _p.getDefaultTabSize();
  int numSpaces = (int)Math.ceil(tabSz / wspace);
  StringBuffer buf = new StringBuffer();
  for(int i = 0; i < numSpaces; i++) {
    buf.append(' ');
  }
  return buf.toString();
}

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com