Example usage for org.apache.poi.hssf.usermodel HSSFWorkbook close

List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook close

Introduction

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

Prototype

@Override
public void close() throws IOException 

Source Link

Document

Closes the underlying POIFSFileSystem from which the Workbook was read, if any.

Usage

From source file:com.onsemi.cdars.config.FtpConfigUSL24hrs.java

public void cronRun() throws FileNotFoundException, IOException {
    LOGGER.info(/* w w w .  ja va  2  s . c o m*/
            "Upper Spec Limit (USL Shipping) executed at everyday on 8:00 am. Current time is : " + new Date());

    String username = System.getProperty("user.name");
    if (!"fg79cj".equals(username)) {
        username = "imperial";
    }
    DateFormat dateFormat = new SimpleDateFormat("ddMMMyyyy");
    Date date = new Date();
    String todayDate = dateFormat.format(date);

    String reportName = "C:\\Users\\" + username
            + "\\Documents\\CDARS\\HIMS USL for Sending to SBN Factory Report (" + todayDate + ").xls";

    FileOutputStream fileOut = new FileOutputStream(reportName);
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("HIMS PROCESS EXCEED USL");
    CellStyle style = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setBoldweight(HSSFFont.COLOR_NORMAL);
    font.setBold(true);
    font.setColor(HSSFColor.DARK_BLUE.index);
    style.setFont(font);
    sheet.createFreezePane(0, 1); // Freeze 1st Row

    HSSFRow rowhead = sheet.createRow((short) 0);
    rowhead.setRowStyle(style);

    HSSFCell cell1_0 = rowhead.createCell(0);
    cell1_0.setCellStyle(style);
    cell1_0.setCellValue("HARDWARE TYPE");

    HSSFCell cell1_1 = rowhead.createCell(1);
    cell1_1.setCellStyle(style);
    cell1_1.setCellValue("HARDWARE ID");

    HSSFCell cell1_2 = rowhead.createCell(2);
    cell1_2.setCellStyle(style);
    cell1_2.setCellValue("MATERIAL PASS NO");

    HSSFCell cell1_3 = rowhead.createCell(3);
    cell1_3.setCellStyle(style);
    cell1_3.setCellValue("DURATION");

    HSSFCell cell1_4 = rowhead.createCell(4);
    cell1_4.setCellStyle(style);
    cell1_4.setCellValue("CURRENT STATUS");

    //            WhUSLDAO whUslDAO = new WhUSLDAO();
    //            List<WhUSL> whUslList = whUslDAO.getWhUSLLog();
    String materialPassNo = "";
    String hardwareId = "";
    String hardwareType = "";
    String duration = "";
    String status = "";
    String text = "";

    WhStatusLogDAO statusD = new WhStatusLogDAO();
    List<WhStatusLog> whUslList = statusD.getTLReqToApproveAndApproveToMpCreatedList();

    boolean checksize1 = false;
    boolean checksize2 = false;
    for (int i = 0; i < whUslList.size(); i++) {
        checksize1 = true;
        hardwareType = whUslList.get(i).getEquipmentType();
        hardwareId = whUslList.get(i).getEquipmentId();
        materialPassNo = whUslList.get(i).getMpNo();
        String hourReqApp = whUslList.get(i).getRequestToApprove24();
        String hourReqAppIfNull = whUslList.get(i).getRequestToApproveTemp24();
        String hourAppMp = whUslList.get(i).getApproveToMPCreated24();
        String hourAppMpIfNull = whUslList.get(i).getApproveToMPCreatedTemp24();

        boolean flag = false;

        if (hourReqAppIfNull != null) {
            if (Integer.parseInt(hourReqAppIfNull) >= 24 && hourReqApp == null) {
                duration = whUslList.get(i).getRequestToApproveTemp();
                status = "Pending Approval";
                flag = true;
            }
        }

        if (hourAppMpIfNull != null) {
            if (Integer.parseInt(hourAppMpIfNull) >= 24 && hourAppMp == null && hourReqApp != null) {
                duration = whUslList.get(i).getApproveToMPCreatedTemp();
                status = "Pending Material Pass Number";
                flag = true;
            }
        }

        if (flag == true) {
            HSSFRow contents = sheet.createRow(sheet.getLastRowNum() + 1);
            //                
            HSSFCell cell2_0 = contents.createCell(0);
            cell2_0.setCellValue(hardwareType);

            HSSFCell cell2_1 = contents.createCell(1);
            cell2_1.setCellValue(hardwareId);

            HSSFCell cell2_2 = contents.createCell(2);
            cell2_2.setCellValue(materialPassNo);

            HSSFCell cell2_3 = contents.createCell(3);
            cell2_3.setCellValue(duration);

            HSSFCell cell2_4 = contents.createCell(4);
            cell2_4.setCellValue(status);
        }
    }

    WhStatusLogDAO statusD2 = new WhStatusLogDAO();
    List<WhStatusLog> whUslList2 = statusD2.getTLMpCreatedToFinalInventoryDateList();

    for (int i = 0; i < whUslList2.size(); i++) {
        checksize2 = true;
        hardwareType = whUslList2.get(i).getEquipmentType();
        hardwareId = whUslList2.get(i).getEquipmentId();
        materialPassNo = whUslList2.get(i).getMpNo();
        String hourMpTt = whUslList2.get(i).getMpCreatedToTtScan24();
        String hourMpTtIfNull = whUslList2.get(i).getMpCreatedToTtScanTemp24();
        String hourTtBs = whUslList2.get(i).getTtScanToBsScan24();
        String hourTtBsIfNull = whUslList2.get(i).getTtScanToBsScanTemp24();
        String hourBsShip = whUslList2.get(i).getBsScanToShip24();
        String hourBsShipIfNull = whUslList2.get(i).getBsScanToShipTemp24();
        String hourShipInv = whUslList2.get(i).getShipToInventory24();
        String hourShipInvIfNull = whUslList2.get(i).getShipToInventoryTemp24();

        boolean flag = false;

        if (hourMpTtIfNull != null) {
            if (Integer.parseInt(hourMpTtIfNull) >= 24 && hourMpTt == null) {
                duration = whUslList2.get(i).getMpCreatedToTtScanTemp();
                status = "Pending Trip Ticket Scanning";
                flag = true;
            }
        }

        if (hourTtBsIfNull != null) {
            if (Integer.parseInt(hourTtBsIfNull) >= 24 && hourTtBs == null && hourMpTt != null) {
                duration = whUslList2.get(i).getTtScanToBsScanTemp();
                status = "Pending Barcode Sticker Scanning";
                flag = true;
            }
        }

        if (hourBsShipIfNull != null) {
            if (Integer.parseInt(hourBsShipIfNull) >= 24 && hourBsShip == null && hourTtBs != null
                    && hourMpTt != null) {
                duration = whUslList2.get(i).getBsScanToShipTemp();
                status = "Pending Shipping Packing List";
                flag = true;
            }
        }

        if (hourShipInvIfNull != null) {
            if (Integer.parseInt(hourShipInvIfNull) >= 24 && hourShipInv == null && hourBsShip != null
                    && hourTtBs != null && hourMpTt != null) {
                duration = whUslList2.get(i).getShipToInventoryTemp();
                status = "Pending Inventory in Seremban Factory";
                flag = true;
            }
        }

        if (flag == true) {
            HSSFRow contents = sheet.createRow(sheet.getLastRowNum() + 1);
            //                
            HSSFCell cell2_0 = contents.createCell(0);
            cell2_0.setCellValue(hardwareType);

            HSSFCell cell2_1 = contents.createCell(1);
            cell2_1.setCellValue(hardwareId);

            HSSFCell cell2_2 = contents.createCell(2);
            cell2_2.setCellValue(materialPassNo);

            HSSFCell cell2_3 = contents.createCell(3);
            cell2_3.setCellValue(duration);

            HSSFCell cell2_4 = contents.createCell(4);
            cell2_4.setCellValue(status);
        }

    }

    if (checksize1 == true || checksize2 == true) {
        workbook.write(fileOut);
        workbook.close();

        //send email
        LOGGER.info("send email to person in charge");
        EmailSender emailSender = new EmailSender();
        com.onsemi.cdars.model.User user = new com.onsemi.cdars.model.User();
        user.setFullname("All");

        List<String> a = new ArrayList<String>();

        String emailApprover = "";
        String emaildistList1 = "";
        String emaildistList2 = "";
        String emaildistList3 = "";
        String emaildistList4 = "";

        emailApprover = "fg79cj@onsemi.com";
        a.add(emailApprover);

        EmailConfigDAO econfD = new EmailConfigDAO();
        int countDistList1 = econfD.getCountTask("Dist List 1");
        if (countDistList1 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList1 = econfD.getEmailConfigByTask("Dist List 1");
            emaildistList1 = distList1.getEmail();
            a.add(emaildistList1);
        }
        econfD = new EmailConfigDAO();
        int countDistList2 = econfD.getCountTask("Dist List 2");
        if (countDistList2 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList2 = econfD.getEmailConfigByTask("Dist List 2");
            emaildistList2 = distList2.getEmail();
            a.add(emaildistList2);
        }
        econfD = new EmailConfigDAO();
        int countDistList3 = econfD.getCountTask("Dist List 3");
        if (countDistList3 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList3 = econfD.getEmailConfigByTask("Dist List 3");
            emaildistList3 = distList3.getEmail();
            a.add(emaildistList3);
        }
        econfD = new EmailConfigDAO();
        int countDistList4 = econfD.getCountTask("Dist List 4");
        if (countDistList4 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList4 = econfD.getEmailConfigByTask("Dist List 4");
            emaildistList4 = distList4.getEmail();
            a.add(emaildistList4);
        }
        String[] myArray = new String[a.size()];
        String[] emailTo = a.toArray(myArray);
        //            String[] to = {"fg79cj@onsemi.com"};
        emailSender.htmlEmailWithAttachment(servletContext, user, //user name requestor
                emailTo,
                new File("C:\\Users\\"
                        + username + "\\Documents\\CDARS\\HIMS USL for Sending to SBN Factory Report ("
                        + todayDate + ").xls"),
                "List of Hardware Exceed USL (24 hours) for Sending to SBN Factory", //subject
                "Report for Hardware Process from HIMS(Hadware Sending to SBN Factory) that exceed Upper Specs Limit (24 hours) has been made. <br />"
                        + "Hence, attached is the report file for your view and perusal. <br /><br />"
                        + "<br /><br /> " + "<style>table, th, td {border: 1px solid black;} </style>"
                        + "<table style=\"width:100%\">" //tbl
                        + "<tr>" + "<th>HARDWARE TYPE</th> " + "<th>HARDWARE ID</th> "
                        + "<th>MATERIAL PASS NO.</th>" + "<th>DURATION</th>" + "<th>CURRENT STATUS</th>"
                        + "</tr>" + table() + "</table>" + "<br />Thank you." //msg
        );
    }

    //        }
}

