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


Java XSSFRichTextString类代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFRichTextString的典型用法代码示例。如果您正苦于以下问题:Java XSSFRichTextString类的具体用法?Java XSSFRichTextString怎么用?Java XSSFRichTextString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XSSFRichTextString类属于org.apache.poi.xssf.usermodel包,在下文中一共展示了XSSFRichTextString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHtmlValue

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
public String getHtmlValue(Cell cell) {
    if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()
        || Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        cell.setCellType(Cell.CELL_TYPE_STRING);
        return cell.getStringCellValue();
    } else if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        if (cell.getRichStringCellValue().numFormattingRuns() == 0) {
            return XmlEscapers.xmlContentEscaper().escape(cell.getStringCellValue());
        } else if (is07) {
            return getXSSFRichString((XSSFRichTextString) cell.getRichStringCellValue());
        } else {
            return getHSSFRichString((HSSFRichTextString) cell.getRichStringCellValue());
        }
    }
    return "";
}
 
开发者ID:rushingpig,项目名称:poix,代码行数:17,代码来源:CellValueHelper.java

示例2: formattedContents

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
/**
 * Tries to format the contents of the last contents appropriately based on the type of cell and the discovered
 * numeric format.
 *
 * @return
 */
String formattedContents() {
    switch (currentCell.getType()) {
    case "s": // string stored in shared table
        int idx = Integer.parseInt(lastContents);
        return new XSSFRichTextString(sst.getEntryAt(idx)).toString();
    case "inlineStr": // inline string (not in sst)
        return new XSSFRichTextString(lastContents).toString();
    case "str": //
        return lastContents;
    case "e": // error type
        return StringUtils.EMPTY;// "ERROR:  " + lastContents;
    case "n": // numeric type
        if (currentCell.getNumericFormat() != null && lastContents.length() > 0) {
            return dataFormatter.formatRawCellContents(Double.parseDouble(lastContents), currentCell.getNumericFormatIndex(),
                    currentCell.getNumericFormat());
        } else {
            return lastContents;
        }
    default:
        return lastContents;
    }
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:29,代码来源:StreamingSheetReader.java

示例3: getXSSFRichString

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
/**
 * 07版本复杂数据
 * @param rich
 * @return
 */
private String getXSSFRichString(XSSFRichTextString rich) {
    int nums = rich.numFormattingRuns();
    StringBuilder sb = new StringBuilder();
    String text = rich.toString();
    int currentIndex = 0, lastIndex = 0;
    for (int i = 1; i <= nums; i++) {
        sb.append("<span ");
        try {
            sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1)));
            sb.append("_");
            sb.append(cssRandom);
            sb.append("'");
        } catch (Exception e) {
        }
        sb.append(">");
        currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length()
            : rich.getIndexOfFormattingRun(i);
        sb.append(
            XmlEscapers.xmlContentEscaper().escape(text.substring(lastIndex, currentIndex)));
        sb.append("</span>");
        lastIndex = currentIndex;
    }
    return sb.toString();
}
 
开发者ID:rushingpig,项目名称:poix,代码行数:30,代码来源:CellValueHelper.java

示例4: getXSSFRichString

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
/**
 * 07版本复杂数据
 * @param rich
 * @return
 */
private String getXSSFRichString(XSSFRichTextString rich) {
    int nums = rich.numFormattingRuns();
    StringBuilder sb = new StringBuilder();
    String text = rich.toString();
    int currentIndex = 0, lastIndex = 0;
    for (int i = 1; i <= nums; i++) {
        sb.append("<span ");
        try {
            sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1)));
            sb.append("_");
            sb.append(cssRandom);
            sb.append("'");
        } catch (Exception e) {
        }
        sb.append(">");
        currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich
            .getIndexOfFormattingRun(i);
        sb.append(XmlEscapers.xmlContentEscaper().escape(
            text.substring(lastIndex, currentIndex)));
        sb.append("</span>");
        lastIndex = currentIndex;
    }
    return sb.toString();
}
 
开发者ID:xiaolanglang,项目名称:easypoi,代码行数:30,代码来源:CellValueHelper.java

示例5: getFontAtIndex

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的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());
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:40,代码来源:RichTextStringUtil.java

