Example usage for org.apache.poi.hssf.usermodel HSSFDataFormatter HSSFDataFormatter

List of usage examples for org.apache.poi.hssf.usermodel HSSFDataFormatter HSSFDataFormatter

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFDataFormatter HSSFDataFormatter.

Prototype

public HSSFDataFormatter() 

Source Link

Document

Creates a formatter using the Locale#getDefault() default locale .

Usage

From source file:com.primovision.lutransport.service.ImportMainSheetServiceImpl.java

private Object getCellValue(HSSFCell cell, boolean resolveFormula) {
    if (cell == null) {
        return null;
    }/*from  www. j a v  a  2  s  .  co m*/
    Object result = null;
    int cellType = cell.getCellType();
    switch (cellType) {
    case HSSFCell.CELL_TYPE_BLANK:
        result = "";
        break;
    case HSSFCell.CELL_TYPE_BOOLEAN:
        result = cell.getBooleanCellValue() ? Boolean.TRUE : Boolean.FALSE;
        break;
    case HSSFCell.CELL_TYPE_ERROR:
        result = "ERROR: " + cell.getErrorCellValue();
        break;
    case HSSFCell.CELL_TYPE_FORMULA:

        switch (cell.getCachedFormulaResultType()) {
        case HSSFCell.CELL_TYPE_NUMERIC:
            /*System.out.println("Last evaluated as: " + cell.getNumericCellValue());
            result = cell.getNumericCellValue();
            break;*/
            if (DateUtil.isCellDateFormatted(cell)) {
                result = cell.getDateCellValue();
            } else {
                result = cell.getNumericCellValue();
            }
            System.out.println("Numeric cell value == " + result);
            break;
        case HSSFCell.CELL_TYPE_STRING:
            System.out.println("Last evaluated as \"" + cell.getRichStringCellValue() + "\"");
            result = cell.getRichStringCellValue();
            break;
        }

        //result = cell.getCellFormula();

        break;
    case HSSFCell.CELL_TYPE_NUMERIC:
        HSSFCellStyle cellStyle = cell.getCellStyle();
        short dataFormat = cellStyle.getDataFormat();

        System.out.println("Data format for " + cell.getColumnIndex() + " = " + dataFormat);
        // assumption is made that dataFormat = 14,
        // when cellType is HSSFCell.CELL_TYPE_NUMERIC
        // is equal to a DATE format.
        //if (dataFormat == 165 || dataFormat == 164 || dataFormat == 14) {
        if (DateUtil.isCellDateFormatted(cell)) {
            result = cell.getDateCellValue();
        } else {
            result = cell.getNumericCellValue();
        }

        if (dataFormat == 0) { // alternative way of getting value : can this be replaced for the entire block
            result = new HSSFDataFormatter().formatCellValue(cell);
        }
        System.out.println("Numeric cell value == " + result);

        break;
    case HSSFCell.CELL_TYPE_STRING:
        //result = cell.getStringCellValue();
        result = cell.getRichStringCellValue();
        System.out.println("String -> " + result);
        break;
    default:
        break;
    }

    if (result instanceof Integer) {
        return String.valueOf((Integer) result);
    } else if (result instanceof Double) {
        return String.valueOf(((Double) result)); //.longValue());
    }
    if (result instanceof Date) {
        return result;
    }
    return result.toString();
}

From source file:de.jlo.talendcomp.excel.SpreadsheetFile.java

License:Apache License

protected DataFormatter getDataFormatter() {
    if (dataFormatter == null) {
        if (workbook instanceof HSSFWorkbook) {
            dataFormatter = new HSSFDataFormatter();
        } else {/*from   ww  w . ja v  a 2  s . co  m*/
            dataFormatter = new DataFormatter();
        }
    }
    return dataFormatter;
}

From source file:org.castafiore.groovy.Main.java

License:Open Source License

/**
 * @param args//from   w w  w .ja  v a  2  s  .  c  o m
 */