From source file:com.onsemi.cdars.config.FtpConfigUSL24hrs.java

public void cronRun2() throws FileNotFoundException, IOException {
    LOGGER.info("Upper Spec Limit (USL Retrieval) executed at everyday on 8:00 am. Current time is : "
            + new Date());

    String username = System.getProperty("user.name");
    if (!"fg79cj".equals(username)) {
        username = "imperial";
    }//from  www  .  ja v  a2s  .  c o  m
    DateFormat dateFormat = new SimpleDateFormat("ddMMMyyyy");
    Date date = new Date();
    String todayDate = dateFormat.format(date);

    String reportName = "C:\\Users\\" + username
            + "\\Documents\\CDARS\\HIMS USL for Retrieving from SBN Factory Report (" + todayDate + ").xls";

    FileOutputStream fileOut = new FileOutputStream(reportName);
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("HIMS PROCESS EXCEED USL");
    CellStyle style = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setBoldweight(HSSFFont.COLOR_NORMAL);
    font.setBold(true);
    font.setColor(HSSFColor.DARK_BLUE.index);
    style.setFont(font);
    sheet.createFreezePane(0, 1); // Freeze 1st Row

    HSSFRow rowhead = sheet.createRow((short) 0);
    rowhead.setRowStyle(style);

    HSSFCell cell1_0 = rowhead.createCell(0);
    cell1_0.setCellStyle(style);
    cell1_0.setCellValue("HARDWARE TYPE");

    HSSFCell cell1_1 = rowhead.createCell(1);
    cell1_1.setCellStyle(style);
    cell1_1.setCellValue("HARDWARE ID");

    HSSFCell cell1_2 = rowhead.createCell(2);
    cell1_2.setCellStyle(style);
    cell1_2.setCellValue("MATERIAL PASS NO");

    HSSFCell cell1_3 = rowhead.createCell(3);
    cell1_3.setCellStyle(style);
    cell1_3.setCellValue("DURATION");

    HSSFCell cell1_4 = rowhead.createCell(4);
    cell1_4.setCellStyle(style);
    cell1_4.setCellValue("CURRENT STATUS");

    String materialPassNo = "";
    String hardwareId = "";
    String hardwareType = "";
    String duration = "";
    String status = "";
    String text = "";

    WhStatusLogDAO statusD = new WhStatusLogDAO();
    List<WhStatusLog> whUslList = statusD.getTLRetrieveRequestToCloseList();

    boolean checksize1 = false;
    for (int i = 0; i < whUslList.size(); i++) {
        checksize1 = true;
        hardwareType = whUslList.get(i).getEquipmentType();
        hardwareId = whUslList.get(i).getEquipmentId();
        materialPassNo = whUslList.get(i).getMpNo();
        String hourReqVer = whUslList.get(i).getRequestToVerifiedDate24();
        String hourReqVerIfNull = whUslList.get(i).getRequestToVerifiedDateTemp24();
        String hourVerShip = whUslList.get(i).getVerifiedDatetoShipDate24();
        String hourVerShipIfNull = whUslList.get(i).getVerifiedDatetoShipDateTemp24();
        String hourShipBScan = whUslList.get(i).getShipDateToBsScan24();
        String hourShipBScanIfNull = whUslList.get(i).getShipDateToBsScanTemp24();
        String hourBScanTT = whUslList.get(i).getBsScanToTtScan24();
        String hourBScanTTIfNull = whUslList.get(i).getBsScanToTtScanTemp24();

        boolean flag = false;

        if (hourReqVerIfNull != null) {
            if (Integer.parseInt(hourReqVerIfNull) >= 24 && hourReqVer == null) {
                duration = whUslList.get(i).getRequestToVerifiedDateTemp();
                status = "Pending Box Barcode Verification at SBN Factory";
                flag = true;
            }
        }

        if (hourVerShipIfNull != null) {
            if (Integer.parseInt(hourVerShipIfNull) >= 24 && hourVerShip == null && hourReqVer != null) {
                duration = whUslList.get(i).getVerifiedDatetoShipDateTemp();
                status = "Pending Shipping Packing List";
                flag = true;
            }
        }

        if (hourShipBScanIfNull != null) {
            if (Integer.parseInt(hourShipBScanIfNull) >= 24 && hourShipBScan == null && hourVerShip != null) {
                duration = whUslList.get(i).getShipDateToBsScanTemp();
                status = "Pending Box Barcode Verification at Rel Lab";
                flag = true;
            }
        }

        if (hourBScanTTIfNull != null) {
            if (Integer.parseInt(hourBScanTTIfNull) >= 24 && hourBScanTT == null && hourShipBScan != null) {
                duration = whUslList.get(i).getBsScanToTtScanTemp();
                status = "Pending Trip Ticket Verification at Rel Lab";
                flag = true;
            }
        }

        if (flag == true) {
            HSSFRow contents = sheet.createRow(sheet.getLastRowNum() + 1);
            //                
            HSSFCell cell2_0 = contents.createCell(0);
            cell2_0.setCellValue(hardwareType);

            HSSFCell cell2_1 = contents.createCell(1);
            cell2_1.setCellValue(hardwareId);

            HSSFCell cell2_2 = contents.createCell(2);
            cell2_2.setCellValue(materialPassNo);

            HSSFCell cell2_3 = contents.createCell(3);
            cell2_3.setCellValue(duration);

            HSSFCell cell2_4 = contents.createCell(4);
            cell2_4.setCellValue(status);
        }
    }

    if (checksize1 == true) {
        workbook.write(fileOut);
        workbook.close();

        //send email
        LOGGER.info("send email to person in charge");
        EmailSender emailSender = new EmailSender();
        com.onsemi.cdars.model.User user = new com.onsemi.cdars.model.User();
        user.setFullname("All");

        List<String> a = new ArrayList<String>();

        String emailApprover = "";
        String emaildistList1 = "";
        String emaildistList2 = "";
        String emaildistList3 = "";
        String emaildistList4 = "";

        emailApprover = "fg79cj@onsemi.com";
        a.add(emailApprover);

        EmailConfigDAO econfD = new EmailConfigDAO();
        int countDistList1 = econfD.getCountTask("Dist List 1");
        if (countDistList1 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList1 = econfD.getEmailConfigByTask("Dist List 1");
            emaildistList1 = distList1.getEmail();
            a.add(emaildistList1);
        }
        econfD = new EmailConfigDAO();
        int countDistList2 = econfD.getCountTask("Dist List 2");
        if (countDistList2 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList2 = econfD.getEmailConfigByTask("Dist List 2");
            emaildistList2 = distList2.getEmail();
            a.add(emaildistList2);
        }
        econfD = new EmailConfigDAO();
        int countDistList3 = econfD.getCountTask("Dist List 3");
        if (countDistList3 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList3 = econfD.getEmailConfigByTask("Dist List 3");
            emaildistList3 = distList3.getEmail();
            a.add(emaildistList3);
        }
        econfD = new EmailConfigDAO();
        int countDistList4 = econfD.getCountTask("Dist List 4");
        if (countDistList4 == 1) {
            econfD = new EmailConfigDAO();
            EmailConfig distList4 = econfD.getEmailConfigByTask("Dist List 4");
            emaildistList4 = distList4.getEmail();
            a.add(emaildistList4);
        }
        String[] myArray = new String[a.size()];
        String[] emailTo = a.toArray(myArray);
        //                String[] to = {"hmsrelon@gmail.com", "hmsrelontest@gmail.com"};  //9/11/16
        //            String[] to = {"fg79cj@onsemi.com"};
        emailSender.htmlEmailWithAttachment(servletContext, user, //user name requestor
                emailTo,
                new File("C:\\Users\\"
                        + username + "\\Documents\\CDARS\\HIMS USL for Retrieving from SBN Factory Report ("
                        + todayDate + ").xls"),
                "List of Hardware Exceed USL (24 hours) for Retrieval from SBN Factory", //subject
                "Report for Hardware Process from HIMS(Hadware Retrieval from SBN Factory) that exceed Upper Specs Limit (24 hours) has been made. <br />"
                        + "Hence, attached is the report file for your view and perusal. <br /><br />"
                        + "<br /><br /> " + "<style>table, th, td {border: 1px solid black;} </style>"
                        + "<table style=\"width:100%\">" //tbl
                        + "<tr>" + "<th>HARDWARE TYPE</th> " + "<th>HARDWARE ID</th> "
                        + "<th>MATERIAL PASS NO.</th>" + "<th>DURATION</th>" + "<th>CURRENT STATUS</th>"
                        + "</tr>" + table2() + "</table>" + "<br />Thank you." //msg
        );
    }

    //        }
}

