Java tutorial
package singleton; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import obj.Data; public class StaticClass { private static StaticClass obj = new StaticClass(); public String ExcelPath; // lists protected List<Data> okList = new ArrayList<Data>(); protected List<Data> nokList = new ArrayList<Data>(); protected List<Data> nokNaList = new ArrayList<Data>(); protected List<Data> blankList = new ArrayList<Data>(); public static StaticClass getInstance() { if (obj == null) { obj = new StaticClass(); } return obj; } public synchronized void copyFromExcel(String fileName) throws IOException { //System.out.println("start"); Data temp; String value = ""; File inFile = new File(fileName); FileInputStream file = new FileInputStream(inFile); XSSFWorkbook wb = new XSSFWorkbook(file); XSSFSheet sheet = wb.getSheetAt(4); // Build Image Analysis page is at // the 4th sheet of Open source // license excel file. int rows = sheet.getPhysicalNumberOfRows(); for (int i = 2; i < rows; ++i) { // start index should be 2 since the // 1st row is used for titles. XSSFRow row = sheet.getRow(i); if (row != null) { int cells = row.getPhysicalNumberOfCells(); // Number of cells // at each row. temp = new Data(); for (int colIndex = 1; colIndex <= cells; colIndex++) { XSSFCell cell = row.getCell(colIndex); if (colIndex == 1) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: temp.setBinary(""); break; case XSSFCell.CELL_TYPE_STRING: temp.setBinary(cell.getStringCellValue()); break; } } else if (colIndex == 2) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: temp.setPath(""); break; case XSSFCell.CELL_TYPE_STRING: temp.setPath(cell.getStringCellValue()); break; } } else if (colIndex == 3) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: temp.setOnok(""); break; case XSSFCell.CELL_TYPE_STRING: value = cell.getStringCellValue(); temp.setOnok(value); break; } } else if (colIndex == 4) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: temp.setOssComponent(""); break; case XSSFCell.CELL_TYPE_STRING: temp.setOssComponent(cell.getStringCellValue()); break; } } else if (colIndex == 6) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: temp.setLicense(""); break; case XSSFCell.CELL_TYPE_STRING: temp.setLicense(cell.getStringCellValue()); break; } } else { continue; } } if (temp != null) { if (value.equalsIgnoreCase("nok")) { nokList.add(temp); //System.out.println("nok count : " + nokList.size()); } else if (value.equalsIgnoreCase("ok")) { okList.add(temp); //System.out.println("ok count : " + okList.size()); } else if (value.equalsIgnoreCase("nok(na)")) { nokNaList.add(temp); //System.out.println("nok(na) count : " + nokNaList.size()); } else { blankList.add(temp); //System.out.println("blank count : " + blankList.size()); } System.out.println(temp.getBinary() + "\t" + temp.getPath() + "\t\t" + temp.getOnok() + "\t\t" + temp.getLicense()); } } } } }