public static void main(String[] args) throws Exception {
    //      Main m = new Main();
    //       m.startContainer();
    //       TutorialService tService = (TutorialService)m.getObject("tutorial");
    //       tService.testMethod();
    //       List<ASTNode> nodes = new AstBuilder().buildFromString("def w; def v; System.out.println(\"fsdfsdfs\");");
    //       
    //       
    //       for(ASTNode n : nodes){
    //          if(n instanceof BlockStatement){
    //             BlockStatement block = (BlockStatement)n;
    //            
    //             List<Statement> stms = block.getStatements();
    //             for(Statement s : stms){
    //                if(s instanceof ExpressionStatement){
    //                   ExpressionStatement expression = (ExpressionStatement)s;
    //                   Expression exp = expression.getExpression();
    //                   if(exp instanceof DeclarationExpression){
    //                      DeclarationExpression declaration = (DeclarationExpression)exp;
    //                      System.out.println( declaration.getLeftExpression().getText());
    //                   }
    //                   
    //                  //System.out.println(expression.getExpression().getClass().getName()); 
    //                   
    //                }
    //                //System.out.println(s.getClass().getName());
    //             }
    //          }
    //         // System.out.println(n.getText());
    //       }

    ///root/users/erevolution/Applications/e-Shop/erevolution/DefaultCashBook/entries/2012/
    //INSERT INTO WFS_FILE VALUES ('Account', '/root/users/erevolution/Applications/e-Shop/erevolution/DefaultCashBook/accounts/1351867186927', 'org.castafiore.accounting.Account', NULL, '2012-11-02 23:23:20', NULL, '2012-11-02 23:23:20', '\0', '1351867186927', 'erevolution', '*:users', 0, 0, '', NULL, 1, 1, '', 'Whenever there is a sales', NULL, 'Sales Account', NULL, NULL, NULL, NULL, NULL, 'SALES', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'Income', 0.00, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '/root/users/erevolution/Applications/e-Shop/erevolution/DefaultCashBook/accounts', NULL);

    //      List<String> tier1 = new ArrayList<String>();
    //      List<String> tier2 = new ArrayList<String>();
    //      Sheet s = new HSSFWorkbook(new FileInputStream(new File("c:\\java\\erevolution\\tiers.xls"))).getSheetAt(0);
    //      for(int i =1; i <= s.getLastRowNum();i++){
    //         
    //         Row r = s.getRow(i);
    //         if(r != null && r.getCell(1) != null && r.getCell(1).getNumericCellValue() >0){
    //            //tier 1 agent for erevolution
    //            //System.out.println("insert into SECU_RELATIONSHIP values ("+(i+11000)+",'erevolution', 'Tier 2 Agent', '"+new Double(r.getCell(1).getNumericCellValue()).intValue()+"');");
    //            tier2.add(new Double(r.getCell(1).getNumericCellValue()).intValue() + "");
    //            
    //         }
    //         
    //         if(r != null && r.getCell(0) != null && r.getCell(0).getNumericCellValue() >0){
    //            //tier 1 agent for erevolution
    //            //System.out.println("insert into SECU_RELATIONSHIP values ("+(i+11000)+",'erevolution', 'Tier 2 Agent', '"+new Double(r.getCell(1).getNumericCellValue()).intValue()+"');");
    //            tier1.add(new Double(r.getCell(0).getNumericCellValue()).intValue() + "");
    //            
    //         }
    ////         if(s.getRow(i).getCell(0).getStringCellValue().equalsIgnoreCase("merchant"))
    ////            System.out.println("insert into SECU_RELATIONSHIP values ("+(i+10000)+",'erevolution', '"+s.getRow(i).getCell(3).getStringCellValue()+"', '"+s.getRow(i).getCell(1).getStringCellValue()+"');");
    //      }
    //FileOutputStream fout = new FileOutputStream(new File("c:\\java\\erevolution\\tiers.sql"));
    //FileWriter writer = new FileWriter(new File("c:\\java\\erevolution\\tiers.sql"));
    //int i = 12000;
    //      for(String t1 : tier1){
    //         for(String t2 : tier2){
    //            //writer.write(str)
    //            writer.write("insert into SECU_RELATIONSHIP values ("+(i++)+",'"+t1+"', 'Customer', '"+t2+"');\n");
    //            writer.write("insert into SECU_RELATIONSHIP values ("+(i++)+",'"+t2+"', 'Supplier', '"+t1+"');\n");
    //         }
    //      }

    //writer.flush();
    //writer.close();

    //      FileWriter writer = new FileWriter(new File("c:\\java\\erevolution\\tiers.sql"));
    //      tier2.add("erevolution");
    //      String[] accs = new String[]{"Sales:SALES","Purchases:PURCHASES", 
    //            "Travelling Expenses:TRAVELLING", "Salary:SALARY", "Tax:TAX", "Misc:MISC", 
    //            "Electricity:ELEC,Water,Telecom","NPS,NPF:NPS", "Bank charges and Interest:BNKCHGS","Loan:LOAN","Petty cash:PETTY", "Vehicle expenses:VEHICLE"};
    //      
    //      
    //      
    //      for(String t1 : tier1){
    //         
    //         for(String ss : accs){
    //            String[] parts = StringUtil.split(ss, ":");
    //            String code = parts[1];
    //            String acco = parts[0];
    //            String name = System.currentTimeMillis()+StringUtil.nextString(10);
    //            writer.write("INSERT INTO WFS_FILE VALUES ('Account', '/root/users/"+t1+"/Applications/e-Shop/"+t1+"/DefaultCashBook/accounts/"+name+ "', 'org.castafiore.accounting.Account', NULL, '2012-11-02 23:23:20', NULL, '2012-11-02 23:23:20', '\0', '1351867186927', '"+t1+"', '*:users', 0, 0, ' ', NULL, 1, 1, ' ', '"+acco+"', NULL, '"+acco+"', NULL, NULL, NULL, NULL, NULL, '"+code+"', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'Income', 0.00, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '/root/users/"+t1+"/Applications/e-Shop/"+t1+"/DefaultCashBook/accounts', NULL);\n");
    //         }
    //         
    //         
    //         
    //      }
    //      
    //      for(String t1 : tier2){
    //         for(String ss : accs){
    //            String[] parts = StringUtil.split(ss, ":");
    //            String code = parts[1];
    //            String acco = parts[0];
    //            String name = System.currentTimeMillis()+StringUtil.nextString(10);
    //            writer.write("INSERT INTO WFS_FILE VALUES ('Account', '/root/users/"+t1+"/Applications/e-Shop/"+t1+"/DefaultCashBook/accounts/"+name+ "', 'org.castafiore.accounting.Account', NULL, '2012-11-02 23:23:20', NULL, '2012-11-02 23:23:20', '\0', '1351867186927', '"+t1+"', '*:users', 0, 0, ' ', NULL, 1, 1, ' ', '"+acco+"', NULL, '"+acco+"', NULL, NULL, NULL, NULL, NULL, '"+code+"', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'Income', 0.00, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '/root/users/"+t1+"/Applications/e-Shop/"+t1+"/DefaultCashBook/accounts', NULL);\n");
    //         }
    //      }
    //      
    //      writer.flush();
    //      writer.close();
    Workbook hs = new HSSFWorkbook();
    Cell c = hs.createSheet().createRow(0).createCell(0);
    c.setCellValue("45");

    c.getCellStyle().setDataFormat(HSSFDataFormat.getBuiltinFormat("$#,##0_);($#,##0)"));
    DataFormatter d = new HSSFDataFormatter();

    System.out.println(d.formatCellValue(c));
    //MessageFormat.format(pattern, arguments)

}