From source file:com.opendoorlogistics.core.tables.io.PoiIO.java

License:Open Source License

public static boolean exportDatastore(ODLDatastore<? extends ODLTableReadOnly> ds, File file, boolean xlsx,
        ProcessingApi processing, ExecutionReport report) {
    //tmpFileBugFix();

    Workbook wb = null;/*from ww w.  j a v  a 2  s  .  co  m*/
    SXSSFWorkbook sxssfwb = null;
    HSSFWorkbook hssfwb = null;
    if (xlsx == false) {
        hssfwb = new HSSFWorkbook();
        hssfwb.createInformationProperties();
        hssfwb.getSummaryInformation().setAuthor(AppConstants.ORG_NAME);
        wb = hssfwb;
    } else {
        //   sxssfwb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
        sxssfwb = new SXSSFWorkbook(null, 100, false, true);
        wb = sxssfwb;

        //   XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
        ///   POIXMLProperties xmlProps = sxssfwb.
        //POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties();
        //   coreProps.setCreator(AppConstants.ORG_NAME);
        //   wb = xssfWorkbook;
    }

    try {
        // save schema
        addSchema(ds, wb);

        for (ODLTableDefinition table : TableUtils.getAlphabeticallySortedTables(ds)) {
            ODLTableReadOnly tro = (ODLTableReadOnly) table;
            Sheet sheet = wb.createSheet(tro.getName());
            if (sheet == null) {
                return false;
            }

            exportTable(sheet, tro, 0, processing, report);

            if (processing != null && processing.isCancelled()) {
                return false;
            }
        }

        if (processing != null) {
            processing.postStatusMessage("Saving whole workbook to disk.");
        }

        saveWorkbook(file, wb);

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (sxssfwb != null) {
            sxssfwb.dispose();
        }

        if (hssfwb != null) {
            try {
                hssfwb.close();
            } catch (Exception e2) {
                // TODO: handle exception
            }
        }
    }

    return true;
}

