Package org.apache.poi.ss.usermodel

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


          int startingFonts = initialFonts[i];
         
          assertEquals(startingFonts, wb.getNumberOfFonts());
         
          // Get a font, and slightly change it
          Font a = wb.createFont();
          assertEquals(startingFonts+1, wb.getNumberOfFonts());
          a.setFontHeightInPoints((short)23);
          assertEquals(startingFonts+1, wb.getNumberOfFonts());
         
          // Get two more, unchanged
          Font b = wb.createFont();
          assertEquals(startingFonts+2, wb.getNumberOfFonts());
          Font c = wb.createFont();
          assertEquals(startingFonts+3, wb.getNumberOfFonts());
       }
    }
View Full Code Here


          "This line finishes with two trailing spaces.  ";
      
       XSSFWorkbook wb = new XSSFWorkbook();
       XSSFSheet sheet = wb.createSheet();

       Font font1 = wb.createFont();
       font1.setColor((short) 20);
       Font font2 = wb.createFont();
       font2.setColor(Font.COLOR_RED);
       Font font3 = wb.getFontAt((short)0);

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

       XSSFRichTextString richTextString =
View Full Code Here

     * Create the cell styles.
     */
    private void createCellStyles() {

        // the font size
        Font f = workbook.createFont();
        f.setFontHeightInPoints((short) 8);

        // bordered cell style
        borderedCellStyle = workbook.createCellStyle();
        borderedCellStyle.setFont(f);
        borderedCellStyle.setBorderBottom(CellStyle.BORDER_THIN);
View Full Code Here

     * Sets the cell styles.
     */
    private void setCellStyles() {

        // Main title
        Font f = workbook.createFont();
        f.setFontHeightInPoints((short) 20);
        mainTitle = workbook.createCellStyle();
        mainTitle.setFont(f);

        // Standard Cell
        f = workbook.createFont();
        f.setFontHeightInPoints((short) 8);
        standard = workbook.createCellStyle();
        standard.setFont(f);

        // Standard Header
        f = workbook.createFont();
        f.setFontHeightInPoints((short) 8);
        standardHeader = workbook.createCellStyle();
        standardHeader.setFont(f);
        standardHeader.setBorderBottom(CellStyle.BORDER_THIN);
        standardHeader.setBorderTop(CellStyle.BORDER_THIN);
        standardHeader.setBorderLeft(CellStyle.BORDER_THIN);
View Full Code Here

    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
   
    CellStyle style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    Font titleFont = wb.createFont();
    titleFont.setFontName("Arial");
    titleFont.setFontHeightInPoints((short) 16);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style.setFont(titleFont);
    styles.put("title", style);

    style = wb.createCellStyle();
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    Font dataFont = wb.createFont();
    dataFont.setFontName("Arial");
    dataFont.setFontHeightInPoints((short) 10);
    style.setFont(dataFont);
    styles.put("data", style);
   
    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(CellStyle.ALIGN_LEFT);
    styles.put("data1", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(CellStyle.ALIGN_CENTER);
    styles.put("data2", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    styles.put("data3", style);
   
    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
//    style.setWrapText(true);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    Font headerFont = wb.createFont();
    headerFont.setFontName("Arial");
    headerFont.setFontHeightInPoints((short) 10);
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    style.setFont(headerFont);
    styles.put("header", style);
   
    return styles;
  }
View Full Code Here

        dateStyle = wb.createCellStyle();
        dateStyle.setDataFormat(fmt.getFormat("yyyy-mm-dd hh:mm:ss"));

        headerStyle = wb.createCellStyle();
        Font headerFont = wb.createFont();
        headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        headerStyle.setFont(headerFont);

        warningStyle = wb.createCellStyle();
        Font warningFont = wb.createFont();
        warningFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        warningFont.setColor(Font.COLOR_RED);
        warningStyle.setFont(warningFont);
    }
View Full Code Here

    Workbook wb = WayIO.workbookOf(cell);
    CellStyle style = wb.createCellStyle();
    style.setAlignment(align.apachePOI());

    if (bold) {
      Font font = wb.createFont();
      font.setBoldweight(Font.BOLDWEIGHT_BOLD);
      style.setFont(font);
    }

    cell.setCellStyle(style);
  }
View Full Code Here

    cell1.setCellValue(new XSSFRichTextString("red bold 18pt italic Arial"));
    cell1.setCellStyle(cellStyle1);

   
    row=sheet.createRow(4);
    Font font2=new XSSFFont();
    font2.setFontHeight((short)1);
    font2.setFontName("Courier");
    font2.setColor(Font.COLOR_NORMAL);
    font2.setUnderline(Font.U_DOUBLE);
    CellStyle cellStyle2=workbook.createCellStyle();
    cellStyle2.setFont(font2);

    Cell cell2=row.createCell(0);
    cell2.setCellValue(new XSSFRichTextString("Something in courier underlined"));
    cell2.setCellStyle(cellStyle2);


    row=sheet.createRow(5);
    cell1=row.createCell(0);
    Font font3=new XSSFFont();
    font3.setFontHeightInPoints((short)9);
    font3.setFontName("Times");
    font3.setStrikeout(true);
    font3.setColor(IndexedColors.PINK.getIndex());
    CellStyle cellStyle3=workbook.createCellStyle();
    cellStyle3.setFont(font3);

    cell1.setCellValue(new XSSFRichTextString("pink italic Times 9pt strikeout!!!"));
    cell1.setCellStyle(cellStyle3);
View Full Code Here

    }
   
    public void testFindFont(){
        //get dafault font and check against default value
      XSSFWorkbook workbook = new XSSFWorkbook();
      Font fontFind=workbook.findFont(Font.BOLDWEIGHT_NORMAL, Font.COLOR_NORMAL, (short)11, "Calibri", false, false, Font.SS_NONE, Font.U_NONE);
      assertNotNull(fontFind);     
     
      //get default font, then change 2 values and check against different values (height changes)
      Font font=workbook.createFont();
      ((XSSFFont)font).setBold(true);
      font.setUnderline(Font.U_DOUBLE);
      StylesSource styleSource=new StylesTable();
      long index=styleSource.putFont(font);
      System.out.println("index="+index);
      workbook.setStylesSource(styleSource);
      fontFind=workbook.findFont(Font.BOLDWEIGHT_BOLD, Font.COLOR_NORMAL, (short)15, "Calibri", false, false, Font.SS_NONE, Font.U_DOUBLE);
View Full Code Here

        assertNotNull(cellStyleAt);
       
        //get custom style
        StylesSource styleSource = workbook.getStylesSource();
        CellStyle customStyle = new XSSFCellStyle(styleSource);
        Font font = new XSSFFont();
        font.setFontName("Verdana");
        customStyle.setFont(font);
        Long x = styleSource.putStyle(customStyle);
        cellStyleAt = workbook.getCellStyleAt(x.shortValue());
        assertNotNull(cellStyleAt);       
    }
View Full Code Here

TOP

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

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.