Ignore:
Timestamp:
Feb 3, 2010, 3:50:14 PM (10 years ago)
Author:
tabma
Message:
  • created taglibrary for importer and first implementation detection of (cell) datatypes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r147 r169  
    2525    boolean transactional = true
    2626
    27     def hello() { println "hello "}
    28 
    2927    /**
    3028    * @param is input stream representing the (workbook) resource
     
    4139     * @return header representation as a string array
    4240     */
    43     def getHeader(HSSFWorkbook wb){
    44         def sheet = wb.getSheetAt(0)
    45         def row = 0
    46         def header = []
    47         def cellvalue
     41    def getHeader(HSSFWorkbook wb, int sheetindex){
     42
     43        def sheet = wb.getSheetAt(sheetindex)
     44        def datamatrix_start = sheet.getFirstRowNum() + 1
     45        def header = []       
    4846        def df = new DataFormatter()
    4947
    50         for (HSSFCell c: sheet.getRow(row)) {
    51             switch (c.getCellType()) {
    52                     case HSSFCell.CELL_TYPE_STRING: header.add (df.formatCellValue(c)); break
    53                     case HSSFCell.CELL_TYPE_NUMERIC: header.add (df.formatCellValue(c)); break
    54                     case HSSFCell.CELL_TYPE_BLANK: header.add(""); break
    55                     default: header.add("")
    56             }       
     48        for (HSSFCell c: sheet.getRow(sheet.getFirstRowNum())) {
     49            def datamatrix_celltype = sheet.getRow(datamatrix_start).getCell(c.getColumnIndex()).getCellType()
     50
     51            // Check for every celltype, currently redundant code, but possibly this will be
     52            // a piece of custom code for every cell type like specific formatting
     53           
     54            switch (c.getCellType()) {
     55                    case HSSFCell.CELL_TYPE_STRING:                     
     56                        header.add (columnindex:c.getColumnIndex(), value:df.formatCellValue(c), celltype:datamatrix_celltype);
     57                        break
     58                    case HSSFCell.CELL_TYPE_NUMERIC:
     59                        header.add (columnindex:c.getColumnIndex(), value:df.formatCellValue(c), celltype:datamatrix_celltype);
     60                        break
     61                    case HSSFCell.CELL_TYPE_BLANK:
     62                        header.add (columnindex:c.getColumnIndex(), value:"-", celltype:datamatrix_celltype);
     63                        break
     64                    default:
     65                        header.add (columnindex:c.getColumnIndex(), value:df.formatCellValue(c), celltype:datamatrix_celltype);
     66                        break
     67            }
    5768        }
    5869        return header
     70    }
     71
     72    /**
     73     * This method is meant to return a matrix of the rows and columns
     74     * used in the preview
     75     *
     76     * @param wb workbook object
     77     * @param sheetindex sheet index used
     78     * @param rows amount of rows returned
     79     * @return two dimensional array (matrix) of HSSFCell objects
     80     */
     81
     82    HSSFCell[][] getDatamatrix(HSSFWorkbook wb, int sheetindex, int count) {
     83        def sheet = wb.getSheetAt(sheetindex)
     84        def rows  = []
     85        def df = new DataFormatter()
     86
     87        (count <= sheet.getLastRowNum()) ?
     88        ((1+sheet.getFirstRowNum())..count).each { rowindex ->
     89
     90            def row = []
     91            for (HSSFCell c: sheet.getRow(rowindex))
     92                row.add(c)
     93                //row.add(df.formatCellValue(c))
     94            rows.add(row)
     95        } : 0
     96
     97        return rows
    5998    }
    6099
Note: See TracChangeset for help on using the changeset viewer.