当前位置: 首页>>代码示例>>Java>>正文


Java RichTextString.applyFont方法代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.RichTextString.applyFont方法的典型用法代码示例。如果您正苦于以下问题:Java RichTextString.applyFont方法的具体用法?Java RichTextString.applyFont怎么用?Java RichTextString.applyFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.ss.usermodel.RichTextString的用法示例。


在下文中一共展示了RichTextString.applyFont方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:xzel23,项目名称:meja,代码行数:19,代码来源:PoiCell.java

示例2: testGetCellValueObject

import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
@Test
public void testGetCellValueObject ()
{
  for (final EExcelVersion eVersion : EExcelVersion.values ())
  {
    final Workbook aWB = eVersion.createWorkbook ();
    final Sheet aSheet = aWB.createSheet ();
    final Row aRow = aSheet.createRow (0);
    final Cell aCell = aRow.createCell (0);

    // boolean
    aCell.setCellValue (true);
    assertEquals (Boolean.TRUE, ExcelReadHelper.getCellValueObject (aCell));

    // int
    aCell.setCellValue (4711);
    assertEquals (Integer.valueOf (4711), ExcelReadHelper.getCellValueObject (aCell));

    // long
    aCell.setCellValue (Long.MAX_VALUE);
    assertEquals (Long.valueOf (Long.MAX_VALUE), ExcelReadHelper.getCellValueObject (aCell));

    // double
    aCell.setCellValue (3.11234);
    assertEquals (Double.valueOf (3.11234), ExcelReadHelper.getCellValueObject (aCell));

    // String
    aCell.setCellValue ("Anyhow");
    assertEquals ("Anyhow", ExcelReadHelper.getCellValueObject (aCell));

    // Rich text string
    final Font aFont = aWB.createFont ();
    aFont.setItalic (true);
    final RichTextString aRTS = eVersion.createRichText ("Anyhow");
    aRTS.applyFont (1, 3, aFont);
    aCell.setCellValue (aRTS);
    assertEquals ("Anyhow", ExcelReadHelper.getCellValueObject (aCell));
  }
}
 
开发者ID:phax,项目名称:ph-poi,代码行数:40,代码来源:ExcelReadHelperTest.java

示例3: 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());
   }
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:34,代码来源:RichTextStringUtil.java

示例4: set

import org.apache.poi.ss.usermodel.RichTextString; //导入方法依赖的package包/类
/**
 * 保持している情報を元に、シートのセルにコメントを設定する。
 * @param sheet
 * @return POIの設定したコメントオブジェクト。
 * @throws IllegalArgumentException sheet is null.
 */
public Comment set(final Sheet sheet) {
    ArgUtils.notNull(sheet, "sheet");
    
    final CreationHelper helper = sheet.getWorkbook().getCreationHelper();
    final Drawing drawing = sheet.createDrawingPatriarch();
    
    // コメントの位置、サイズの指定
    int col1 = column + 1;
    int row1 = row;
    
    if(sheet instanceof HSSFSheet) {
        // 2003形式の場合は、行の位置をずらす。
        row1--;
    }
    
    int col2 = col1 + anchor.columnSize;
    int row2 = row1 + anchor.rowSize;
    final ClientAnchor clientAnchor = drawing.createAnchor(
            anchor.dx1, anchor.dy1, anchor.dx2, anchor.dy2,
            col1, row1, col2, row2
            );
    POIUtils.setClientAnchorType(clientAnchor, anchor.type);
    
    final Comment comment = drawing.createCellComment(clientAnchor);
    comment.setColumn(column);
    comment.setRow(row);
    comment.setAuthor(author);
    comment.setVisible(visible);
    
    // 装飾を適用する。
    final RichTextString richText = helper.createRichTextString(text.text);
    if(text.fonts != null) {
        for(TextFontStore fontStore : text.fonts) {
            if(fontStore.font != null) {
                richText.applyFont(fontStore.startIndex, fontStore.endIndex, fontStore.font);
            } else {
                richText.applyFont(fontStore.startIndex, fontStore.endIndex, fontStore.fontIndex);
            }
        }
    }
    
    comment.setString(richText);
    
    return comment;
    
}
 
开发者ID:mygreen,项目名称:xlsmapper,代码行数:53,代码来源:CellCommentStore.java


注:本文中的org.apache.poi.ss.usermodel.RichTextString.applyFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。