From source file:org.sakaiproject.gradebook.gwt.server.ImportExportUtilityImpl.java

License:Educational Community License

private ImportExportDataFile processNormalXls(org.apache.poi.ss.usermodel.Sheet cur, ImportSettings settings) {
    log.debug("processNormalXls() called");
    ImportExportDataFile data = new ImportExportDataFile();
    int numCols = getNumberOfColumnsFromSheet(cur);
    Iterator<Row> rowIter = cur.rowIterator();
    boolean headerFound = false;
    int id_col = -1;
    while (rowIter.hasNext()) {

        Row curRow = rowIter.next();/*from  ww  w. j  av a 2  s. c  o m*/
        if (!headerFound) {
            id_col = readHeaderRow(curRow);
            headerFound = true;
            log.debug("Header Row # is " + id_col);
        }
        String[] dataEntity = new String[numCols];

        log.debug("numCols = " + numCols);

        for (int i = 0; i < numCols; i++) {
            org.apache.poi.ss.usermodel.Cell cl = curRow.getCell(i);
            String cellData;
            if (i == id_col && null != cl) {
                if (cl.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
                    cellData = String.format("%.0f", cl.getNumericCellValue());
                    log.debug("#1:cellData=" + cellData);
                } else {
                    cellData = new HSSFDataFormatter().formatCellValue(cl);
                    log.debug("#2:cellData=" + cellData);

                }
            } else {

                cellData = new HSSFDataFormatter().formatCellValue(cl);
                log.debug("#3:cellData=" + cellData);
            }
            if (cellData.length() > 0) {
                dataEntity[i] = cellData;
                log.debug("Setting dataEntity[" + i + "] = " + dataEntity[i]);
            } else {
                dataEntity[i] = "";
                log.debug("Inserted empty string at " + i);
            }
        }
        data.addRow(dataEntity);

    }

    return data;
}

