Example usage for org.apache.poi.xssf.usermodel XSSFSheet getPhysicalNumberOfRows

List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet getPhysicalNumberOfRows

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFSheet getPhysicalNumberOfRows.

Prototype

@Override
public int getPhysicalNumberOfRows() 

Source Link

Document

Returns the number of physically defined rows (NOT the number of rows in the sheet)

Usage

From source file:eremeykin.pete.loader.xlsxdao.XlsxModelDao.java

private String getTableTillEndContent(String table) throws DaoException {
    FileInputStream excelFile = null;
    try {//from  w  w  w  .  j ava2  s.c  o m
        excelFile = new FileInputStream(source);
        XSSFWorkbook wb = new XSSFWorkbook(excelFile);
        XSSFSheet sheet = wb.getSheet(table);
        Integer numRow = sheet.getPhysicalNumberOfRows();
        StringBuffer sb = new StringBuffer();
        for (int i = 1; i < numRow; i++) {
            String s = sheet.getRow(i).getCell(0).getStringCellValue();
            sb.append(sheet.getRow(i).getCell(0).getStringCellValue());
            if (!s.endsWith("\n")) {
                sb.append("\n");
            }
        }
        System.out.println(sb.toString());
        return sb.toString();
        //            return sheet.getRow(1).getCell(0).getStringCellValue();
    } catch (FileNotFoundException ex) {
        throw new DaoException("Can't find excel file " + source, ex);
    } catch (IOException ex) {
        throw new DaoException("Can't open excel file " + source, ex);
    } finally {
        try {
            if (excelFile != null) {
                excelFile.close();
            }
        } catch (IOException ex) {
            throw new DaoException("Can't close excel file " + source, ex);
        }
    }
}

From source file:in.expertsoftware.colorcheck.FormatvarificationErrorList.java

private static void printinfo(XSSFWorkbook ErrorWorkbook, String cell_ref, String sheet_name, String error_desc,
        String error_level) {/*  w ww  .  j av  a2  s.  com*/
    XSSFSheet ErrorSheet = ErrorWorkbook.getSheet(sheet_name);
    if (error_level.equals("Error")) {
        ErrorSheet.getRow(0).getCell(1).setCellValue(1 + ErrorSheet.getRow(0).getCell(1).getNumericCellValue());
    } else if (error_level.equals("Warning")) {
        ErrorSheet.getRow(1).getCell(1).setCellValue(1 + ErrorSheet.getRow(1).getCell(1).getStringCellValue());
    }
    XSSFRow row = ErrorSheet.createRow(ErrorSheet.getPhysicalNumberOfRows());
    CreaateStyleOfErrorList(ErrorWorkbook, row, cell_ref, sheet_name, error_desc, error_level);

}

From source file:in.expertsoftware.colorcheck.FormatvarificationErrorList.java

private static void setColorInfoMetaData(XSSFWorkbook ErrorWorkbook) {
    //Set Colour used information on first sheet.
    XSSFSheet setInfoSheet = ErrorWorkbook.getSheetAt(0);
    XSSFRow colourInfoRow;/*w  w  w  .  ja va2  s  .c  o  m*/
    XSSFRow errorColourRow;
    XSSFRow warningColourRow;
    if (setInfoSheet.getPhysicalNumberOfRows() > 5) {
        colourInfoRow = setInfoSheet.getRow(5);
    } else {
        colourInfoRow = setInfoSheet.createRow(5);
    }
    Cell colorInfoCell = colourInfoRow.createCell(6);
    Cell RGBCell = colourInfoRow.createCell(7);
    CreaateHeaderOfErrorList(ErrorWorkbook, colorInfoCell, "Used Color");
    CreaateHeaderOfErrorList(ErrorWorkbook, RGBCell, "RGB Value");
    setInfoSheet.autoSizeColumn(6);
    setInfoSheet.autoSizeColumn(7);
    if (setInfoSheet.getPhysicalNumberOfRows() > 6) {
        errorColourRow = setInfoSheet.getRow(6);
    } else {
        errorColourRow = setInfoSheet.createRow(6);
    }
    if (setInfoSheet.getPhysicalNumberOfRows() > 7) {
        warningColourRow = setInfoSheet.getRow(7);
    } else {
        warningColourRow = setInfoSheet.createRow(7);
    }
    //error color style
    XSSFCellStyle errorStyle = ErrorWorkbook.createCellStyle();
    errorStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    errorStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(225, 171, 171)));
    errorColourRow.createCell(6).setCellStyle(errorStyle);
    errorColourRow.getCell(6).setCellValue("Error");
    errorColourRow.createCell(7).setCellValue("225, 171, 171");
    //warning color style
    XSSFCellStyle warningStyle = ErrorWorkbook.createCellStyle();
    warningStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    warningStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(155, 194, 230)));
    warningColourRow.createCell(6).setCellStyle(warningStyle);
    warningColourRow.getCell(6).setCellValue("Warning");
    warningColourRow.createCell(7).setCellValue("155, 194, 230");
}

