本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFRichTextString類的典型用法代碼示例。如果您正苦於以下問題:Java HSSFRichTextString類的具體用法?Java HSSFRichTextString怎麽用?Java HSSFRichTextString使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HSSFRichTextString類屬於org.apache.poi.hssf.usermodel包,在下文中一共展示了HSSFRichTextString類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insertItemToSheet
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
private void insertItemToSheet(String table, HSSFSheet sheet, ArrayList<String> columns) {
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
Cursor cursor = database.rawQuery("select * from " + table, null);
cursor.moveToFirst();
int n = 1;
while (!cursor.isAfterLast()) {
HSSFRow rowA = sheet.createRow(n);
for (int j = 0; j < columns.size(); j++) {
HSSFCell cellA = rowA.createCell(j);
if (cursor.getType(j) == Cursor.FIELD_TYPE_BLOB) {
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) j, n, (short) (j + 1), n + 1);
anchor.setAnchorType(3);
patriarch.createPicture(anchor, workbook.addPicture(cursor.getBlob(j), HSSFWorkbook.PICTURE_TYPE_JPEG));
} else {
cellA.setCellValue(new HSSFRichTextString(cursor.getString(j)));
}
}
n++;
cursor.moveToNext();
}
cursor.close();
}
示例2: createHeader
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
private void createHeader(HSSFSheet sheet, List<ExpedientConsultaDissenyDto> expedientsConsultaDissenyDto) {
int rowNum = 0;
int colNum = 0;
// Capçalera
HSSFRow xlsRow = sheet.createRow(rowNum++);
HSSFCell cell;
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize("Expedient")));
cell.setCellStyle(headerStyle);
Iterator<Entry<String, DadaIndexadaDto>> it = expedientsConsultaDissenyDto.get(0).getDadesExpedient().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, DadaIndexadaDto> e = (Map.Entry<String, DadaIndexadaDto>)it.next();
sheet.autoSizeColumn(colNum);
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize(e.getValue().getEtiqueta())));
cell.setCellStyle(headerStyle);
}
}
示例3: getHtmlValue
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的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 "";
}
示例4: findMatchColumn
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
public static Integer findMatchColumn(final HSSFRow row, final String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
final HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
continue;
}
final HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (cellValue.getString().matches(str)) {
return Integer.valueOf(colNum);
}
}
return null;
}
示例5: writeCell
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
/**
* Write the value to the cell. Override this method if you have complex data types that may need to be exported.
* @param value the value of the cell
* @param cell the cell to write it to
*/
protected void writeCell(Object value, HSSFCell cell, HSSFWorkbook wb)
{
if (value instanceof Number)
{
Number num = (Number) value;
cell.setCellValue(num.doubleValue());
}
else if (value instanceof Date)
{
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(
wb.getCreationHelper().createDataFormat().getFormat("dd/MM/yyyy HH:mm"));
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue((Date) value);
}
else if (value instanceof Calendar)
{
cell.setCellValue((Calendar) value);
}
else
{
cell.setCellValue(new HSSFRichTextString(escapeColumnValue(value)));
}
}
示例6: getHSSFRichString
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
/**
* 03版本複雜數據
* @param rich
* @return
*/
private String getHSSFRichString(HSSFRichTextString rich) {
int nums = rich.numFormattingRuns();
StringBuilder sb = new StringBuilder();
String text = rich.toString();
int currentIndex = 0;
sb.append(text.substring(0, rich.getIndexOfFormattingRun(0)));
for (int i = 0; i < nums; i++) {
sb.append("<span ");
sb.append("class='font_" + rich.getFontOfFormattingRun(i));
sb.append("_");
sb.append(cssRandom);
sb.append("'>");
currentIndex = rich.getIndexOfFormattingRun(i);
if (i < nums - 1) {
sb.append(XmlEscapers.xmlContentEscaper()
.escape(text.substring(currentIndex, rich.getIndexOfFormattingRun(i + 1))));
} else {
sb.append(XmlEscapers.xmlContentEscaper()
.escape(text.substring(currentIndex, text.length())));
}
sb.append("</span>");
}
return sb.toString();
}
示例7: createHeader
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
private boolean createHeader(WorkbookGeneratorContext context,
HSSFSheet sheet,
HSSFCellStyle style) {
if (context.headerNames == null || context.headerNames.isEmpty()) {
return false;
}
int headerRowIndex = 0;
HSSFRow rowHeader = sheet.createRow(headerRowIndex);
for (int i = 0; i < context.headerNames.size(); i++) {
HSSFCell cell = rowHeader.createCell(i);
sheet.autoSizeColumn((short) i);
cell.setCellStyle(style);
cell.setCellValue(new HSSFRichTextString(context.headerNames.get(i)));
}
return true;
}
示例8: getHSSFRichString
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
/**
* 03版本複雜數據
* @param rich
* @return
*/
private String getHSSFRichString(HSSFRichTextString rich) {
int nums = rich.numFormattingRuns();
StringBuilder sb = new StringBuilder();
String text = rich.toString();
int currentIndex = 0;
sb.append(text.substring(0, rich.getIndexOfFormattingRun(0)));
for (int i = 0; i < nums; i++) {
sb.append("<span ");
sb.append("class='font_" + rich.getFontOfFormattingRun(i));
sb.append("_");
sb.append(cssRandom);
sb.append("'>");
currentIndex = rich.getIndexOfFormattingRun(i);
if (i < nums - 1) {
sb.append(XmlEscapers.xmlContentEscaper().escape(
text.substring(currentIndex, rich.getIndexOfFormattingRun(i + 1))));
} else {
sb.append(XmlEscapers.xmlContentEscaper().escape(
text.substring(currentIndex, text.length())));
}
sb.append("</span>");
}
return sb.toString();
}
示例9: getRichTextString
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
protected HSSFRichTextString getRichTextString(JRStyledText styledText, short forecolor, JRFont defaultFont, Locale locale)
{
String text = styledText.getText();
HSSFRichTextString richTextStr = new HSSFRichTextString(text);
int runLimit = 0;
AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();
while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length())
{
Map<Attribute,Object> attributes = iterator.getAttributes();
JRFont runFont = attributes.isEmpty()? defaultFont : new JRBaseFont(attributes);
short runForecolor = attributes.get(TextAttribute.FOREGROUND) != null ?
getWorkbookColor((Color)attributes.get(TextAttribute.FOREGROUND)).getIndex() :
forecolor;
HSSFFont font = getLoadedFont(runFont, runForecolor, attributes, locale);
richTextStr.applyFont(iterator.getIndex(), runLimit, font);
iterator.setIndex(runLimit);
}
return richTextStr;
}
示例10: getRichTextString
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
protected HSSFRichTextString getRichTextString(JRStyledText styledText, short forecolor, JRFont defaultFont, Locale locale) {
String text = styledText.getText();
HSSFRichTextString richTextStr = new HSSFRichTextString(text);
int runLimit = 0;
AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();
while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length()) {
Map<Attribute,Object> attributes = iterator.getAttributes();
JRFont runFont = attributes.isEmpty()? defaultFont : new JRBaseFont(attributes);
short runForecolor = attributes.get(TextAttribute.FOREGROUND) != null
? getWorkbookColor((Color)attributes.get(TextAttribute.FOREGROUND)).getIndex()
: forecolor;
HSSFFont font = getLoadedFont(runFont, runForecolor, attributes, locale);
richTextStr.applyFont(iterator.getIndex(), runLimit, font);
iterator.setIndex(runLimit);
}
return richTextStr;
}
示例11: createContent
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
public void createContent(WebInput wi, DocInfo di)throws ControllerException {
HSSFWorkbook wb = di.getExcelDocument();
// 創建HSSFSheet對象
HSSFSheet sheet = wb.createSheet("sheet0");
// 創建HSSFRow對象
HSSFRow row = sheet.createRow((short) 0);
// 創建HSSFCell對象
HSSFCell cell = row.createCell((short) 0);
// 用來處理中文問題
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
// 設置單元格的值
// cell.setCellValue("Hello World! 你好,中文世界");
String info = wi.getParameter("info");
HSSFRichTextString rts = new HSSFRichTextString(info);
cell.setCellValue(rts);
HSSFCell cell2 = row.createCell((short) 1);
cell2.setCellValue(new HSSFRichTextString(
"Beetle Web Framework 頁麵生成Excel文件演示!"));
}
示例12: findColumn
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
public static Integer findColumn(final HSSFRow row, final String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
final HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
final HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (str.equals(cellValue.getString())) {
return Integer.valueOf(colNum);
}
}
}
return null;
}
示例13: findCell
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
public static CellLocation findCell(final HSSFSheet sheet, final String str, final int colNum) {
for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet.getLastRowNum() + 1; rowNum++) {
final HSSFRow row = sheet.getRow(rowNum);
if (row == null) {
continue;
}
final HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
final HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (!Check.isEmpty(cellValue.getString())) {
if (cellValue.getString().equals(str)) {
return new CellLocation(rowNum, (short) colNum);
}
}
}
return null;
}
示例14: getCellValue
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
public static String getCellValue(final HSSFSheet sheet, final int r, final int c) {
final HSSFRow row = sheet.getRow(r);
if (row == null) {
return null;
}
final HSSFCell cell = row.getCell(c);
if (cell == null) {
return null;
}
final HSSFRichTextString cellValue = cell.getRichStringCellValue();
return cellValue.toString();
}
示例15: setColumnData
import org.apache.poi.hssf.usermodel.HSSFRichTextString; //導入依賴的package包/類
protected void setColumnData(final Map<String, String> keywordsValueMap, final ColumnTemplate columnTemplate, final HSSFRow row, final NormalColumn normalColumn, final TableView tableView, final int order) {
for (final int columnNum : columnTemplate.columnTemplateMap.keySet()) {
final HSSFCell cell = row.createCell(columnNum);
final String template = columnTemplate.columnTemplateMap.get(columnNum);
String value = null;
if (KEYWORD_ORDER.equals(template)) {
value = String.valueOf(order);
} else {
value = getColumnValue(keywordsValueMap, normalColumn, tableView, template);
}
try {
final double num = Double.parseDouble(value);
cell.setCellValue(num);
} catch (final NumberFormatException e) {
final HSSFRichTextString text = new HSSFRichTextString(value);
cell.setCellValue(text);
}
}
}