Examples of HSSFRichTextString


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

        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

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

    /**
     * Test cloning
     */
    public void testClone() {
        String text = "Hello, World";
        HSSFRichTextString str = new HSSFRichTextString(text);

        TextObjectRecord obj = new TextObjectRecord();
        int frLength = ( str.numFormattingRuns() + 1 ) * 8;
        obj.setFormattingRunLength( (short) frLength );
        obj.setTextLength( (short) str.length() );
        obj.setReserved1(true);
        obj.setReserved2((short)2);
        obj.setReserved3((short)3);
        obj.setReserved4((short)4);
        obj.setReserved5((short)5);
View Full Code Here

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

        worksheet.setColumnWidth(1, (30 * 256));
        worksheet.setColumnWidth(4, (20 * 256));

        HSSFRow row = worksheet.createRow(0);

        HSSFRichTextString value = new HSSFRichTextString("Customers");
        value.applyFont(font);
        row.createCell(0).setCellValue(value);

        row = worksheet.createRow(1);
        row.createCell(0).setCellValue(new HSSFRichTextString("Customer Account Details"));

        worksheet.createRow(2);

        row = worksheet.createRow(3);

        HSSFCellStyle style = wb.createCellStyle();
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        value = new HSSFRichTextString("Name");
        value.applyFont(font);
        HSSFCell cell = row.createCell(0);
        cell.setCellValue(value);
        cell.setCellStyle(style);

        value = new HSSFRichTextString("Email");
        value.applyFont(font);
        cell = row.createCell(1);
        cell.setCellValue(value);
        cell.setCellStyle(style);

        value = new HSSFRichTextString("Age");
        value.applyFont(font);
        cell = row.createCell(2);
        cell.setCellValue(value);
        cell.setCellStyle(style);

        value = new HSSFRichTextString("Holdings");
        value.applyFont(font);
        cell = row.createCell(3);
        cell.setCellValue(value);
        cell.setCellStyle(style);

        value = new HSSFRichTextString("Investments");
        value.applyFont(font);
        cell = row.createCell(4);
        cell.setCellValue(value);
        cell.setCellStyle(style);

        int rowIndex = 4;

        List<Customer> customers = customerService.getCustomers();
        for (Customer customer : customers) {
            row = worksheet.createRow(rowIndex++);

            row.createCell(0).setCellValue(new HSSFRichTextString(customer.getName()));
            row.createCell(1).setCellValue(new HSSFRichTextString(customer.getEmail()));

            if (customer.getAge() != null) {
                row.createCell(2).setCellValue(customer.getAge().intValue());
            }

            if (customer.getHoldings() != null) {
                row.createCell(3).setCellValue(customer.getHoldings().doubleValue());
            }

            row.createCell(4).setCellValue(new HSSFRichTextString(customer.getInvestments()));
        }

        return wb;
    }
View Full Code Here

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

   
    protected void addColumnValue(Row row, String value) {
        int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum();
        Cell cell = row.createCell(cellIndex);

        cell.setCellValue(new HSSFRichTextString(value));
    }
View Full Code Here

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

                if (value != null)
                  builder.append(value);
            }
    } 
       
        cell.setCellValue(new HSSFRichTextString(builder.toString()));
    }
View Full Code Here

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

      }

      switch (ct) {
      case String:
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(new HSSFRichTextString(data));
        break;
      case WrappedString:
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(new HSSFRichTextString(data));
        if(cellStyle==null){
          cellStyle=workBook.createCellStyle();
          cellStyle.setFont(workBook.createFont());
          cellStyle.setWrapText(true);
          cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
View Full Code Here

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

    if(cell==null){
      return null;
    }
    switch(cell.getCellType()){
    case HSSFCell.CELL_TYPE_STRING:
      HSSFRichTextString value=cell.getRichStringCellValue();
      if(value!=null){
        return value.getString().trim();
      }
      break;
    case HSSFCell.CELL_TYPE_NUMERIC:
      if(HSSFDateUtil.isCellDateFormatted(cell)){
        Date xlDtVal=cell.getDateCellValue();
View Full Code Here

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

          if (cell == null) {
            cell = row.createCell(i);
          }
          switch (cellData.getCellType()) {
          case HSSFCell.CELL_TYPE_STRING:
            cell.setCellValue(new HSSFRichTextString(cellData.getRichStringCellValue().getString()));
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            break;
          case HSSFCell.CELL_TYPE_NUMERIC:
            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
            if(HSSFDateUtil.isCellDateFormatted(cellData)){
              Date xlDtVal=cellData.getDateCellValue();
              cell.setCellValue(new HSSFRichTextString(CommonUtilities.getDateInddMMYYYYFormat(xlDtVal)));
              break;
            }else{
              HSSFDataFormatter format = new HSSFDataFormatter(); // copies the data in the same format
              cell.setCellValue(new HSSFRichTextString(format.formatCellValue(cellData)));
            }
            break;
          }
        }
      }
View Full Code Here

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

                while (iterator.hasNext())
                {
                    HeaderCell headerCell = iterator.next();

                    HSSFCell cell = xlsRow.createCell(colNum++);
                    cell.setCellValue(new HSSFRichTextString(getHeaderCellValue(headerCell)));
                    cell.setCellStyle(createHeaderStyle(getWb(), headerCell));
                }
            }

            // get the correct iterator (full or partial list according to the exportFull field)
View Full Code Here

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

     */
    protected void writeCell(Object value, HSSFCell cell)
    {
        if (value == null)
        {
            cell.setCellValue(new HSSFRichTextString(""));
        }
        else if (value instanceof Integer)
        {
            Integer integer = (Integer) value;
            // due to a weird bug in HSSF where it uses shorts, we need to input this as a double value :(
            cell.setCellValue(integer.doubleValue());
            cell.setCellStyle(utils.getStyle(ExcelUtils.STYLE_INTEGER));
        }
        else if (value instanceof Number)
        {
            Number num = (Number) value;
            if (num.equals(Double.NaN))
            {
                cell.setCellValue(new HSSFRichTextString(""));
            }
            else
            {
                cell.setCellValue(num.doubleValue());
            }
            cell.setCellStyle(utils.getStyle(ExcelUtils.STYLE_NUMBER));
        }
        else if (value instanceof Date)
        {
            cell.setCellValue((Date) value);
            cell.setCellStyle(utils.getStyle(ExcelUtils.STYLE_DATE));
        }
        else if (value instanceof Calendar)
        {
            cell.setCellValue((Calendar) value);
            cell.setCellStyle(utils.getStyle(ExcelUtils.STYLE_DATE));
        }
        else
        {
            cell.setCellValue(new HSSFRichTextString(ExcelUtils.escapeColumnValue(value)));
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.