From source file:com.zxy.commons.poi.excel.ExcelUtils.java

License:Apache License

/**
 * ?Excelsheet/* w  w  w . j a v a 2s  .co  m*/
 * 
 * @param inputPath ???Excel
 * @return Excel?
 * @throws IOException IOException
 */
public static Map<String, Table<Integer, String, String>> readAll2table(String inputPath) throws IOException {
    Map<String, Table<Integer, String, String>> tables = Maps.newLinkedHashMap();
    FileInputStream inputStream = null;
    HSSFWorkbook wb = null;
    try {
        inputStream = new FileInputStream(inputPath);
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
        // HSSFWorkbook
        POIFSFileSystem fs = new POIFSFileSystem(bufferedInputStream);
        wb = new HSSFWorkbook(fs);
        List<String> columnNames = Lists.newLinkedList();
        for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) {
            Table<Integer, String, String> table = TreeBasedTable.create();
            HSSFSheet st = wb.getSheetAt(sheetIndex);
            String sheetName = st.getSheetName();
            for (int rowIndex = 0; rowIndex <= st.getLastRowNum(); rowIndex++) {
                HSSFRow row = st.getRow(rowIndex);
                for (int columnIndex = 0; columnIndex < row.getLastCellNum(); columnIndex++) {
                    HSSFCell cell = row.getCell(columnIndex);
                    if (cell != null) {
                        if (rowIndex == 0) { // 
                            columnNames.add(cell.getStringCellValue());
                        } else {
                            String value = cell.getStringCellValue();
                            table.put(rowIndex, columnNames.get(columnIndex), value);
                        }
                    }
                }
            }
            tables.put(sheetName, table);
        }
        return tables;
    } finally {
        if (wb != null) {
            wb.close();
        }
        if (inputStream != null) {
            inputStream.close();
        }
    }
}