示例6: testAddRow

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
@SuppressWarnings("resource")
@Test
public void testAddRow() {
  Calendar cal = Calendar.getInstance();
  Date date = new Date();
  writer.addRow("def");
  writer
      .addRow(null, true, cal, date, 1.1, new HSSFRichTextString("Hello!"),
          new XSSFRichTextString("World."), new HSSFWorkbook()
              .getCreationHelper().createHyperlink(HyperlinkType.URL),
          123, "abc");
  assertEquals("def", writer.getWorkbook().getSheetAt(0).rowIterator().next()
      .cellIterator().next().getStringCellValue());
  WorkbookWriter.openXLSX().addRow(new HSSFRichTextString("Hello!"),
      new XSSFRichTextString("World."));
  WorkbookWriter.openXLS().addRow(new HSSFRichTextString("Hello!"),
      new XSSFRichTextString("World."));

}
 
开发者ID:wnameless,项目名称:workbook-accessor,代码行数:20,代码来源:WorkbookWriterTest.java

示例7: createHeader

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
private void createHeader(Map<String, CellStyle> styles,
                          XSSFSheet sheet,
                          List<String> header) {
    final XSSFRow rowhead = sheet.createRow(0);

    int i = 0;
    for (String headerColumn : header) {
        rowhead.createCell(i).setCellValue(new XSSFRichTextString(headerColumn));
        rowhead.getCell(i).setCellStyle(styles.get("header"));
        i++;
    }
}
 
开发者ID:Dactilo,项目名称:spring-spreadsheet,代码行数:13,代码来源:ExcelStreamer.java

示例8: resolveValue

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
/**
 * Resolve the given value with respect to whether it is a reference to element in shared strings table.
 * Also decode the final value.
 *
 * @param value Value read in element.
 * @param lookupNextValueInSST Whether the value is an index into the shared strings table.
 * @return
 */
