Package org.apache.poi.hssf.usermodel

Examples of org.apache.poi.hssf.usermodel.HSSFRichTextString


    public void testSetString() {
        CommentsTable sheetComments = new CommentsTable();
        CTComment ctComment = CTComment.Factory.newInstance();
        XSSFComment comment = new XSSFComment(sheetComments, ctComment);
        RichTextString richTextString = new HSSFRichTextString(TEST_RICHTEXTSTRING);
        comment.setString(richTextString);
        assertEquals(TEST_RICHTEXTSTRING, ctComment.getText().getT());
    }
View Full Code Here


     
     
      //STRING
      xcell.setCellValue(new XSSFRichTextString("text string"));
      xcell.setCellType(Cell.CELL_TYPE_STRING);
      hcell.setCellValue(new HSSFRichTextString("text string"));
      hcell.setCellType(Cell.CELL_TYPE_STRING);
      assertEquals(hcell.toString(),xcell.toString());
     
      //ERROR
      xcell.setCellErrorValue(FormulaError.VALUE);
View Full Code Here

    row = sheet.createRow(0); // 建立新行
    // 显示标题列名
    for (int i = 0; i < pShowKeys.length; i++) {
      cell = row.createCell(i); // 建立新cell
      // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
      cell.setCellValue(new HSSFRichTextString(pShowKeys[i]));
    }
    // 逐行取数
    int rowId = 1;// 数据行号(从2行开始填充数�?)
    for (Iterator<Object[]> iter = datas.iterator(); iter.hasNext(); rowId++) {
      row = sheet.createRow(rowId); // 建立新行
      Object[] objs = iter.next();
      // 生成每一�?
      for (int j = 0; j < objs.length; j++) {
        cell = row.createCell(j); // 建立新cell
        // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        cell.setCellValue(new HSSFRichTextString((objs[j] == null) ? "" : objs[j]
            .toString()));
      }
    }
    return wb;
  }
View Full Code Here

    row = sheet.createRow(0); // 建立新行
    // 显示标题列名�?
    for (int i = 0; i < pShowKeys.length; i++) {
      cell = row.createCell(i); // 建立新cell
      // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
      cell.setCellValue(new HSSFRichTextString(pShowKeys[i]));
    }
    // 逐行取数�?
    int rowId = 1;// 数据行号(从�?2行开始填充数�?)
    for (Iterator<T> iter = list.iterator(); iter.hasNext(); rowId++) {
      row = sheet.createRow(rowId); // 建立新行
      T obj = iter.next();
      // 生成每一
      for (int i = 0; i < pKeys.length; i++) {
        cell = row.createCell(i); // 建立新cell
        cellVal = exporter.getPropertyValue(obj, pKeys[i]);
        // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        String cellValue = "";
        if (null != cellVal) {
          cellValue = cellVal.toString();
        }
        if (cellVal instanceof Float) {
          cellValue = numberformat.format(cellVal);
        }
        cell.setCellValue(new HSSFRichTextString(cellValue));
      }
    }
    return wb;
  }
View Full Code Here

            cell.setCellStyle(getTimeStyle());
          } else if (values[i] instanceof Calendar) {
            cell.setCellValue((Calendar) values[i]);
            cell.setCellStyle(getTimeStyle());
          } else {
            cell.setCellValue(new HSSFRichTextString((values[i] == null) ? ""
                : values[i].toString()));
          }
        }
      } else {
        HSSFCell cell = row.createCell(0);
        // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        if (datas instanceof Number) {
          cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        }
        cell.setCellValue(new HSSFRichTextString(datas.toString()));
      }
    }
  }
View Full Code Here

    public void testSetString() {
        CommentsTable sheetComments = new CommentsTable();
        CTComment ctComment = CTComment.Factory.newInstance();
        XSSFComment comment = new XSSFComment(sheetComments, ctComment);
        RichTextString richTextString = new HSSFRichTextString(TEST_RICHTEXTSTRING);
        comment.setString(richTextString);
        assertEquals(TEST_RICHTEXTSTRING, ctComment.getText().getT());
    }
View Full Code Here

            case HSSFCell.CELL_TYPE_FORMULA:
              if(formulasNotResults) {
                text.append(cell.getCellFormula());
              } else {
                // Try it as a string, if not as a number
                HSSFRichTextString str =
                  cell.getRichStringCellValue();
                if(str != null && str.length() > 0) {
                  text.append(str.toString());
                } else {
                  // Try and treat it as a number
                  double val = cell.getNumericCellValue();
                  text.append(val);
                }
View Full Code Here

    }

    public void testWrite()
    {
        HSSFRichTextString str = new HSSFRichTextString("Hello, World!");

        TextObjectRecord record = new TextObjectRecord();
        int frLength = ( str.numFormattingRuns() + 1 ) * 8;
        record.setFormattingRunLength( (short) frLength );
        record.setTextLength( (short) str.length() );
        record.setStr( str );
        record.setHorizontalTextAlignment( TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED );
        record.setVerticalTextAlignment( TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP );
        record.setTextLocked( true );
        record.setTextOrientation( TextObjectRecord.TEXT_ORIENTATION_NONE );
View Full Code Here

        for (int i = 0; i < length.length; i++) {
            StringBuffer buff = new StringBuffer(length[i]);
            for (int j = 0; j < length[i]; j++) {
                buff.append("x");
            }
            HSSFRichTextString str = new HSSFRichTextString(buff.toString());

            TextObjectRecord obj = new TextObjectRecord();
            int frLength = ( str.numFormattingRuns() + 1 ) * 8;
            obj.setFormattingRunLength( (short) frLength );
            obj.setTextLength( (short) str.length() );
            obj.setStr( str );

            byte [] data = obj.serialize();
            RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(data));
            is.nextRecord();
            TextObjectRecord record = new TextObjectRecord(is);
            str = record.getStr();

            assertEquals(buff.length(), str.length());
            assertEquals(buff.toString(), str.getString());
        }

    }
View Full Code Here

    public TextObjectRecord( RecordInputStream in )
    {
        super( in );
        if (str == null)
          str = new HSSFRichTextString("");
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.usermodel.HSSFRichTextString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.