From source file:converttooem.ConvertToOemFrame.java

private void convertButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_convertButtonActionPerformed
    progressBar.setValue(0);/*from  ww w.ja  v a  2s . c  o  m*/
    if (selectedFile != null && selectedFile.exists()) {
        String outFileName = selectedFile.getAbsolutePath().replace(".xls", ".dat");
        try {
            //Open the xls file
            HSSFWorkbook wb = null;
            try {
                wb = new HSSFWorkbook(new FileInputStream(selectedFile));
            } catch (NotOLE2FileException e) {
                JOptionPane.showMessageDialog(this, "That file doesn't appear to be a '.xls' file!", "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
            if (wb == null) {
                return;
            }
            //Open the second(1) sheet
            HSSFSheet sheet = wb.getSheetAt(1);
            //Pull scan meta data
            ScanData sd = new ScanData();
            sd.scanner = sheet.getRow(11).getCell(8).getStringCellValue();
            sd.mileage = sheet.getRow(37).getCell(4).getNumericCellValue();
            sd.standby = sheet.getRow(38).getCell(4).getNumericCellValue();
            sheet = wb.getSheetAt(3);
            sd.scanPrice = sheet.getRow(32).getCell(4).getNumericCellValue();
            sd.totalPrice = sd.scanPrice + sd.mileage + sd.standby + 50.0;
            //Open the first(0) sheet
            sheet = wb.getSheetAt(0);
            sd.numberOfJoints = (int) sheet.getRow(107).getCell(15).getNumericCellValue();
            sd.company = sheet.getRow(2).getCell(9).getStringCellValue();
            System.out.println("Company: " + sd.company);
            sd.well = sheet.getRow(2).getCell(5).getStringCellValue();
            sd.companyMan = sheet.getRow(36).getCell(15).getStringCellValue();
            sd.size = "" + sheet.getRow(36).getCell(2).getNumericCellValue();
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(selectedFile.lastModified());

            sd.date = c.getTime();
            sd.grade = sheet.getRow(36).getCell(11).getStringCellValue();
            sd.pullingUnit = sheet.getRow(36).getCell(7).getStringCellValue();
            System.out.println(sd);
            progressBar.setValue(10);

            PrintWriter out = new PrintWriter(new FileWriter(new File(outFileName)));
            out.println("2");
            out.println(sd.numberOfJoints);
            out.println("3");
            out.println("2");
            //Yellow Range
            int yellowMin = getInt(yellowMinField);
            int yellowMax = getInt(yellowMaxField);
            out.println(yellowMin);
            out.println(yellowMax);
            //Blue Range
            int blueMin = getInt(blueMinField);
            int blueMax = getInt(blueMaxField);
            out.println(blueMin);
            out.println(blueMax);
            //Green Range
            int greenMin = getInt(greenMinField);
            int greenMax = getInt(greenMaxField);
            out.println(greenMin);
            out.println(greenMax);
            //Red Range
            int redMin = getInt(redMinField);
            int redMax = getInt(redMaxField);
            out.println(redMin);
            out.println(redMax);
            //Date

            String dateString = String.format("%s-%s-%s", "" + c.get(Calendar.YEAR),
                    (sd.date.getMonth() + 1 < 10 ? "0" + (sd.date.getMonth() + 1)
                            : "" + sd.date.getMonth() + 1),
                    (sd.date.getDate() < 10 ? "0" + sd.date.getDate() : "" + sd.date.getMonth()));
            System.out.println(c.get(Calendar.YEAR));
            System.out.println(c.get(Calendar.MONTH + 1));
            System.out.println(c.get(Calendar.DATE));
            System.out.println(dateString);
            out.println(dateString);
            //Name
            out.println(selectedFile.getName().replace(".xls", ""));
            out.println();
            out.println();
            out.println(sd.grade);
            out.println();
            out.println(sd.company);
            out.println(sd.well);
            out.println("Company man: " + sd.companyMan);
            out.println();
            out.println();
            out.println("Stealth Oilwell Services");
            out.println("7668 W. 42ND Odessa, TX 79764");
            out.println("Office: 432-333-3600");
            out.println("Scan Tech: " + sd.scanner);
            out.println();
            out.println("Scan: " + sd.scanPrice);
            out.println("Mileage: " + sd.mileage);
            out.println("Standby: " + sd.standby);
            out.println("Rubber Charge: $50.00");
            out.println("Total: " + sd.totalPrice);
            out.println();
            out.println("THIS IS NOT AN INVOICE");
            for (int i = 0; i < 15; i++) {
                out.println();
            }
            out.println("HOLE-PIT");
            out.println("RODWEAR-SPLIT");
            out.println("COLOR");
            for (int i = 0; i < 4; i++) {
                out.println();
            }
            progressBar.setValue(20);
            System.out.println(sd.numberOfJoints);
            int onRow = 113;
            for (int i = 0; i < sd.numberOfJoints; i++) {
                int pit = ((int) (sheet.getRow(onRow).getCell(2).getNumericCellValue() * 100.0));
                int wear = ((int) (sheet.getRow(onRow).getCell(11).getNumericCellValue() * 100.0));
                int worst = Math.max(pit, wear);
                out.println(pit);
                out.println(wear);
                if (worst >= yellowMin && worst <= yellowMax) {
                    out.println("YELLOW");
                } else if (worst >= blueMin && worst <= blueMax) {
                    out.println("BLUE");
                } else if (worst >= greenMin && worst <= greenMax) {
                    out.println("GREEN");
                } else if (worst >= redMin && worst <= redMax) {
                    out.println("RED");
                } else {
                    out.println("UNDEFINED");
                }
                for (int j = 0; j < 4; j++) {
                    out.println();
                }
                onRow++;
                switch (onRow) {
                case 168:
                    onRow = 175;
                    break;
                case 225:
                    onRow = 232;
                    break;
                case 282:
                    onRow = 289;
                    break;
                case 339:
                    onRow = 346;
                    break;
                case 396:
                    onRow = 403;
                    break;
                case 453:
                    onRow = 460;
                    break;
                default:
                    break;
                }
                progressBar.setValue(20 + ((int) ((i / sd.numberOfJoints) * 75)));
            }
            wb.close();
            out.flush();
            out.close();
            progressBar.setValue(100);
            System.out.println("Done");
        } catch (IOException ex) {
            Logger.getLogger(ConvertToOemFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:data.services.BaseParamService.java

public void updateFromXml(File fl) {
    try {/*w  w  w  .ja  v a  2 s  . com*/
        FileInputStream fi = new FileInputStream(fl);
        try {
            HSSFWorkbook workbook = new HSSFWorkbook(fi);
            HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator<Row> it = sheet.iterator();
            it.next();
            while (it.hasNext()) {
                Row row = it.next();

                Cell uidc = row.getCell(0);
                String uid = "";
                if (uidc != null) {
                    uid = StringAdapter.HSSFSellValue(uidc).trim();
                    if (uid.contains(".")) {
                        int point = uid.indexOf(".");
                        uid = uid.substring(0, point);
                    }
                }

                Cell namec = row.getCell(1);
                String name = "";
                if (namec != null) {
                    name = StringAdapter.HSSFSellValue(namec).trim();
                }

                Cell typec = row.getCell(2);
                String type = "";
                if (typec != null) {
                    type = StringAdapter.HSSFSellValue(typec).trim();
                    //ParamType ptype = ParamType.getParamTypeFromString(type);
                }

                Cell statc = row.getCell(3);
                String stat = "";
                if (statc != null) {
                    stat = StringAdapter.HSSFSellValue(statc).trim();
                    //StaticType stype = StaticType.getStaticTypeFromString(stat);
                }

                Cell ppc = row.getCell(4);
                String ppStr = "";
                if (ppc != null) {
                    ppStr = StringAdapter.HSSFSellValue(ppc).trim();
                }

                Cell radc = row.getCell(5);
                String rad = "";
                if (radc != null) {
                    rad = StringAdapter.HSSFSellValue(radc).trim();
                    if (rad.contains(".")) {
                        int point = rad.indexOf(".");
                        rad = rad.substring(0, point);
                    }
                    if (rad.trim().equals("0")) {
                        rad = "";
                    } else {
                        rad = rad.replace(" ", "");
                    }
                }

                Cell ac = row.getCell(6);
                String a = "0";
                if (ac != null) {
                    a = StringAdapter.HSSFSellValue(ac);
                    if (a.contains(".")) {
                        int point = a.indexOf(".");
                        a = a.substring(0, point);
                    }
                    if (a.equals("")) {
                        a = "0";
                    }
                }
                Cell vc = row.getCell(7);
                String v = "0";
                if (vc != null) {
                    v = StringAdapter.HSSFSellValue(vc);
                    if (v.contains(".")) {
                        int point = v.indexOf(".");
                        v = v.substring(0, point);
                    }
                    if (v.equals("")) {
                        v = "0";
                    }
                }
                Cell kc = row.getCell(8);
                String k = "0";
                if (kc != null) {
                    k = StringAdapter.HSSFSellValue(ac);
                    if (k.contains(".")) {
                        int point = k.indexOf(".");
                        k = k.substring(0, point);
                    }
                    if (k.equals("")) {
                        k = "0";
                    }
                }

                BaseParam bp = getBaseParam(uid);
                if (bp != null) {
                    bp.setName(name);
                    bp.setParamType(ParamType.getParamTypeFromString(type));
                    bp.setStaticType(StaticType.getStaticTypeFromString(stat));
                    //bp.setPercentParams(getPercentParamsFromString(ppStr,bp));
                    bp.setRadical(rad);
                    bp.setAudial(a);
                    bp.setVisual(v);
                    bp.setKinestet(k);
                    update(bp, getPercentParamsFromString(ppStr, bp));
                } else {
                    bp = new BaseParam();
                    bp.setUid(uid);
                    bp.setName(name);
                    bp.setParamType(ParamType.getParamTypeFromString(type));
                    bp.setStaticType(StaticType.getStaticTypeFromString(stat));
                    bp.setPercentParams(getPercentParamsFromString(ppStr, bp));
                    bp.setRadical(rad);
                    bp.setAudial(a);
                    bp.setVisual(v);
                    bp.setKinestet(k);
                    createParam(bp);
                }
            }
            workbook.close();
        } catch (Exception e) {
            addError(StringAdapter.getStackTraceException(e));
        }
        fi.close();
    } catch (Exception e) {
        addError("  xml");
        addError(e.getMessage());
    }
}

From source file:data.services.CarCompletionOptionService.java

public void updateFromXml(File fl) {
    try {//from ww w  .jav  a2s. c  o m
        FileInputStream fi = new FileInputStream(fl);
        try {
            HSSFWorkbook workbook = new HSSFWorkbook(fi);
            HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator<Row> it = sheet.iterator();
            while (it.hasNext()) {
                Row row = it.next();

                Cell idCell = row.getCell(0);
                if (idCell != null) {
                    Long id = StringAdapter.toLong(StringAdapter.HSSFSellValue(idCell));

                    Cell uidc = row.getCell(3);
                    String uid = "";
                    if (uidc != null) {
                        uid = StringAdapter.HSSFSellValue(uidc);
                        if (uid.contains(".")) {
                            int point = uid.indexOf(".");
                            uid = uid.substring(0, point);
                        }
                    }

                    Cell valc = row.getCell(4);
                    Double val = (double) 0;
                    if (valc != null) {
                        String valstr = StringAdapter.HSSFSellValue(valc).replace(",", ".").trim();
                        val = StringAdapter.toDouble(valstr);
                    }

                    Cell percc = row.getCell(5);
                    Long perc = (long) 0;
                    if (percc != null) {
                        String percstr = StringAdapter.HSSFSellValue(percc);
                        if (percstr.contains(".")) {
                            int point = percstr.indexOf(".");
                            percstr = percstr.substring(0, point);
                        }
                        if (!percstr.equals("")) {
                            perc = StringAdapter.toLong(percstr);
                        }
                    }

                    Cell radc = row.getCell(6);
                    String rad = "";
                    if (radc != null) {
                        rad = StringAdapter.HSSFSellValue(radc).trim();
                        if (rad.contains(".")) {
                            int point = rad.indexOf(".");
                            rad = rad.substring(0, point);
                        }
                        if (rad.trim().equals("0")) {
                            rad = "";
                        } else {
                            rad = rad.replace(" ", "");
                        }
                    }

                    Cell ac = row.getCell(7);
                    String a = "0";
                    if (ac != null) {
                        a = StringAdapter.HSSFSellValue(ac);
                        if (a.contains(".")) {
                            int point = a.indexOf(".");
                            a = a.substring(0, point);
                        }
                        if (a.equals("")) {
                            a = "0";
                        }
                    }
                    Cell vc = row.getCell(8);
                    String v = "0";
                    if (vc != null) {
                        v = StringAdapter.HSSFSellValue(vc);
                        if (v.contains(".")) {
                            int point = v.indexOf(".");
                            v = v.substring(0, point);
                        }
                        if (v.equals("")) {
                            v = "0";
                        }
                    }
                    Cell kc = row.getCell(9);
                    String k = "0";
                    if (kc != null) {
                        k = StringAdapter.HSSFSellValue(ac);
                        if (k.contains(".")) {
                            int point = k.indexOf(".");
                            k = k.substring(0, point);
                        }
                        if (k.equals("")) {
                            k = "0";
                        }
                    }

                    CarCompletionOption cl = carCompletionOptionDao.find(id);
                    if (cl != null) {
                        cl.setUid(uid);
                        cl.setParamValue(val);
                        cl.setPercentValue(perc);
                        cl.setRadical(rad);
                        cl.setAudial(Integer.valueOf(a));
                        cl.setVisual(Integer.valueOf(v));
                        cl.setKinestet(Integer.valueOf(k));
                        if (validate(cl)) {
                            carCompletionOptionDao.update(cl);
                        }
                    }
                }
            }
            workbook.close();
        } catch (Exception e) {
            addError(StringAdapter.getStackTraceException(e));
        }
        fi.close();
    } catch (Exception e) {
        addError("  xml");
        addError(StringAdapter.getStackTraceException(e));
    }
}

From source file:data.services.CarOptionValueService.java

public void updateFromXml(File fl) throws Exception {
    try {/*w ww  .  j  a va  2  s.c  o  m*/
        FileInputStream fi = new FileInputStream(fl);
        int i = 0;
        int m = 1;
        try {
            HSSFWorkbook workbook = new HSSFWorkbook(fi);
            HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator<Row> it = sheet.iterator();
            it.next();
            while (it.hasNext()) {
                Row row = it.next();
                m++;
                Cell idCell = row.getCell(0);
                Long covId = null;
                if (idCell != null) {
                    String supstr = StringAdapter.HSSFSellValue(idCell).trim();
                    if (supstr.contains(".")) {
                        int point = supstr.indexOf(".");
                        supstr = supstr.substring(0, point);
                    }
                    if (!supstr.equals("")) {
                        covId = StringAdapter.toLong(supstr);
                    }
                }
                CarOptionValue cov = carOptionValueDao.find(covId);
                if (cov != null) {

                    Cell radc = row.getCell(4);
                    String rad = "";
                    if (radc != null) {
                        rad = StringAdapter.HSSFSellValue(radc).trim();
                        if (rad.contains(".")) {
                            int point = rad.indexOf(".");
                            rad = rad.substring(0, point);
                        }
                        if (rad.trim().equals("0")) {
                            rad = "";
                        } else {
                            rad = rad.replace(" ", "");
                        }
                    }

                    Cell valc = row.getCell(5);
                    Double val = (double) 0;
                    if (valc != null) {
                        String valstr = StringAdapter.HSSFSellValue(valc).replace(",", ".").trim();
                        val = StringAdapter.toDouble(valstr);
                    }

                    Cell percc = row.getCell(6);
                    Long perc = (long) 0;
                    if (percc != null) {
                        String percstr = StringAdapter.HSSFSellValue(percc);
                        if (percstr.contains(".")) {
                            int point = percstr.indexOf(".");
                            percstr = percstr.substring(0, point);
                        }
                        if (!percstr.equals("")) {
                            perc = StringAdapter.toLong(percstr);
                        }
                    }

                    Cell ac = row.getCell(7);
                    Integer a = 0;
                    if (ac != null) {
                        String supstr = StringAdapter.HSSFSellValue(ac);
                        if (supstr.contains(".")) {
                            int point = supstr.indexOf(".");
                            supstr = supstr.substring(0, point);
                        }
                        if (!supstr.equals("")) {
                            a = Integer.valueOf(supstr);
                        }
                    }
                    Cell vc = row.getCell(8);
                    Integer v = 0;
                    if (vc != null) {
                        String supstr = StringAdapter.HSSFSellValue(vc);
                        if (supstr.contains(".")) {
                            int point = supstr.indexOf(".");
                            supstr = supstr.substring(0, point);
                        }
                        if (!supstr.equals("")) {
                            v = Integer.valueOf(supstr);
                        }
                    }
                    Cell kc = row.getCell(9);
                    Integer k = 0;
                    if (kc != null) {
                        String supstr = StringAdapter.HSSFSellValue(kc);
                        if (supstr.contains(".")) {
                            int point = supstr.indexOf(".");
                            supstr = supstr.substring(0, point);
                        }
                        if (!supstr.equals("")) {
                            k = Integer.valueOf(supstr);
                        }
                    }
                    if (!Objects.equals(cov.getAudial(), a) || !Objects.equals(cov.getVisual(), v)
                            || !Objects.equals(cov.getKinestet(), k) || cov.getParamValue().compareTo(val) != 0
                            || !cov.getRadical().equals(rad) || cov.getPercentValue().compareTo(perc) != 0) {
                        updateByDescAndCcoId(covId, perc, val, a, v, k, rad, m);
                        i++;
                    }
                } else {
                    addError("?  ? ?  " + covId + ", ? " + m + "; ");
                }

            }
            workbook.close();
            addError(" " + i + " ?; ? ?: " + m + "; ");
        } catch (Exception e) {
            //addError(StringAdapter.getStackTraceException(e) + "str:"+i+"; ");
            throw new Exception(StringAdapter.getStackTraceException(e) + "str:" + i + "; ");
        }
        fi.close();
    } catch (Exception e) {
        //addError("  xml");
        //addError(e.getMessage());
        throw new Exception(StringAdapter.getStackTraceException(e));
    }
}

From source file:data.services.CarPropertyService.java

public void updateFromXml(File fl) {
    try {//from   www.j ava 2 s . c o  m
        FileInputStream fi = new FileInputStream(fl);
        try {
            HSSFWorkbook workbook = new HSSFWorkbook(fi);
            HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator<Row> it = sheet.iterator();
            while (it.hasNext()) {
                Row row = it.next();
                Long id = StringAdapter.toLong(StringAdapter.HSSFSellValue(row.getCell(0)));
                Cell cuid = row.getCell(3);
                String uid = "";
                if (cuid != null) {
                    uid = StringAdapter.HSSFSellValue(cuid);
                }
                Cell valc = row.getCell(4);
                Double val = (double) 0;
                if (valc != null) {
                    String valstr = StringAdapter.HSSFSellValue(valc).replace(",", ".").trim();
                    val = StringAdapter.toDouble(valstr);
                }

                Cell percc = row.getCell(5);
                Long perc = (long) 0;
                if (percc != null) {
                    String percstr = StringAdapter.HSSFSellValue(percc);
                    if (percstr.contains(".")) {
                        int point = percstr.indexOf(".");
                        percstr = percstr.substring(0, point);
                    }
                    if (!percstr.equals("")) {
                        perc = StringAdapter.toLong(percstr);
                    }
                }

                Cell crad = row.getCell(6);
                String rad = "";
                if (crad != null) {
                    rad = StringAdapter.HSSFSellValue(crad);
                    if (rad.contains(".")) {
                        int point = rad.indexOf(".");
                        rad = rad.substring(0, point);
                    }
                    if (rad.trim().equals("0")) {
                        rad = "";
                    } else {
                        rad = rad.replace(" ", "");
                    }
                }

                /*String val=StringAdapter.HSSFSellValue(row.getCell(4));
                 String pers=StringAdapter.HSSFSellValue(row.getCell(5));
                 String rad=StringAdapter.HSSFSellValue(row.getCell(6));*/
                CarProperty cl = carPropertyDao.find(id);
                if (cl != null) {
                    cl.setUid(uid);
                    cl.setParamValue(val);
                    cl.setPercentValue(perc);
                    cl.setRadical(rad);
                    if (validate(cl)) {
                        carPropertyDao.update(cl);
                    }
                }
            }
            workbook.close();
        } catch (Exception e) {
            addError(StringAdapter.getStackTraceException(e));
        }
        fi.close();
    } catch (Exception e) {
        addError("  xml");
        addError(StringAdapter.getStackTraceException(e));
    }
}

From source file:data.services.ColorGroupService.java

public void updateFromXml(File fl) {
    try {//ww w  . j a  va2  s.com
        FileInputStream fi = new FileInputStream(fl);
        try {
            HSSFWorkbook workbook = new HSSFWorkbook(fi);
            HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator<Row> it = sheet.iterator();
            while (it.hasNext()) {
                Row row = it.next();
                Long id = StringAdapter.toLong(StringAdapter.HSSFSellValue(row.getCell(0)));
                /*String uid=StringAdapter.HSSFSellValue(row.getCell(3));
                String val=StringAdapter.HSSFSellValue(row.getCell(4));
                String pers=StringAdapter.HSSFSellValue(row.getCell(5));
                String rad=StringAdapter.HSSFSellValue(row.getCell(6));*/
                String uid = row.getCell(3).getStringCellValue();
                String val = row.getCell(4).getStringCellValue();
                String pers = row.getCell(5).getStringCellValue();
                String rad = row.getCell(6).getStringCellValue();

                ColorGroup cl = colorGroupDao.find(id);
                if (cl != null) {
                    cl.setUid(uid);
                    cl.setParamValue(StringAdapter.toDouble(val));
                    cl.setParamValue(StringAdapter.toDouble(pers));
                    cl.setRadical(rad);
                    if (validate(cl)) {
                        colorGroupDao.update(cl);
                    }
                }
            }
            workbook.close();
        } catch (Exception e) {
            addError(StringAdapter.getStackTraceException(e));
        }
        fi.close();
    } catch (Exception e) {
        addError("  xml");
        addError(e.getMessage());
    }
}