Package org.apache.poi.ss.usermodel

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


        // an attempt to register an existing format returns its index
        int poundFmtIdx = wb.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getDataFormat();
        assertEquals(poundFmtIdx, wb.createDataFormat().getFormat(poundFmt));

        // now create a custom format with Pound (\u00a3)
        DataFormat dataFormat = wb.createDataFormat();
        short customFmtIdx = dataFormat.getFormat("\u00a3##.00[Yellow]");
        assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX );
        assertEquals("\u00a3##.00[Yellow]", dataFormat.getFormat(customFmtIdx));
    }
View Full Code Here


                    // alignment
                    newStyle.setAlignment(cellStyle.getAlignment());
                    newStyle.setVerticalAlignment(cellStyle.getVerticalAlignment());
                    // misc
                    DataFormat dataFormat = resultWorkbook.getCreationHelper().createDataFormat();
                    newStyle.setDataFormat(dataFormat.getFormat(cellStyle.getDataFormatString()));
                    newStyle.setHidden(cellStyle.getHidden());
                    newStyle.setLocked(cellStyle.getLocked());
                    newStyle.setIndention(cellStyle.getIndention());
                    newStyle.setRotation(cellStyle.getRotation());
                    newStyle.setWrapText(cellStyle.getWrapText());
View Full Code Here

        // an attempt to register an existing format returns its index
        int poundFmtIdx = wb.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getDataFormat();
        assertEquals(poundFmtIdx, wb.getStylesSource().putNumberFormat(poundFmt));

        // now create a custom format with Pound (\u00a3)
        DataFormat dataFormat = wb.createDataFormat();
        short customFmtIdx = dataFormat.getFormat("\u00a3##.00[Yellow]");
        assertTrue(customFmtIdx > BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX );
        assertEquals("\u00a3##.00[Yellow]", dataFormat.getFormat(customFmtIdx));
    }
View Full Code Here

    public static void main(String[]args) throws Exception {
        Workbook wb = new XSSFWorkbook()//or new HSSFWorkbook();
        Sheet sheet = wb.createSheet("format sheet");
        CellStyle style;
        DataFormat format = wb.createDataFormat();
        Row row;
        Cell cell;
        short rowNum = 0;
        short colNum = 0;

        row = sheet.createRow(rowNum++);
        cell = row.createCell(colNum);
        cell.setCellValue(11111.25);
        style = wb.createCellStyle();
        style.setDataFormat(format.getFormat("0.0"));
        cell.setCellStyle(style);

        row = sheet.createRow(rowNum++);
        cell = row.createCell(colNum);
        cell.setCellValue(11111.25);
        style = wb.createCellStyle();
        style.setDataFormat(format.getFormat("#,##0.0000"));
        cell.setCellStyle(style);

        FileOutputStream fileOut = new FileOutputStream("ooxml_dataFormat.xlsx");
        wb.write(fileOut);
        fileOut.close();
View Full Code Here

    public static void main(String[]args) throws Exception {
        Workbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("format sheet");
        CellStyle style;
        DataFormat format = wb.createDataFormat();
        Row row;
        Cell cell;
        short rowNum = 0;
        short colNum = 0;

        row = sheet.createRow(rowNum++);
        cell = row.createCell(colNum);
        cell.setCellValue(11111.25);
        style = wb.createCellStyle();
        style.setDataFormat(format.getFormat("0.0"));
        cell.setCellStyle(style);

        row = sheet.createRow(rowNum++);
        cell = row.createCell(colNum);
        cell.setCellValue(11111.25);
        style = wb.createCellStyle();
        style.setDataFormat(format.getFormat("#,##0.0000"));
        cell.setCellStyle(style);

        FileOutputStream fileOut = new FileOutputStream("ooxml_dataFormat.xlsx");
        wb.write(fileOut);
        fileOut.close();
View Full Code Here

    c3.setCellFormula("SUM(C3:C32)");
  }

  private Map<String, CellStyle> createStyles(Workbook wb) {
    styles = Maps.newHashMap();
    DataFormat df = wb.createDataFormat();

    // --字体设定 --//

    //普通字体
    Font normalFont = wb.createFont();
    normalFont.setFontHeightInPoints((short) 10);

    //加粗字体
    Font boldFont = wb.createFont();
    boldFont.setFontHeightInPoints((short) 10);
    boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

    //蓝色加粗字体
    Font blueBoldFont = wb.createFont();
    blueBoldFont.setFontHeightInPoints((short) 10);
    blueBoldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    blueBoldFont.setColor(IndexedColors.BLUE.getIndex());

    // --Cell Style设定-- //

    //标题格式
    CellStyle headerStyle = wb.createCellStyle();
    headerStyle.setFont(boldFont);
    styles.put("header", headerStyle);

    //日期格式
    CellStyle dateCellStyle = wb.createCellStyle();
    dateCellStyle.setFont(normalFont);
    dateCellStyle.setDataFormat(df.getFormat("yyyy"));
    setBorder(dateCellStyle);
    styles.put("dateCell", dateCellStyle);

    //数字格式
    CellStyle numberCellStyle = wb.createCellStyle();
    numberCellStyle.setFont(normalFont);
    numberCellStyle.setDataFormat(df.getFormat("#,##0.00"));
    setBorder(numberCellStyle);
    styles.put("numberCell", numberCellStyle);

    //合计列格式
    CellStyle totalStyle = wb.createCellStyle();
View Full Code Here

    boldStyle.setFont(font);   
  }
 
  private void createDateFormatStyle() {
    dateStyle = wb.createCellStyle();
    DataFormat df = wb.createDataFormat();
    dateStyle.setDataFormat(df.getFormat(DEFAULT_DATE_FORMAT));
  }
View Full Code Here

    return dateStyle;
  }
 
  public CellStyle getCustomDataFormatStyle(String dataFormat) {
    CellStyle cellStyle = wb.createCellStyle();
    DataFormat df = wb.createDataFormat();
    cellStyle.setDataFormat(df.getFormat(dataFormat));
    return cellStyle;
  }
View Full Code Here

  public static WorkbookXlsBuilder newWorkbookXls() {
    return new WorkbookXlsBuilder();
  }

  static void applyFormatTo(Workbook wb, CellStyle style, String formatString) {
    DataFormat df = wb.createDataFormat();
    style.setDataFormat(df.getFormat(formatString));
  }
View Full Code Here

  }

  static void applyFormatTo(Cell cell, String string) {
    Workbook wb = workbookOf(cell);
    CellStyle style = cell.getCellStyle();
    DataFormat df = wb.createDataFormat();
    style.setDataFormat(df.getFormat(string));
  }
View Full Code Here

TOP

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

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.