private String resolveValue(String value, boolean lookupNextValueInSST) {
  if(lookupNextValueInSST) {
    int idx = (int)Double.parseDouble(value);
    return new XSSFRichTextString(sst.getEntryAt(idx)).toString();
  }

  return new XSSFRichTextString(value).toString();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:StAXBasedParser.java

示例9: writeExcel

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
public static void writeExcel(HttpServletResponse response,List<String> list) throws Exception {
	response.setContentType("application/vnd.ms-excel");//文件格式,此处设置为excel
	response.setHeader("Content-Disposition","attachment;filename=file.xls");//此处设置了下载文件的默认名称
	ServletOutputStream sos = response.getOutputStream();
    //创建一个新的excel
	XSSFWorkbook wb = new XSSFWorkbook();//XSSFWorkbook
	/**
	 * 采用现成Excel模板
	 * 用这种方式得先保证每个cell有值,不然会报空指针
	 * 有时我们用row.getCell(i)会得到null,那么此时就要用Iterator<Cell> it = row.cellIterator();
	 * XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(new File("D://a.xlsx")));
	 * XSSFSheet sheet = wb.getSheet("Sheet1");
	 * row[i] = sheet.getRow(i);
	 * headerCell[j] = row[i].getCell(j);
	 */
	//创建sheet页
	XSSFSheet sheet = wb.createSheet("sheet1");//sheet名
	//创建行数
	XSSFRow[] row = new XSSFRow[list.size()];
	//插入数据
	for (int i = 0; i < row.length; i++) {
		row[i] = sheet.createRow(i);
		sheet.setDefaultColumnWidth(30);//设置列的长度
		String info[] = list.get(i).split(",");
		XSSFCell[] headerCell = new XSSFCell[info.length];
		for (int j = 0; j < headerCell.length; j++) {
			headerCell[j] = row[i].createCell(j);
			headerCell[j].setCellValue(new XSSFRichTextString(info[j]));
			/**设置模板样式*/
			//headerCell[j].setCellStyle(setStyle(wb));
		}
	}
	wb.write(sos);
	wb.close();
    sos.flush();
    sos.close();
    response.flushBuffer();
}
 
开发者ID:tank2140896,项目名称:JavaWeb,代码行数:39,代码来源:FileUtil.java

示例10: getFontForFormattingRun

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
private Font getFontForFormattingRun(RichTextString richText, int i) {
    if (richText instanceof HSSFRichTextString) {
        HSSFRichTextString hssfRichText = (HSSFRichTextString) richText;
        return ((PoiWorkbook.PoiHssfWorkbook) getWorkbook()).getFont(hssfRichText.getFontOfFormattingRun(i)).getFont();
    } else {
        return getWorkbook().getFont(((XSSFRichTextString) richText).getFontOfFormattingRun(i)).getFont();
    }
}
 
开发者ID:xzel23,项目名称:meja,代码行数:9,代码来源:PoiCell.java

示例11: handleInlineString

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
@Override
public void handleInlineString(XSSFCellStyle style, String inlineString) {
    XSSFRichTextString rtsi = new XSSFRichTextString(inlineString);
    rawValues.add(rtsi.toString().toUpperCase());
    formattedValues.add('"' + rtsi.toString() + '"');

}
 
开发者ID:iMDT,项目名称:xlsx-io,代码行数:8,代码来源:DefaultDataHandlerImpl.java

示例12: handleSharedStringsTableIndex

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
@Override
public void handleSharedStringsTableIndex(XSSFCellStyle style, String sharedStringsTableIndex) {
    try {
        int idx = Integer.parseInt(sharedStringsTableIndex);
        XSSFRichTextString rtss = new XSSFRichTextString(sharedStringsTable.getEntryAt(idx));
        rawValues.add(rtss.toString());
        formattedValues.add('"' + rtss.toString() + '"');

    } catch (NumberFormatException ex) {
        rawValues.add("ERROR");
        formattedValues.add("ERROR");
    }

}
 
开发者ID:iMDT,项目名称:xlsx-io,代码行数:15,代码来源:DefaultDataHandlerImpl.java

示例13: writeCoverSheet

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
public void writeCoverSheet(String projectName,String creatorName,
		String creatorEmail,String organizationName,String toolInfo) {
	
	sheet.getRow(ROW_10).getCell(COL_D).setCellValue(
			new XSSFRichTextString(projectName));
	sheet.getRow(ROW_10).getCell(COL_F).setCellValue(
			new XSSFRichTextString(DateUtil.getCurrentTime("%1$tY-%1$tm-%1$te (%1$ta)")));
	sheet.getRow(ROW_11).getCell(COL_D).setCellValue(
			new XSSFRichTextString(creatorEmail));
	sheet.getRow(ROW_12).getCell(COL_D).setCellValue(
			new XSSFRichTextString(organizationName));
	sheet.getRow(ROW_13).getCell(COL_D).setCellValue(
			new XSSFRichTextString(toolInfo));
}
 
开发者ID:spdx,项目名称:ATTIC-osit,代码行数:15,代码来源:CoverSheetTemplate.java

示例14: endElement

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
/**
 * (non-Javadoc)
 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
 */
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
	// 处理excel的行
	if ("row".equals(qName)) {
		if (cacheSize > rowCache.size() && cRow.getCells() != null) {
			rowCache.add(cRow);
		} else {
			rowsHandler.handleRows(rowCache);
			rowCache.clear();
		}
		lastElementName = null;
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		monitor.worked(1);
	} else if ("t".equals(qName) && !isSheredString) {
		cCell.setCellConentent(lastCellContent.toString().trim());
		lastCellContent.delete(0, lastCellContent.length());
	} else if ("v".equals(qName)) {
		int idx = -1;
		try {
			idx = Integer.parseInt(lastCellContent.toString().trim());
			XSSFRichTextString rtss = new XSSFRichTextString(sharedStringsTable.getEntryAt(idx));
			cCell.setCellConentent(rtss.toString());
			lastCellContent.delete(0, lastCellContent.length());
		} catch (NumberFormatException e) {
		}
	}
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:34,代码来源:XlsxRowReader.java

示例15: unformattedContents

import org.apache.poi.xssf.usermodel.XSSFRichTextString; //导入依赖的package包/类
/**
 * Returns the contents of the cell, with no formatting applied
 *
 * @return
 */
String unformattedContents() {
    switch (currentCell.getType()) {
    case "s": // string stored in shared table
        int idx = Integer.parseInt(lastContents);
        return new XSSFRichTextString(sst.getEntryAt(idx)).toString();
    case "inlineStr": // inline string (not in sst)
        return new XSSFRichTextString(lastContents).toString();
    default:
        return lastContents;
    }
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:17,代码来源:StreamingSheetReader.java


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