Package org.apache.poi.ss.usermodel

Examples of org.apache.poi.ss.usermodel.RichTextString


    else if (text.length() > 0)
    {
      if (text.length() < 32768)
      {
        // There's rich text.
        final RichTextString rtStr = creationHelper.createRichTextString(text);
        for (int i = 0; i < buffer.size(); i++)
        {
          final RichTextFormat o = (RichTextFormat) buffer.get(i);
          final int position = o.getPosition();
          final HSSFFontWrapper font = o.getFont();
          if (i == (buffer.size() - 1))
          {
            // Last element ..
            rtStr.applyFont(position, text.length(), fontFactory.getExcelFont(font));
          }
          else
          {
            final RichTextFormat next = (RichTextFormat) buffer.get(i + 1);
            rtStr.applyFont(position, next.getPosition(), fontFactory.getExcelFont(font));
          }
        }
        return rtStr;
      }
      else
      {
        ExcelTextExtractor.logger.warn(
            "Excel-Cells cannot contain text larger than 32.737 characters. Text will be clipped.");

        final String realText = text.substring(0, 32767);
        final RichTextString rtStr = creationHelper.createRichTextString(realText);
        for (int i = 0; i < buffer.size(); i++)
        {
          final RichTextFormat o = (RichTextFormat) buffer.get(i);
          final int position = o.getPosition();
          if (position >= 32767)
          {
            break;
          }
          final HSSFFontWrapper font = o.getFont();
          if (i == (buffer.size() - 1))
          {
            // Last element ..
            final int endPosition = Math.min(32767, text.length());
            rtStr.applyFont(position, endPosition, fontFactory.getExcelFont(font));
          }
          else
          {
            final RichTextFormat next = (RichTextFormat) buffer.get(i + 1);
            final int endPosition = Math.min(32767, next.getPosition());
            rtStr.applyFont(position, endPosition, fontFactory.getExcelFont(font));
          }
        }
        return rtStr;
      }
    }
View Full Code Here


    if (text.length() > 0)
    {
      if (text.length() < 32768)
      {
        // There's rich text.
        final RichTextString rtStr = creationHelper.createRichTextString(text);
        for (int i = 0; i < buffer.size(); i++)
        {
          final RichTextFormat o = buffer.get(i);
          final int position = o.getPosition();
          final HSSFFontWrapper font = o.getFont();
          if (i == (buffer.size() - 1))
          {
            // Last element ..
            rtStr.applyFont(position, text.length(), fontFactory.getExcelFont(font));
          }
          else
          {
            final RichTextFormat next = buffer.get(i + 1);
            rtStr.applyFont(position, next.getPosition(), fontFactory.getExcelFont(font));
          }
        }
        return rtStr;
      }
      else
      {
        ExcelTextExtractor.logger.warn(
            "Excel-Cells cannot contain text larger than 32.737 characters. Text will be clipped.");

        final String realText = text.substring(0, 32767);
        final RichTextString rtStr = creationHelper.createRichTextString(realText);
        for (int i = 0; i < buffer.size(); i++)
        {
          final RichTextFormat o = buffer.get(i);
          final int position = o.getPosition();
          if (position >= 32767)
          {
            break;
          }
          final HSSFFontWrapper font = o.getFont();
          if (i == (buffer.size() - 1))
          {
            // Last element ..
            final int endPosition = Math.min(32767, text.length());
            rtStr.applyFont(position, endPosition, fontFactory.getExcelFont(font));
          }
          else
          {
            final RichTextFormat next = buffer.get(i + 1);
            final int endPosition = Math.min(32767, next.getPosition());
            rtStr.applyFont(position, endPosition, fontFactory.getExcelFont(font));
          }
        }
        return rtStr;
      }
    }
View Full Code Here

              {
                tableModel.addColumn(Messages.getString("TableDataSourceEditor.Column",
                    String.valueOf(tableModel.getColumnCount())), Object.class);
              }

              final RichTextString string = cell.getRichStringCellValue();
              if (string != null)
              {
                tableModel.addColumn(string.getString(), Object.class);
              }
              else
              {
                tableModel.addColumn(Messages.getString("TableDataSourceEditor.Column", String.valueOf(colIdx)), Object.class);
              }
            }
          }
        }
      }

      Object[] rowData = null;
      while (rowIterator.hasNext())
      {
        final Row row = (Row) rowIterator.next();
        final short cellCount = row.getLastCellNum();
        if (cellCount == -1)
        {
          continue;
        }
        if (rowData == null || rowData.length != cellCount)
        {
          rowData = new Object[cellCount];
        }

        for (short colIdx = 0; colIdx < cellCount; colIdx++)
        {
          final Cell cell = row.getCell(colIdx);

          final Object value;
          if (cell != null)
          {
            if (cell.getCellType() == Cell.CELL_TYPE_STRING)
            {
              final RichTextString string = cell.getRichStringCellValue();
              if (string != null)
              {
                value = string.getString();
              }
              else
              {
                value = null;
              }
View Full Code Here

        AttributedString str;
        TextLayout layout;

        double width = -1;
        if (cellType == Cell.CELL_TYPE_STRING) {
            RichTextString rt = cell.getRichStringCellValue();
            String[] lines = rt.getString().split("\\n");
            for (int i = 0; i < lines.length; i++) {
                String txt = lines[i] + defaultChar;

                str = new AttributedString(txt);
                copyAttributes(font, str, 0, txt.length());

                if (rt.numFormattingRuns() > 0) {
                    // TODO: support rich text fragments
                }

                layout = new TextLayout(str.getIterator(), fontRenderContext);
                if(style.getRotation() != 0){
View Full Code Here

    Sheet sheet1 = workbook.createSheet("sheet1");
    Sheet sheet2 = workbook.createSheet("sheet2");
    workbook.createSheet("sheet3");

    RichTextString rts = workbook.getCreationHelper().createRichTextString("hello world");

    sheet1.createRow(0).createCell((short)0).setCellValue(1.2);
    sheet1.createRow(1).createCell((short)0).setCellValue(rts);
    sheet2.createRow(0);
View Full Code Here

        XSSFRow row = sheet.createRow(0);
        XSSFCell cell = row.createCell(0);

        XSSFFont font = wb.createFont();
        RichTextString rts = factory.createRichTextString("");
        rts.applyFont(font);
        cell.setCellValue(rts);

        sheet.autoSizeColumn(0);
    }
View Full Code Here

        XSSFRow row = sheet.createRow(0);
        XSSFCell cell = row.createCell(0);

        XSSFFont font = wb.createFont();
        RichTextString rts = factory.createRichTextString("");
        rts.applyFont(font);
        cell.setCellValue(rts);

        sheet.autoSizeColumn(0);
    }
View Full Code Here

    Sheet sheet1 = workbook.createSheet("sheet1");
    Sheet sheet2 = workbook.createSheet("sheet2");
    workbook.createSheet("sheet3");

    RichTextString rts = workbook.getCreationHelper().createRichTextString("hello world");

    sheet1.createRow(0).createCell((short)0).setCellValue(1.2);
    sheet1.createRow(1).createCell((short)0).setCellValue(rts);
    sheet2.createRow(0);
View Full Code Here

        for (String str : texts) {
            sb.append(separator);
            sb.append(str);
            separator="\n";
        }
        RichTextString str = factory.createRichTextString(sb.toString());
        comment.setString(str);
        comment.setVisible(Boolean.FALSE);
        comment.setAuthor("AlgebraToSpreadsheet");

        // Assign the comment to the cell
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

TOP

Related Classes of org.apache.poi.ss.usermodel.RichTextString

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.