From source file:POS.migrate.Excel_to_db_inventory_items.java

public static List<Excel_to_db_inventory_items> showExcelData(List sheetData, String path) {

    FileInputStream fis;//from w w  w . j a v  a2 s  . co  m
    List<Excel_to_db_inventory_items> datas = new ArrayList();
    try {
        fis = new FileInputStream(path);
        int r = 0;
        int r_set = 1;
        int id = 0;
        for (int i = 0; i < sheetData.size(); i++) {
            List list = (List) sheetData.get(i);
            int size = list.size();
            String[] record = new String[12];
            int record_size = 0;
            for (int j = 0; j < list.size(); j++) {

                CellReference cellReference = new CellReference("B3");
                HSSFCell cell = (HSSFCell) list.get(j);
                HSSFDataFormatter hdf = new HSSFDataFormatter();
                String data = "";
                if (j >= 12) {
                    break;
                }
                if (j == 1 || j == 4 || j == 5) {
                    try {
                        data = "" + cell.getNumericCellValue();
                    } catch (Exception e) {
                        data = "" + cell.getStringCellValue();
                    }
                } else {

                    try {
                        data = "" + cell.getStringCellValue();
                    } catch (Exception e) {
                        data = "" + cell.getNumericCellValue();
                    }
                }

                record[record_size] = data;
                //                    System.out.print(data + " | ");
                record_size++;
            }
            String qty = record[0];
            String item_code = record[1];
            String barcode = record[2];
            String description = record[3];
            String cost = record[4];
            String selling_price = record[5];
            String category = record[6];
            String classification = record[7];
            String sub_classification = record[8];
            String brand = record[9];
            String model = record[10];

            String unit = record[11];
            System.out.println("model:" + model);
            System.out.println("unit:" + unit);
            Excel_to_db_inventory_items encoded = new Excel_to_db_inventory_items(qty, item_code, barcode,
                    description, cost, selling_price, category, classification, sub_classification, brand,
                    model, unit);
            if (record[0] != null) {
                datas.add(encoded);
                System.out.println("");
            }

        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Excel_to_db_inventory_items.class.getName()).log(Level.SEVERE, null, ex);
    }

    return datas;
}

From source file:POS.test2.pisps_items.java