From source file:io.unravellingtechnologies.excalibur.Sheet.java

License:Open Source License

/**
 * Default constructor. Loads the sheet into the object, with all the data in it.
 * /*ww w. j av  a2 s  .c  om*/
 * @param excelBook Excel book object where the sheet will be read from.
 * @param sheetName Name of the sheet to read.
 */
Sheet(final XSSFWorkbook excelBook, final String sheetName) {

    final XSSFSheet sheet = excelBook.getSheet(sheetName);

    /*
     * If it has rows proceed. Note: to be considered valid at least one row must exist (header).
     */
    if (sheet.getPhysicalNumberOfRows() > 1) {
        sheetHeader = new HashMap<Integer, String>();
        rows = new ArrayList<Row>();

        setSheetHeader(sheet);
        loadRows(sheet);
    }
}

From source file:io.unravellingtechnologies.excalibur.Sheet.java

License:Open Source License

/**
 * Loads all the rows that have content into the Sheet structure.
 *///from   ww w .  j ava  2  s  .c  om
private void loadRows(XSSFSheet sheet) {
    if (logger.isDebugEnabled()) {
        logger.debug("Loading sheet rows...");
    }

    if (sheet.getPhysicalNumberOfRows() < 2) {
        return;
    }

    for (Iterator<org.apache.poi.ss.usermodel.Row> rowIt = sheet.rowIterator(); rowIt.hasNext();) {
        org.apache.poi.ss.usermodel.Row tableRow = rowIt.next();

        if (tableRow.getRowNum() != sheet.getFirstRowNum()) {
            Row row = new Row(new HashMap<String, String>());

            for (Iterator<Cell> cellIt = tableRow.cellIterator(); cellIt.hasNext();) {
                Cell cell = cellIt.next();

                row.addCell(getColumnName(cell.getColumnIndex()), cell.getStringCellValue());
            }

            rows.add(row);
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Completed loading " + rows.size() + " rows.");
    }
}

From source file:lldval.LLDVal.java

/**
 * @param args the command line arguments
 *///from w w w . ja v  a  2s . c om
public static void main(String[] args) throws IOException {

    // reading data from a csv file  
    System.out.println("Reading data from csv :");
    ReadCsv readCsv = new ReadCsv();
    readCsv.readCsv("./tunables.csv");
    writeXLSXFile("./PCAT_AnalysisFile.xlsx", "Info");
    Workbook wb = new XSSFWorkbook(new FileInputStream("./PCAT_AnalysisFile.xlsx"));
    XSSFSheet clusterSheet = (XSSFSheet) wb.createSheet("caaConfigurations");
    XSSFSheet hwSheet = (XSSFSheet) wb.createSheet("HWConfigurations");
    XSSFSheet vfcSheet = (XSSFSheet) wb.createSheet("VFC Mappings");
    // reading data from a csv file and convert to java object  
    System.out.println("Reading data from csv and convert to java object:");
    //  csvToTunables csvToJavaObject = new csvToTunables();  
    //  csvToJavaObject.convertCsvToJava();  
    pcatFolders pcatFolder = new pcatFolders("./systems");

    //    System.out.println(Arrays.toString(pcatFolder.pcatFolderList));
    String[] lparName = pcatFolder.pcatFolderList;
    System.out.println(Arrays.toString(lparName));
    //      caa CAA = new caa();
    //      readCaa readCaas = new readCaa("dx980");
    for (int j = 0; j < lparName.length - 1; j++) {
        pcatLparFolders lparFolders = new pcatLparFolders("./systems", lparName[j]);
        System.out.print("LparName : " + String.valueOf(lparName[j]) + "  : ");
        System.out.println(Arrays.toString(lparFolders.fileList));
        for (int t = 0; t < lparFolders.fileList.length; t++) {
            System.out.println(lparFolders.fileList[t]);
            switch (lparFolders.fileList[t]) {
            //        case "caa":
            //            readCaa caa = new readCaa(lparName[j]);
            //            caa.processingLineByLine();
            //            System.out.println("Cluster Configuration Populating");
            ////            System.out.println(caa.toString());
            ////            System.out.println(String.valueOf(CAA.CLUSTER_NAME+" : "+CAA.Cluster_shorthand_id_for_node+" : "+CAA.Mean_Deviation_in_network_rtt_to_node+" : "+CAA.Node_name+" : "+CAA.Number_of_clusters_node_is_a_member_in+" : "+CAA.Smoothed_rtt_to_node+" : "+CAA.State_of_node+" : "+CAA.UUID_for_node));
            //            int sheetLength = clusterSheet.getPhysicalNumberOfRows();
            //            if(sheetLength == 0){
            //                Row row = clusterSheet.createRow((short)sheetLength);
            //                Cell cell = row.createCell(0);
            //                cell.setCellValue("CLUSTER_NAME");
            //                Cell cell1 = row.createCell(1);
            //                cell1.setCellValue("Node_name");
            //                Cell cell2 = row.createCell(2);
            //                cell2.setCellValue("Number_of_clusters_node_is_a_member_in");
            //                Cell cell3 = row.createCell(3);
            //                cell3.setCellValue("State_of_node");
            //                Cell cell4 = row.createCell(4);
            //                cell4.setCellValue("UUID_for_node");
            //                Cell cell5 = row.createCell(5);
            //                cell5.setCellValue("Cluster_shorthand_id_for_node");
            //                Cell cell6 = row.createCell(6);
            //                cell6.setCellValue("Smoothed_rtt_to_node");
            //                Cell cell7 = row.createCell(7);
            //                cell7.setCellValue("Mean_Deviation_in_network_rtt_to_node");}else
            //              if (CAA.CLUSTER_NAME != null && !CAA.CLUSTER_NAME.isEmpty()){
            //                Row row = clusterSheet.createRow((short)sheetLength+1);
            //                Cell cell = row.createCell(0);
            //                cell.setCellValue(CAA.CLUSTER_NAME);
            //                Cell cell1 = row.createCell(1);
            //                cell1.setCellValue(CAA.Node_name);
            //                Cell cell2 = row.createCell(2);
            //                cell2.setCellValue(CAA.Number_of_clusters_node_is_a_member_in);
            //                Cell cell3 = row.createCell(3);
            //                cell3.setCellValue(CAA.State_of_node);
            //                Cell cell4 = row.createCell(4);
            //                cell4.setCellValue(CAA.UUID_for_node);
            //                Cell cell5 = row.createCell(5);
            //                cell5.setCellValue(CAA.Cluster_shorthand_id_for_node);
            //                Cell cell6 = row.createCell(6);
            //                cell6.setCellValue(CAA.Smoothed_rtt_to_node);
            //                Cell cell7 = row.createCell(7);
            //                cell7.setCellValue(CAA.Mean_Deviation_in_network_rtt_to_node);
            //              }
            //                    try {
            //        FileOutputStream out = new FileOutputStream("./PCAT_AnalysisFile.xlsx");
            //        wb.write(out);
            //        out.close();
            //    } catch (Exception e) {
            //        e.printStackTrace();
            //    }
            //            break;
            case "hds":
                System.out.println("HDS Storage Configuration Populating");
                readHDL parser = new readHDL(lparName[j]);
                parser.processLineByLine(lparName[j]);
                //    System.out.println(String.valueOf(lpar.getLparName()+" : "+lpar.getLparID()+" : "+lpar.getHostname()+" : "+lpar.getEntCapacity()));
                log("Done.");
                break;
            //        case "hmc":
            //            System.out.println("HMC Configuration Populating");
            //            break;
            case "hw":
                System.out.println("Hardware  Configuration Populating");
                readHW hw = new readHW(lparName[j]);
                hw.processLineByLine();
                System.out.println(lpar.lparID + " : " + lpar.lparName + " : " + lpar.hostname + " : "
                        + lpar.entCapacity + " : " + lpar.maxCPU + " : " + lpar.desiredCPU + " : " + lpar.minCPU
                        + " : " + lpar.MaxVirtCPU + " : " + lpar.DesVirtCPU + " : " + lpar.minVirtCPU);
                int hwsheetLength = hwSheet.getPhysicalNumberOfRows();
                if (hwsheetLength == 0) {
                    Row row = hwSheet.createRow((short) hwsheetLength);
                    Cell cell = row.createCell(0);
                    cell.setCellValue("LparID");
                    Cell cell1 = row.createCell(1);
                    cell1.setCellValue("lparName");
                    Cell cell2 = row.createCell(2);
                    cell2.setCellValue("hostname");
                    Cell cell3 = row.createCell(3);
                    cell3.setCellValue("maxMem");
                    Cell cell4 = row.createCell(4);
                    cell4.setCellValue("desiredMem");
                    Cell cell5 = row.createCell(5);
                    cell5.setCellValue("maxMem");
                    Cell cell6 = row.createCell(6);
                    cell6.setCellValue("MemMode");
                    Cell cell7 = row.createCell(7);
                    cell7.setCellValue("maxCPU");
                    Cell cell8 = row.createCell(8);
                    cell8.setCellValue("desiredCPU");
                    Cell cell9 = row.createCell(9);
                    cell9.setCellValue("minCPU");
                    Cell cell10 = row.createCell(10);
                    cell10.setCellValue("MaxVirtCPU");
                    Cell cell11 = row.createCell(11);
                    cell11.setCellValue("DesVirtCPU");
                    Cell cell12 = row.createCell(12);
                    cell12.setCellValue("minVirtCPU");
                    Cell cell13 = row.createCell(13);
                    cell13.setCellValue("entCapacity");
                    Cell cell14 = row.createCell(14);
                    cell14.setCellValue("weight");
                    Cell cell15 = row.createCell(15);
                    cell15.setCellValue("SMTType");
                    Cell cell16 = row.createCell(16);
                    cell16.setCellValue("cpuMode");
                } else if (lpar.lparID != null && !lpar.lparID.isEmpty()) {
                    Row row = hwSheet.createRow((short) hwsheetLength + 1);
                    Cell cell = row.createCell(0);
                    cell.setCellValue(lpar.lparID);
                    Cell cell1 = row.createCell(1);
                    cell1.setCellValue(lpar.lparName);
                    Cell cell2 = row.createCell(2);
                    cell2.setCellValue(lpar.hostname);
                    Cell cell3 = row.createCell(3);
                    cell3.setCellValue(lpar.maxMem);
                    Cell cell4 = row.createCell(4);
                    cell4.setCellValue(lpar.desiredMem);
                    Cell cell5 = row.createCell(5);
                    cell5.setCellValue(lpar.maxMem);
                    Cell cell6 = row.createCell(6);
                    cell6.setCellValue(lpar.MemMode);
                    Cell cell7 = row.createCell(7);
                    cell7.setCellValue(lpar.maxCPU);
                    Cell cell8 = row.createCell(8);
                    cell8.setCellValue(lpar.desiredCPU);
                    Cell cell9 = row.createCell(9);
                    cell9.setCellValue(lpar.minCPU);
                    Cell cell10 = row.createCell(10);
                    cell10.setCellValue(lpar.MaxVirtCPU);
                    Cell cell11 = row.createCell(11);
                    cell11.setCellValue(lpar.DesVirtCPU);
                    Cell cell12 = row.createCell(12);
                    cell12.setCellValue(lpar.minVirtCPU);
                    Cell cell13 = row.createCell(13);
                    cell13.setCellValue(lpar.entCapacity);
                    Cell cell14 = row.createCell(14);
                    cell14.setCellValue(lpar.weight);
                    Cell cell15 = row.createCell(15);
                    cell15.setCellValue(lpar.SMTType);
                    Cell cell16 = row.createCell(16);
                    cell16.setCellValue(lpar.cpuMode);
                }
                try {
                    FileOutputStream out = new FileOutputStream("./PCAT_AnalysisFile.xlsx");
                    wb.write(out);
                    out.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            //        case "network":
            //            System.out.println("Network Configuration Populating");
            //            break;
            //        case "os":
            //            System.out.println("Operating System Configuration Populating");
            //            break;
            //        case "perf":
            //            System.out.println("Performance Configuration Populating");
            //            break;
            //        case "secure":
            //            System.out.println("Security Configuration Populating");
            //            break;
            //        case "storage":
            //            System.out.println("Storage Configuration Populating");
            //            break;
            //        case "tsm":
            //            System.out.println("TSM Configuration Populating");
            //            break;
            case "vio":
                vfcs.clear();
                System.out.println("VIO Configuration Populating");
                readVFCMap vfcmapd = new readVFCMap(lparName[j]);
                vfcmapd.processPatern();
                vfcMap vfcmap = new vfcMap();
                System.out.println(vfcs.size());
                for (int vfcRows = 0; vfcRows <= vfcs.size() - 1; vfcRows++) {
                    System.out.println(vfcs.get(vfcRows).vfcName + " | " + vfcs.get(vfcRows).physLoc + " | "
                            + vfcs.get(vfcRows).clntId + " | " + vfcs.get(vfcRows).clntName + " | "
                            + vfcs.get(vfcRows).status + " | " + vfcs.get(vfcRows).fc_name + " | "
                            + vfcs.get(vfcRows).fc_loc_code + " | " + vfcs.get(vfcRows).flags + " | "
                            + vfcs.get(vfcRows).VFC_client_name + " | " + vfcs.get(vfcRows).VFC_client_DRC);
                    int vfcsheetLength = vfcSheet.getPhysicalNumberOfRows();
                    if (vfcsheetLength == 0) {
                        Row row = vfcSheet.createRow((short) vfcsheetLength);
                        int count = 0;
                        Cell cell = row.createCell(0);
                        cell.setCellValue("Lpar Name");
                        for (Field field : vfcmap.getClass().getDeclaredFields()) {
                            count++;
                            //                System.out.println(field.getName());
                            Cell nextcell = row.createCell(count);
                            nextcell.setCellValue(field.getName());

                        }
                        //                Row row1 = vfcSheet.createRow(1);
                        //                System.out.println("value row"+row1);
                        //                Cell valuecell = row1.createCell(0);
                        //                valuecell.setCellValue(lparName[j]);
                        //                Cell vfcNamecell = row1.createCell(vfcRows);
                        //                vfcNamecell.setCellValue(vfcs.get(vfcRows).vfcName);
                        //                Cell physLoccell = row1.createCell(vfcRows);
                        //                physLoccell.setCellValue(vfcs.get(vfcRows).physLoc);
                        //                Cell clntIdcell = row1.createCell(vfcRows);
                        //                clntIdcell.setCellValue(vfcs.get(vfcRows).clntId);
                        //                Cell clntNamecell = row1.createCell(vfcRows);
                        //                clntNamecell.setCellValue(vfcs.get(vfcRows).clntName);
                        //                Cell statuscell = row1.createCell(vfcRows);
                        //                statuscell.setCellValue(vfcs.get(vfcRows).status);
                        //                Cell fc_namecell = row1.createCell(vfcRows);
                        //                fc_namecell.setCellValue(vfcs.get(vfcRows).fc_name);
                        //                Cell fc_loc_codecell = row1.createCell(vfcRows);
                        //                fc_loc_codecell.setCellValue(vfcs.get(vfcRows).fc_loc_code);
                        //                Cell flagscell = row1.createCell(vfcRows);
                        //                flagscell.setCellValue(vfcs.get(vfcRows).flags);
                        //                Cell VFC_client_namecell = row1.createCell(vfcRows);
                        //                VFC_client_namecell.setCellValue(vfcs.get(vfcRows).VFC_client_name);
                        //                Cell VFC_client_DRCcell = row1.createCell(vfcRows);
                        //                VFC_client_DRCcell.setCellValue(vfcs.get(vfcRows).VFC_client_DRC);
                        //vfcs.get(vfcRows).vfcName+" | "+vfcs.get(vfcRows).physLoc+" | "+vfcs.get(vfcRows).clntId+" | "+vfcs.get(vfcRows).clntName+" | "+vfcs.get(vfcRows).status+" | "+vfcs.get(vfcRows).fc_name+" | "+vfcs.get(vfcRows).fc_loc_code+" | "+vfcs.get(vfcRows).flags+" | "+vfcs.get(vfcRows).VFC_client_name+" | "+vfcs.get(vfcRows).VFC_client_DRC
                    } else if (vfcs.get(vfcRows).vfcName != null && !vfcs.get(vfcRows).vfcName.isEmpty()) {
                        Row valuerow = vfcSheet.createRow((short) vfcsheetLength);
                        System.out.println("value row" + valuerow);
                        Cell valuecell = valuerow.createCell(0);
                        valuecell.setCellValue(lparName[j]);
                        Cell vfcNamecell = valuerow.createCell(vfcRows);
                        vfcNamecell.setCellValue(vfcs.get(vfcRows).vfcName);
                        Cell physLoccell = valuerow.createCell(vfcRows);
                        physLoccell.setCellValue(vfcs.get(vfcRows).physLoc);
                        Cell clntIdcell = valuerow.createCell(vfcRows);
                        clntIdcell.setCellValue(vfcs.get(vfcRows).clntId);
                        Cell clntNamecell = valuerow.createCell(vfcRows);
                        clntNamecell.setCellValue(vfcs.get(vfcRows).clntName);
                        Cell statuscell = valuerow.createCell(vfcRows);
                        statuscell.setCellValue(vfcs.get(vfcRows).status);
                        Cell fc_namecell = valuerow.createCell(vfcRows);
                        fc_namecell.setCellValue(vfcs.get(vfcRows).fc_name);
                        Cell fc_loc_codecell = valuerow.createCell(vfcRows);
                        fc_loc_codecell.setCellValue(vfcs.get(vfcRows).fc_loc_code);
                        Cell flagscell = valuerow.createCell(vfcRows);
                        flagscell.setCellValue(vfcs.get(vfcRows).flags);
                        Cell VFC_client_namecell = valuerow.createCell(vfcRows);
                        VFC_client_namecell.setCellValue(vfcs.get(vfcRows).VFC_client_name);
                        Cell VFC_client_DRCcell = valuerow.createCell(vfcRows);
                        VFC_client_DRCcell.setCellValue(vfcs.get(vfcRows).VFC_client_DRC);

                        //                    valueCount++;
                        //                Cell value1cell = valuerow.createCell(valueCount);
                        //                value1cell.setCellValue(map.clntName);// i am stuck here to iterate around the values of each instance of the object.
                    }
                }
                FileOutputStream out = new FileOutputStream("./PCAT_AnalysisFile.xlsx");
                wb.write(out);
                out.close();
                break;
            default:
                //            System.out.println("Nothing to do");
                break;

            }
        }
        ;
    }
    ;

    //  getPropValue testRun = new getPropValue("./Systems/dx1010/hw/lparstat-vfcRows.txt");

}

From source file:localization.excel.java

public static void convert(String filePath) {
    Vector<String> zFile;
    if (filePath.endsWith(".zip")) {
        zFile = readzipfile(filePath);/*from w w  w. java2  s  .c om*/
        for (String s : zFile) {
            if (s.endsWith(".xlsx")) {
                //System.out.println(s);
                convert(s);
            }
        }
    } else if (!filePath.endsWith(".xlsx")) {
        return;
    } else {
        try {
            FileInputStream file = new FileInputStream(new File(filePath));
            System.out.println(filePath);
            //Get the workbook instance for XLS file 
            XSSFWorkbook workbook = new XSSFWorkbook(file);
            XSSFSheet sheet = workbook.getSheetAt(0);
            XSSFRow row;
            XSSFCell cell;
            rowNumber = sheet.getPhysicalNumberOfRows();
            try {
                for (int i = 0; i < rowNumber; i++) {
                    row = sheet.getRow(i);
                    if (row != null) {
                        int columnNum = row.getPhysicalNumberOfCells();
                        //System.out.println(columnNum);
                        for (int j = 0; j < columnNum; j++) {
                            cell = row.getCell(j);

                            if (j == 0) {
                                String name = cell.getRichStringCellValue().getString();
                                if (name.equalsIgnoreCase("Esri")) {
                                    langNumber++;
                                }
                                //System.out.println(name);
                            }
                        }
                        if (i == 3) {
                            cell = row.getCell(30);
                            XSSFCellStyle cs = cell.getCellStyle();
                            cell = row.createCell(32);
                            cell.setCellValue("Additional Charge per language");
                            cell.setCellStyle(cs);
                        }
                    }
                }
            } catch (Exception e) {

            }
            System.out.println(langNumber);
            double total = Double.parseDouble(sheet.getRow(langNumber + 3).getCell(29).getRawValue());

            double subTotal = total / langNumber;
            DecimalFormat df = new DecimalFormat("#.000");
            for (int i = 0; i < langNumber; i++) {
                cell = sheet.getRow(i + 4).createCell(32);
                cell.setCellValue("$" + df.format(subTotal));
            }

            file.close();
            FileOutputStream outFile = new FileOutputStream(filePath);
            workbook.write(outFile);
            outFile.close();
            rowNumber = 0;
            langNumber = 0;
            System.out.println("Done");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

From source file:mil.tatrc.physiology.datamodel.dataset.DataSetReader.java

License:Apache License

protected static List<SEPatient> readPatients(XSSFSheet xlSheet) {
    String property, value, unit;
    List<SEPatient> patients = new ArrayList<SEPatient>();
    try {/*  w w  w  . j  a  v a 2  s  . c o m*/
        int rows = xlSheet.getPhysicalNumberOfRows();
        for (int r = 0; r < rows; r++) {
            XSSFRow row = xlSheet.getRow(r);
            if (row == null)
                continue;
            int cells = row.getPhysicalNumberOfCells();
            if (r == 0) {// Allocate the number of patients we have
                for (int i = 1; i < cells; i++)
                    patients.add(new SEPatient());
            }
            property = row.getCell(0).getStringCellValue();
            if (property == null || property.isEmpty())
                continue;
            Log.info("Processing Patient Field : " + property);
            for (int c = 1; c < cells; c++) {
                String cellValue = null;
                XSSFCell cell = row.getCell(c);
                switch (cell.getCellType()) {
                case XSSFCell.CELL_TYPE_NUMERIC:
                    cellValue = Double.toString(cell.getNumericCellValue());
                    break;
                case XSSFCell.CELL_TYPE_STRING:
                    cellValue = cell.getStringCellValue();
                    break;
                }
                if (cellValue == null || cellValue.isEmpty())
                    continue;
                int split = cellValue.indexOf(" ");
                // Pull The Value
                if (split == -1) {
                    value = cellValue;
                    unit = "";
                } else {
                    value = cellValue.substring(0, split);
                    unit = cellValue.substring(split + 1);
                }
                if (value.equals("INF"))
                    value = "Infinity";
                if (!setProperty(patients.get(c - 1), property, value, unit)) {
                    Log.error("Error pulling" + property + " from " + cellValue);
                    break;
                }
            }
        }
    } catch (Exception ex) {
        Log.error("Error reading XLS", ex);
        return null;
    }
    return patients;
}

From source file:mil.tatrc.physiology.datamodel.dataset.DataSetReader.java

License:Apache License

protected static Map<String, SESubstance> readSubstances(XSSFSheet xlSheet) {
    EnumAnatomy currCmpt = null;//from  ww  w . j  av  a2  s  .co m
    String property, value, unit;
    SESubstance substance = null;
    SESubstanceAnatomyEffect afx = null;
    List<SESubstance> substances = new ArrayList<SESubstance>();
    Set<Integer> skipColumns = new HashSet<Integer>();

    try {
        int rows = xlSheet.getPhysicalNumberOfRows();
        for (int r = 0; r < rows; r++) {
            XSSFRow row = xlSheet.getRow(r);
            if (row == null)
                continue;
            int cells = row.getPhysicalNumberOfCells();
            if (r == 0) {
                for (int c = 1; c < cells; c++) {
                    property = row.getCell(c).getStringCellValue().trim();
                    if (property.equals("Reference Value") || property.equals("Reference Source")
                            || property.equals("Notes/Page"))
                        skipColumns.add(c);
                }
            }
            property = row.getCell(0).getStringCellValue().trim();
            if (property == null || property.isEmpty())
                continue;
            Log.info("Processing Substance Field : " + property);
            if (property.indexOf("Compartment Effects") > -1) {
                if (property.indexOf("Myocardium") > -1)
                    currCmpt = EnumAnatomy.MYOCARDIUM;
                else if (property.indexOf("Fat") > -1)
                    currCmpt = EnumAnatomy.FAT;
                else if (property.indexOf("Kidneys") > -1)
                    currCmpt = EnumAnatomy.KIDNEYS;
                else if (property.indexOf("Brain") > -1)
                    currCmpt = EnumAnatomy.BRAIN;
                else if (property.indexOf("Muscle") > -1)
                    currCmpt = EnumAnatomy.MUSCLE;
                else if (property.indexOf("Skin") > -1)
                    currCmpt = EnumAnatomy.SKIN;
                else if (property.indexOf("Bone") > -1)
                    currCmpt = EnumAnatomy.BONE;
                else if (property.indexOf("Gut") > -1)
                    currCmpt = EnumAnatomy.GUT;
                else if (property.indexOf("Splanchnic") > -1)
                    currCmpt = EnumAnatomy.SPLANCHNIC;
                else if (property.indexOf("Spleen") > -1)
                    currCmpt = EnumAnatomy.SPLEEN;
                else if (property.indexOf("Large Intestine") > -1)
                    currCmpt = EnumAnatomy.LARGE_INTESTINE;
                else if (property.indexOf("Small Intestine") > -1)
                    currCmpt = EnumAnatomy.SMALL_INTESTINE;
                else if (property.indexOf("Liver") > -1)
                    currCmpt = EnumAnatomy.LIVER;
                else if (property.indexOf("Right Lung") > -1)
                    currCmpt = EnumAnatomy.RIGHT_LUNG;
                else if (property.indexOf("Left Lung") > -1)
                    currCmpt = EnumAnatomy.LEFT_LUNG;
                else {
                    Log.error("Unsupported Anatomy Compartment : " + property);
                    break;
                }
            }
            int s = -1;
            for (int c = 1; c < cells; c++) {
                if (skipColumns.contains(c))
                    continue;
                s++;
                String cellValue = null;
                XSSFCell cell = row.getCell(c);
                switch (cell.getCellType()) {
                case XSSFCell.CELL_TYPE_NUMERIC:
                    cellValue = Double.toString(cell.getNumericCellValue());
                    break;
                case XSSFCell.CELL_TYPE_STRING:
                    cellValue = cell.getStringCellValue();
                    break;
                case XSSFCell.CELL_TYPE_FORMULA:
                    switch (evaluator.evaluateFormulaCell(cell)) {
                    case XSSFCell.CELL_TYPE_NUMERIC:
                        cellValue = Double.toString(cell.getNumericCellValue());
                        break;
                    case XSSFCell.CELL_TYPE_STRING:
                        cellValue = cell.getStringCellValue();
                        break;
                    }
                }
                if (cellValue == null)
                    continue;
                cellValue = cellValue.trim();
                if (cellValue.isEmpty())
                    continue;
                if (property.equals("Name")) {
                    substance = new SESubstance();
                    substances.add(substance);
                }

                int split = cellValue.indexOf(" ");
                // Pull The Value
                if (split == -1) {
                    value = cellValue;
                    unit = "";
                } else {
                    value = cellValue.substring(0, split);
                    unit = cellValue.substring(split + 1);
                }
                if (value.equals("INF"))
                    value = "Infinity";
                substance = substances.get(c - (3 * s) - 1);

                if (currCmpt == null)
                    afx = null;
                else
                    afx = substance.getAnatomyEffect(currCmpt);
                if (!setProperty(substance, afx, property, value, unit)) {
                    Log.error("Error pulling" + property + " from " + cellValue);
                    break;
                }
            }
        }
    } catch (Exception ex) {
        Log.error("Error reading XLS", ex);
        return null;
    }
    Map<String, SESubstance> map = new HashMap<String, SESubstance>();
    for (SESubstance sub : substances)
        map.put(sub.getName(), sub);
    return map;
}

From source file:mil.tatrc.physiology.datamodel.dataset.DataSetReader.java

License:Apache License

protected static List<SESubstanceCompound> readCompounds(XSSFSheet xlSheet,
        Map<String, SESubstance> substances) {
    String property, value, unit;
    SESubstance s;/* w ww . j  av a  2  s  .  co  m*/
    SESubstanceCompound compound = null;
    SESubstanceCompoundComponent component = null;
    List<SESubstanceCompound> compounds = new ArrayList<SESubstanceCompound>();
    try {
        int rows = xlSheet.getPhysicalNumberOfRows();
        for (int r = 0; r < rows; r++) {
            XSSFRow row = xlSheet.getRow(r);
            if (row == null)
                continue;
            int cells = row.getPhysicalNumberOfCells();
            if (r == 0) {// Allocate the number of patients we have
                for (int i = 1; i < cells; i++)
                    compounds.add(new SESubstanceCompound());
            }
            property = row.getCell(0).getStringCellValue();
            if (property == null || property.isEmpty())
                continue;
            Log.info("Processing Patient Field : " + property);
            if (property.equals("Data Type"))
                continue;// Only one type at this point
            for (int c = 1; c < cells; c++) {
                String cellValue = null;
                XSSFCell cell = row.getCell(c);
                switch (cell.getCellType()) {
                case XSSFCell.CELL_TYPE_NUMERIC:
                    cellValue = Double.toString(cell.getNumericCellValue());
                    break;
                case XSSFCell.CELL_TYPE_STRING:
                    cellValue = cell.getStringCellValue();
                    break;
                }
                if (cellValue == null || cellValue.isEmpty())
                    continue;
                int split = cellValue.indexOf(" ");
                // Pull The Value
                if (split == -1) {
                    value = cellValue;
                    unit = "";
                } else {
                    value = cellValue.substring(0, split);
                    unit = cellValue.substring(split + 1);
                }
                compound = compounds.get(c - 1);
                if (property.equals("Compound Name")) {
                    compound.setName(value);
                    continue;
                }
                if (property.equals("Component Name")) {
                    s = substances.get(value);
                    component = compound.getComponent(s);
                    continue;
                }
                if (!setProperty(component, property, value, unit)) {
                    Log.error("Error setting property");
                    break;
                }
            }
        }
    } catch (Exception ex) {
        Log.error("Error reading XLS", ex);
        return null;
    }
    return compounds;
}