Package org.apache.poi.ss.usermodel

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


            }
        } else {
            sheetName = "Times";
        }
        Sheet sheet = workbook.createSheet(sheetName);
        Row header = sheet.createRow(0);
        header.createCell(0).setCellValue("locale");
        header.createCell(1).setCellValue("DisplayName");
        header.createCell(2).setCellValue("Excel " + styleName);
        header.createCell(3).setCellValue("java.text.DateFormat");
        header.createCell(4).setCellValue("Equals");
        header.createCell(5).setCellValue("Java pattern");
        header.createCell(6).setCellValue("Excel pattern");

        int rowNum = 1;
        for( Locale locale : DateFormat.getAvailableLocales() ) {
            try {
                Row row = sheet.createRow(rowNum++);
   
                row.createCell(0).setCellValue(locale.toString());
                row.createCell(1).setCellValue(locale.getDisplayName());
   
                DateFormat dateFormat;
                if( dates ) {
                    if( times ) {
                        dateFormat = DateFormat.getDateTimeInstance(style, style, locale);
                    } else {
                        dateFormat = DateFormat.getDateInstance(style, locale);
                    }
                } else {
                    dateFormat = DateFormat.getTimeInstance(style, locale);
                }
   
                Cell cell = row.createCell(2);
   
                cell.setCellValue(date);
                CellStyle cellStyle = row.getSheet().getWorkbook().createCellStyle();
   
                String javaDateFormatPattern = ((SimpleDateFormat)dateFormat).toPattern();
                String excelFormatPattern = DateFormatConverter.convert(locale, javaDateFormatPattern);
   
                DataFormat poiFormat = row.getSheet().getWorkbook().createDataFormat();
                cellStyle.setDataFormat(poiFormat.getFormat(excelFormatPattern));
                row.createCell(3).setCellValue(dateFormat.format(date));
   
                cell.setCellStyle(cellStyle);
   
                // the formula returns TRUE is the formatted date in column C equals to the string in column D
                row.createCell(4).setCellFormula("TEXT(C"+rowNum+",G"+rowNum+")=D" + rowNum);
                row.createCell(5).setCellValue(javaDateFormatPattern);
                row.createCell(6).setCellValue(excelFormatPattern);
            } catch (Exception e) {
                throw new RuntimeException("Failed for locale: " + locale + ", having locales: " +
                        Arrays.toString(DateFormat.getAvailableLocales()), e);
            }
        }
View Full Code Here


     * Called to convert the contents of the currently opened workbook into
     * a CSV file.
     */
    private void convertToCSV() {
        Sheet sheet = null;
        Row row = null;
        int lastRowNum = 0;
        this.csvData = new ArrayList<ArrayList>();

        System.out.println("Converting files contents to CSV format.");

View Full Code Here

        int lastRow = range.getLastRow();
        int firstColumn = range.getFirstColumn();
        int lastColumn = range.getLastColumn();
        final int width = lastColumn - firstColumn + 1;
        SimpleCellWalkContext ctx = new SimpleCellWalkContext();
        Row currentRow = null;
        Cell currentCell = null;

        for (ctx.rowNumber = firstRow; ctx.rowNumber <= lastRow; ++ctx.rowNumber) {
            currentRow = sheet.getRow(ctx.rowNumber);
            if (currentRow == null) {
                continue;
            }
            for (ctx.colNumber = firstColumn; ctx.colNumber <= lastColumn; ++ctx.colNumber) {
                currentCell = currentRow.getCell(ctx.colNumber);

                if (currentCell == null) {
                    continue;
                }
                if (isEmpty(currentCell) && !traverseEmptyCells) {
View Full Code Here

        AreaReference ar = new AreaReference(ctPivotCacheDefinition.getCacheSource().getWorksheetSource().getRef());
        CellReference firstCell = ar.getFirstCell();
        CellReference lastCell = ar.getLastCell();
        int columnStart = firstCell.getCol();
        int columnEnd = lastCell.getCol();
        Row row = sheet.getRow(firstCell.getRow());
        CTCacheFields cFields;
        if(ctPivotCacheDefinition.getCacheFields() != null) {
            cFields = ctPivotCacheDefinition.getCacheFields();
        } else {
            cFields = ctPivotCacheDefinition.addNewCacheFields();
        }
        //For each column, create a cache field and give it en empty sharedItems
        for(int i=columnStart; i<=columnEnd; i++) {
            CTCacheField cf = cFields.addNewCacheField();
            if(i==columnEnd){
                cFields.setCount(cFields.getCacheFieldList().size());
            }
            //General number format
            cf.setNumFmtId(0);
            Cell cell = row.getCell(i);
            cell.setCellType(Cell.CELL_TYPE_STRING);
            cf.setName(row.getCell(i).getStringCellValue());
            cf.addNewSharedItems();
        }
    }
View Full Code Here

                throw new UserAdminException("The first sheet is empty");
            }
            int limit = sheet.getLastRowNum();
            boolean isDuplicate = false;
            for (int i = 1; i < limit+1; i++) {
                Row row = sheet.getRow(i);
                Cell cell = row.getCell(0);
                String userName = cell.getStringCellValue();
                if (!userStore.isExistingUser(userName)) {
                    userStore.addUser(userName, password, null, null, null, true);
                } else {
                    isDuplicate = true;
View Full Code Here

    /**
    * @param row 0-based
    * @param column 0-based
    */
   void setCellFormula(int row, int column, String formula) {
       Row r = sheet.getRow(row);
       if (r == null) {
           r = sheet.createRow(row);
       }
       Cell cell = r.getCell(column);
       if (cell == null) {
           cell = r.createCell(column);
       }
       cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);
       cell.setCellFormula(formula);
   }
View Full Code Here

     * @param lastRow 1-based
     */
    protected void autofillSecondRowDownTo(int lastRow) {
        checkState(! evaluated);

        Row firstRow = sheet.getRow(1-1);
        int columnCount = firstRow.getLastCellNum();
        Row row = sheet.getRow(2-1);

        int column = 0;
        for (Cell cell = row.getCell(column); column < columnCount; cell = row.getCell(++column)) {
            if (cell == null) {
                continue;
            }
            String formula = cell.getCellFormula();

View Full Code Here

     * @param rowNo 0-based
     * @param column 0-based
     * @return null, if cell not defined
     */
    String getCellFormula(int rowNo, int column) {
        Row row = sheet.getRow(rowNo);
        if (row == null) { return null; }
        Cell cell = row.getCell(column);
        if (cell == null) { return null; }
        checkState(cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA);
        return cell.getCellFormula();
    }
View Full Code Here

        return cell.getCellFormula();
    }

    void printCell(String cellAddress) {
        CellReference cellReference = new CellReference(cellAddress);
        Row row = sheet.getRow(cellReference.getRow());
        Cell cell = row.getCell(cellReference.getCol());
        int resultType = cell.getCachedFormulaResultType();
        if (resultType == XSSFCell.CELL_TYPE_NUMERIC){
            System.err.print(cell.getNumericCellValue());
        } else if (resultType == XSSFCell.CELL_TYPE_BOOLEAN) {
            System.err.print(cell.getBooleanCellValue());
View Full Code Here

     * @param row 0-based
     * @param column 0-based
     *
     */
    void setCellFormula(int row, int column, String formula) {
        Row r = sheet.getRow(row);
        if (r == null) {
            r = sheet.createRow(row);
        }
        Cell cell = r.getCell(column);
        if (cell == null) {
            cell = r.createCell(column);
        }
        cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);
        cell.setCellFormula(formula);
    }
View Full Code Here

TOP

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

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.