public static List<items> showItems() {
    String path = "C:\\\\Users\\\\Guinness\\\\Documents\\\\Projects\\\\Algorithm\\\\pisps records\\\\items.xls";
    FileInputStream fis = null;// w  w  w  .java  2 s  .c o m
    List sheetData = new ArrayList();
    try {
        fis = new FileInputStream(path);
        HSSFWorkbook workbook = new HSSFWorkbook(fis);
        HSSFSheet sheet = workbook.getSheetAt(0);
        Iterator rows = sheet.rowIterator();
        while (rows.hasNext()) {
            HSSFRow row = (HSSFRow) rows.next();
            Iterator cells = row.cellIterator();

            List data = new ArrayList();
            while (cells.hasNext()) {
                HSSFCell cell = (HSSFCell) cells.next();
                data.add(cell);
            }
            sheetData.add(data);
        }
    } catch (IOException e) {
        JOptionPane.showMessageDialog(null, "Unsupported Format");
    } finally {

        if (fis != null) {
            try {
                fis.close();

            } catch (IOException ex) {
                Logger.getLogger(pisps_items.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    List<items> datas = new ArrayList();
    try {
        fis = new FileInputStream(path);
        int r = 0;
        int r_set = 1;

        String prev_no = "";
        for (int i = 0; i < sheetData.size(); i++) {
            List list = (List) sheetData.get(i);
            int size = list.size();
            List<String> record = new ArrayList();
            for (int j = 0; j < list.size(); j++) {
                HSSFCell cell = (HSSFCell) list.get(j);
                HSSFDataFormatter hdf = new HSSFDataFormatter();
                String data = "";

                if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                    String mydata = cell.getStringCellValue();
                    data = data + "" + mydata + "";
                    record.add(data);
                } else {
                    data = data + cell.getNumericCellValue() + "";
                    record.add(data);

                }

            }
            String[] aw = new String[size];
            int jj = 0;
            for (String s : record) {

                aw[jj] = s;
                jj++;
            }

            String item_code = FitIn.fmt_woc(aw[7]);
            String description = aw[1];
            String category = aw[2];
            String classification = aw[3];
            String sub_classification = aw[4];
            String brand = aw[5];
            String model = aw[6];

            items item = new items(item_code, description, category, classification, sub_classification, brand,
                    model);
            datas.add(item);
        }
        return datas;

    } catch (FileNotFoundException ex) {
        Logger.getLogger(pisps_items.class.getName()).log(Level.SEVERE, null, ex);
    }
    return datas;

}

From source file:POS.test2.pisps_items.java

public static List<cost> showCost() {

    String path = "C:\\\\Users\\\\Guinness\\\\Documents\\\\Projects\\\\Algorithm\\\\pisps records\\\\cost.xls";
    FileInputStream fis = null;//from  w  ww .ja va2 s. com
    List sheetData = new ArrayList();
    try {
        fis = new FileInputStream(path);
        HSSFWorkbook workbook = new HSSFWorkbook(fis);
        HSSFSheet sheet = workbook.getSheetAt(0);
        Iterator rows = sheet.rowIterator();
        while (rows.hasNext()) {
            HSSFRow row = (HSSFRow) rows.next();
            Iterator cells = row.cellIterator();

            List data = new ArrayList();
            while (cells.hasNext()) {
                HSSFCell cell = (HSSFCell) cells.next();
                data.add(cell);
            }
            sheetData.add(data);
        }
    } catch (IOException e) {
        JOptionPane.showMessageDialog(null, "Unsupported Format");
    } finally {

        if (fis != null) {
            try {
                fis.close();

            } catch (IOException ex) {
                Logger.getLogger(pisps_items.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    List<cost> datas = new ArrayList();
    try {
        fis = new FileInputStream(path);
        int r = 0;
        int r_set = 1;

        String prev_no = "";
        for (int i = 0; i < sheetData.size(); i++) {
            List list = (List) sheetData.get(i);
            int size = list.size();
            List<String> record = new ArrayList();
            for (int j = 0; j < list.size(); j++) {
                HSSFCell cell = (HSSFCell) list.get(j);
                HSSFDataFormatter hdf = new HSSFDataFormatter();
                String data = "";

                if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                    String mydata = cell.getStringCellValue();
                    data = data + "" + mydata + "";
                    record.add(data);
                } else {
                    data = data + cell.getNumericCellValue() + "";
                    record.add(data);

                }

            }
            String[] aw = new String[size];
            int jj = 0;
            for (String s : record) {

                aw[jj] = s;
                jj++;
            }

            String item_code = FitIn.fmt_woc(aw[0]);
            double cost = FitIn.toDouble(aw[1]);
            double price = FitIn.toDouble(aw[2]);
            cost cos = new cost(item_code, cost, price);

            datas.add(cos);
        }
        return datas;

    } catch (FileNotFoundException ex) {
        Logger.getLogger(pisps_items.class.getName()).log(Level.SEVERE, null, ex);
    }
    return datas;

}

From source file:spires.printing.Encoded_baptism.java

public static List<Encoded_baptism> showExcelData(List sheetData, String path) {

    FileInputStream fis;/*  w  w w .jav a2  s.c  o  m*/
    List<Encoded_baptism> datas = new ArrayList();
    try {
        fis = new FileInputStream(path);
        int r = 0;
        int r_set = 1;
        int id = 0;
        for (int i = 0; i < sheetData.size(); i++) {

            List list = (List) sheetData.get(i);
            int size = list.size();
            String[] record = new String[15];
            int record_size = 0;
            for (int j = 0; j < list.size(); j++) {

                CellReference cellReference = new CellReference("B3");
                HSSFCell cell = (HSSFCell) list.get(j);
                HSSFDataFormatter hdf = new HSSFDataFormatter();
                String data = "";
                if (j >= 14) {
                    break;
                }
                if (cell.getCellType() == 0) {
                    if (j == 5 || j == 8) {
                        data = "" + DateType.sf.format(getRoundedDate(cell.getNumericCellValue())) + "";
                    } else {
                        data = "" + cell.getNumericCellValue();
                    }
                } else {
                    data = cell.getStringCellValue();
                }

                record[record_size] = data;
                //                    System.out.print(data + " | ");
                record_size++;
            }
            //                System.out.println("");
            Date d = getRoundedDate(FitIn.toDouble(record[3]));
            String da = DateType.sf.format(d);

            int page_no = FitIn.toInt(record[0]);
            int index_no = FitIn.toInt(record[1]);
            String fname = record[2];
            String mi = record[3];
            String lname = record[4];
            String date_of_baptism = record[5];
            String parish_priest = record[6];
            String minister = record[7];
            String date_of_birth = record[8];
            String place_of_birth = record[9];
            String place_of_baptism = "";
            String father = record[10];
            String mother = record[11];
            String sponsors = record[12];
            String remarks = record[13];

            if (page_no != 0) {

                if (fname.equalsIgnoreCase("n/a")) {
                    fname = "";
                }
                if (mi.equalsIgnoreCase("n/a")) {
                    mi = "";
                }
                if (lname.equalsIgnoreCase("n/a")) {
                    lname = "";
                }
                if (parish_priest.equalsIgnoreCase("n/a")) {
                    parish_priest = "";
                }
                if (minister.equalsIgnoreCase("n/a")) {
                    minister = "";
                }
                if (place_of_birth.equalsIgnoreCase("n/a")) {
                    place_of_birth = "";
                }
                if (place_of_baptism.equalsIgnoreCase("n/a")) {
                    place_of_baptism = "";
                }
                if (father.equalsIgnoreCase("n/a")) {
                    father = "";
                }
                if (mother.equalsIgnoreCase("n/a")) {
                    mother = "";
                }
                if (sponsors.equalsIgnoreCase("n/a")) {
                    sponsors = "";
                }
                if (remarks.equalsIgnoreCase("n/a")) {
                    remarks = "";
                }
                Encoded_baptism to = new Encoded_baptism(page_no, index_no, fname, mi, lname, date_of_baptism,
                        parish_priest, minister, date_of_birth, place_of_birth, place_of_baptism, father,
                        mother, sponsors, remarks);
                datas.add(to);
            }

        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Encoded_Funeral.class.getName()).log(Level.SEVERE, null, ex);
    }

    return datas;
}

From source file:spires.printing.Encoded_Funeral.java

public static List<to_encoded> showExcelData(List sheetData, String path) {

    FileInputStream fis;/*w  w w  . j a v  a2 s . com*/
    List<to_encoded> datas = new ArrayList();
    try {
        fis = new FileInputStream(path);
        int r = 0;
        int r_set = 1;
        int id = 0;
        for (int i = 0; i < sheetData.size(); i++) {
            List list = (List) sheetData.get(i);
            int size = list.size();
            String[] record = new String[11];
            int record_size = 0;
            for (int j = 0; j < list.size(); j++) {

                CellReference cellReference = new CellReference("B3");
                HSSFCell cell = (HSSFCell) list.get(j);
                HSSFDataFormatter hdf = new HSSFDataFormatter();
                String data = "";
                if (j >= 11) {
                    break;
                }
                if (j >= 0 && j <= 2 || j == 7 || j == 10) {
                    data = "" + cell.getNumericCellValue();
                } else if (j == 7 || j == 10) {
                    data = "" + DateType.sf.format(getRoundedDate(cell.getNumericCellValue())) + "";

                } else {
                    data = cell.getStringCellValue();
                }
                record[record_size] = data;
                System.out.print(data + " | ");
                record_size++;
            }
            String index_no = record[0];
            String book_no = record[1];
            String page_no = record[2];
            String date_of_burial = record[7];
            String price = record[9];
            String fname = record[3];
            String mi = record[4];
            String lname = record[5];
            String residence = record[8];
            String informant = record[6];
            String remarks = "";
            String parents = record[6];
            String date_of_burial2 = record[10];
            to_encoded t = new to_encoded(index_no, book_no, page_no, date_of_burial, price, fname, mi, lname,
                    residence, informant, remarks, parents, date_of_burial2, 0);

            if (record[0] != null) {
                datas.add(t);
                System.out.println("");
            }

        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Encoded_Funeral.class.getName()).log(Level.SEVERE, null, ex);
    }

    return datas;
}

From source file:ypcnv.views.impl.FileXLS.java

License:Open Source License

/**
 * With respect to cell type get cell's content.
 * //from   w w  w  . j  a va 2 s .c  o m
 * @param cell
 *            - cell to be processed.
 * @return Cell's content.
 */
private String getCellContent(HSSFCell cell) {

    int foundCellType = cell.getCellType();
    String cellContent = null;

    switch (foundCellType) {
    case Cell.CELL_TYPE_STRING:
        cellContent = cell.getStringCellValue();
        break;
    case Cell.CELL_TYPE_FORMULA:
        cellContent = cell.getStringCellValue();
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        cellContent = cell.getBooleanCellValue() ? "TRUE" : "FALSE";
        break;
    case Cell.CELL_TYPE_ERROR:
        byte xlsErrorCode = cell.getErrorCellValue();
        if (xlsErrorCode == 0) {
            cellContent = "";
        } else {
            cellContent = "XLS error code '" + xlsErrorCode + "'.";
            String message = "XLS cell type is 'ERROR', the XLS error code is '" + xlsErrorCode + "'."
                    + " The cell row=" + cell.getRowIndex() + ", col=" + cell.getColumnIndex() + ".";
            LOG.info(message);
        }
        break;
    case Cell.CELL_TYPE_NUMERIC:
        HSSFDataFormatter numericFormat = new HSSFDataFormatter();
        cellContent = numericFormat.formatCellValue(cell);
        // cellContent = cell.getNumericCellValue();
        break;
    default:
        cellContent = "";
        break;
    }
    return cellContent;
}