List of usage examples for org.apache.poi.ss.usermodel Cell getColumnIndex
int getColumnIndex();
From source file:es.SSII2.manager.ExcelManagerMail.java
public void readAccountExcel() throws FileNotFoundException, IOException { FileInputStream file;/*from ww w . ja v a 2s.co m*/ file = new FileInputStream(new File(excel)); try (XSSFWorkbook workbook = new XSSFWorkbook(file)) { XSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); Row row; // Recorremos todas las filas para mostrar el contenido de cada celda while (rowIterator.hasNext()) { workers = new WorkersID(); row = rowIterator.next(); // Obtenemos el iterator que permite recorres todas las celdas de una fila Iterator<Cell> cellIterator = row.cellIterator(); Cell celda; String celdas; while (cellIterator.hasNext()) { celda = cellIterator.next(); if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 0 && celda.getCellType() != 3) { celdas = celda.getStringCellValue(); //anadir la cuenta al arraylist y las posiciones workers.setNombre(celdas); } if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 1 && celda.getCellType() != 3) { celdas = celda.getStringCellValue(); //anadir la cuenta al arraylist y las posiciones workers.setApellido1(celdas); } if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 2 && celda.getCellType() != 3) { celdas = celda.getStringCellValue(); //anadir la cuenta al arraylist y las posiciones workers.setApellido2(celdas); } if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 6 && celda.getCellType() != 3) { celdas = celda.getStringCellValue(); //anadir la cuenta al arraylist y las posiciones workers.setEmpresa(celdas); } } //se mete los datos en el arraylist if (workers.getNombre() != null) arrayWorkers.add(workers); } } //System.out.println(arrayWorkers.get(6).getApellido1()); email = new WorkersEmail(arrayWorkers); email.creacionCorreos(); }
From source file:eu.learnpad.ontology.kpi.data.ExcelParser.java
public List<List<String>> getDataTable() throws IOException, InvalidFormatException { List<List<String>> dataTable = new ArrayList<>(); Integer rowNumber = -2;/*w w w . ja va 2 s . c o m*/ Workbook wb = WorkbookFactory.create(excelFile); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); for (Sheet sheet : wb) { if (sheet.getSheetName().equals(SHEETNAME)) { for (Row row : sheet) { //stop with the first empty row if (row.getCell(0) == null) { break; } if (rowNumber >= -1) { rowNumber++; dataTable.add(new ArrayList<String>()); } for (Cell cell : row) { String sheetName = sheet.getSheetName(); String cellRow = "Row:" + cell.getRowIndex(); String cellColumn = "Column:" + cell.getColumnIndex(); Object[] o = new Object[] { sheetName, cellRow, cellColumn }; LOGGER.log(Level.INFO, "Processing: Sheet={0} celladress={1}", o); if (rowNumber <= -1 && cell.getCellType() == Cell.CELL_TYPE_BLANK) { continue; } if (rowNumber == -2 && cell.getCellType() == Cell.CELL_TYPE_STRING) { if (cell.getRichStringCellValue().getString().equals(DATACELLNAME)) { rowNumber = -1; continue; } } //Attributes (column headers) if (rowNumber == 0) { dataTable.get(rowNumber).add(cell.getRichStringCellValue().getString()); } if (rowNumber >= 1) { switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: dataTable.get(rowNumber).add(cell.getRichStringCellValue().getString()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { dataTable.get(rowNumber).add(cell.getDateCellValue().toString()); } else { dataTable.get(rowNumber).add(Double.toString(cell.getNumericCellValue())); } break; case Cell.CELL_TYPE_BOOLEAN: dataTable.get(rowNumber).add(Boolean.toString(cell.getBooleanCellValue())); break; case Cell.CELL_TYPE_FORMULA: switch (cell.getCachedFormulaResultType()) { case Cell.CELL_TYPE_STRING: dataTable.get(rowNumber).add(cell.getRichStringCellValue().getString()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { dataTable.get(rowNumber).add(cell.getDateCellValue().toString()); } else { dataTable.get(rowNumber).add(Double.toString(cell.getNumericCellValue())); } break; case Cell.CELL_TYPE_BOOLEAN: dataTable.get(rowNumber).add(Boolean.toString(cell.getBooleanCellValue())); break; default: dataTable.get(rowNumber).add(""); } break; default: dataTable.get(rowNumber).add(""); } } } } } } return dataTable; }
From source file:excel.Excel.java
/** * @param args the command line arguments * @throws java.io.IOException/*from w w w. j av a 2s .co m*/ */ public static void main(String args[]) throws IOException { Thread a; // String nameFile = "C:\\Users\\dfcastellanosc.SOPORTECOS\\Downloads\\Files\\Informacin Etapa Productiva.xlsx"; // Process p = Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + nameFile); FileInputStream file = new FileInputStream( new File("C:\\Users\\dfcastellanosc.SOPORTECOS\\Documents\\registroempleados.xlsx")); try (XSSFWorkbook workbook = new XSSFWorkbook(file)) { XSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); Row row; while (rowIterator.hasNext()) { row = rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); Cell celda; while (cellIterator.hasNext()) { celda = cellIterator.next(); switch (celda.getCellType()) { case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(celda)) { if (celda.getColumnIndex() == 17) { System.out.println("|" + celda.getDateCellValue() + "|"); } else { System.out.print("|" + celda.getDateCellValue() + "|"); } } else { Double ds = celda.getNumericCellValue(); Long pt = ds.longValue(); if (celda.getColumnIndex() == 17) { System.out.println("|" + pt + "|"); } else { System.out.print("|" + pt + "|"); } } break; case Cell.CELL_TYPE_STRING: if (celda.getColumnIndex() == 17) { System.out.println("|" + celda.getStringCellValue() + "|"); } else { System.out.print("|" + celda.getStringCellValue() + "|"); } break; case Cell.CELL_TYPE_BOOLEAN: if (celda.getColumnIndex() == 17) { System.out.println("|" + celda.getBooleanCellValue() + "|"); } else { System.out.print("|" + celda.getBooleanCellValue() + "|"); } break; } } } workbook.close(); } }
From source file:ExcelRead.CrbRead.java
public void readFromExcel(String file, JTable table) throws IOException { XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(file)); XSSFSheet sheet = wb.getSheetAt(0);//from w ww . j a v a 2 s . co m Iterator<Row> it = sheet.iterator(); while (it.hasNext()) { Row row = it.next(); Iterator<Cell> cells = row.iterator(); while (cells.hasNext()) { Cell cell = cells.next(); int cellIndex = cell.getColumnIndex(); switch (cellIndex) { case 0: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { old_reg_cod = String.valueOf((int) cell.getNumericCellValue()); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { old_reg_cod = cell.getStringCellValue(); break; } case 1: name = cell.getStringCellValue(); break; case 2: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { new_reg_cod = String.valueOf((int) cell.getNumericCellValue()); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { new_reg_cod = cell.getStringCellValue(); break; } default: System.out.print("|"); break; } } DefaultTableModel model = (DefaultTableModel) table.getModel(); String[] data = { old_reg_cod, name, new_reg_cod }; model.addRow(data); removeAllFields(); } }
From source file:ExcelRead.PatientRead.java
public void readFromExcel(String file, JTable table) throws IOException { XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(file)); XSSFSheet sheet = wb.getSheetAt(0);// w w w.ja v a2 s . com Iterator<Row> it = sheet.iterator(); while (it.hasNext()) { Row row = it.next(); Iterator<Cell> cells = row.iterator(); while (cells.hasNext()) { Cell cell = cells.next(); int cellIndex = cell.getColumnIndex(); switch (cellIndex) { case 0: ID = (int) cell.getNumericCellValue(); // table.setValueAt(ID, i, 0); break; case 1: String[] fullName = cell.getStringCellValue().split(" "); name = fullName[1]; surname = fullName[0]; middleName = fullName[2]; // table.setValueAt(cell.getStringCellValue(), i, 1); break; case 2: SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); birthdate = sdf.format(cell.getDateCellValue()); //table.setValueAt(birthdate, i, 2); break; case 3: sex = cell.getStringCellValue(); //table.setValueAt(sex, i, 3); break; case 4: address = cell.getStringCellValue(); // table.setValueAt(address, i, 4); break; case 5: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { lpu_id = String.valueOf((int) cell.getNumericCellValue()); // table.setValueAt(lpu_id, i, 5); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { lpu_id = cell.getStringCellValue(); //table.setValueAt(lpu_id, i, 5); break; } case 6: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { crb_id = String.valueOf((int) cell.getNumericCellValue()); // table.setValueAt(crb_id, i, 6); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { crb_id = cell.getStringCellValue(); // table.setValueAt(crb_id, i, 6); break; } case 7: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { snils = String.valueOf((int) cell.getNumericCellValue()); // table.setValueAt(snils, i, 7); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { snils = cell.getStringCellValue(); //table.setValueAt(snils, i, 7); break; } case 8: String[] passport = cell.getStringCellValue().split(" "); //table.setValueAt(cell.getStringCellValue(), i, 8); pass_ser = passport[0]; pass_num = passport[1]; break; case 9: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { old_police = String.valueOf((int) cell.getNumericCellValue()); // table.setValueAt(old_police, i, 9); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { old_police = cell.getStringCellValue(); // table.setValueAt(old_police, i, 9); break; } case 10: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { new_police = String.valueOf((int) cell.getNumericCellValue()); //table.setValueAt(new_police, i, 10); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { new_police = cell.getStringCellValue(); //table.setValueAt(new_police, i, 10); break; } case 11: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { phoneNum = String.valueOf((int) cell.getNumericCellValue()); //table.setValueAt(phoneNum, i, 11); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { phoneNum = cell.getStringCellValue(); //table.setValueAt(phoneNum, i, 11); break; } default: System.out.print("|"); break; } } DefaultTableModel model = (DefaultTableModel) table.getModel(); String[] data = { String.valueOf(ID), surname + " " + name + " " + middleName, birthdate, sex, address, lpu_id, crb_id, snils, pass_ser + " " + pass_num, old_police, new_police, phoneNum }; model.addRow(data); removeAllFields(); } }
From source file:ExcelReadFile.ExcellReadSpecialite.java
public List<Specialite> readBooksFromExcelFile(String excelFilePath) throws IOException { List<Specialite> listSpecialite = new ArrayList<>(); FileInputStream file = new FileInputStream(new File(excelFilePath)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = new XSSFWorkbook(file); //Get first/desired sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(0); Sheet firstSheet = workbook.getSheetAt(0); Iterator<Row> iterator = firstSheet.iterator(); while (iterator.hasNext()) { Row nextRow = iterator.next();//from w w w . j av a 2 s . com Iterator<Cell> cellIterator = nextRow.cellIterator(); Specialite sp = new Specialite(); Admin admin = new Admin(); while (cellIterator.hasNext()) { Cell nextCell = cellIterator.next(); int columnIndex = nextCell.getColumnIndex(); switch (columnIndex) { case 0: sp.setIntitule((String) getCellValue(nextCell)); break; } } listSpecialite.add(sp); } file.close(); return listSpecialite; }
From source file:ExcelReadFile.ExcelReadMedecin.java
public List<Medecin> readBooksFromExcelFile(String excelFilePath) { List<Medecin> listMed = null; try {//from w ww.j a v a 2s . c o m listMed = new ArrayList<>(); FileInputStream file = new FileInputStream(new File(excelFilePath)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = new XSSFWorkbook(file); //Get first/desired sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(0); Sheet firstSheet = workbook.getSheetAt(0); Iterator<Row> iterator = firstSheet.iterator(); while (iterator.hasNext()) { Row nextRow = iterator.next(); Iterator<Cell> cellIterator = nextRow.cellIterator(); Medecin med = new Medecin(); Specialite s = new Specialite(); Admin ad = new Admin(); while (cellIterator.hasNext()) { Cell nextCell = cellIterator.next(); int columnIndex = nextCell.getColumnIndex(); switch (columnIndex) { case 0: ad.setId_admin(((Integer) getCellValue(nextCell))); med.setAdmin(serviceAdmin.findAdminById(ad.getId_admin())); break; case 1: s.setId_specialite((((Integer) getCellValue(nextCell)).intValue())); med.setSpecialite(serviceSpecialite.findSpecialiteById(s.getId_specialite())); break; case 2: med.setAdresse((String) getCellValue(nextCell)); break; case 3: med.setDate_naissance((String) getCellValue(nextCell)); break; case 4: med.setLogin((String) getCellValue(nextCell)); break; case 5: med.setNom((String) getCellValue(nextCell)); break; case 6: med.setNumero_telephone((String) getCellValue(nextCell)); break; case 7: med.setPassword((String) getCellValue(nextCell)); break; case 8: med.setPrenom((String) getCellValue(nextCell)); break; } } listMed.add(med); } file.close(); } catch (IOException e) { e.printStackTrace(); } return listMed; }
From source file:ExcelReadFile.ExcelReadSecretaire.java
public List<Secretaire> readBooksFromExcelFile(String excelFilePath) throws IOException { List<Secretaire> listMed = new ArrayList<>(); FileInputStream file = new FileInputStream(new File(excelFilePath)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = new XSSFWorkbook(file); //Get first/desired sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(0); Sheet firstSheet = workbook.getSheetAt(0); Iterator<Row> iterator = firstSheet.iterator(); while (iterator.hasNext()) { Row nextRow = iterator.next();/*w ww.j a v a 2 s . c o m*/ Iterator<Cell> cellIterator = nextRow.cellIterator(); Medecin s = new Medecin(); Secretaire med = new Secretaire(); Admin ad = new Admin(); while (cellIterator.hasNext()) { Cell nextCell = cellIterator.next(); int columnIndex = nextCell.getColumnIndex(); switch (columnIndex) { case 0: ad.setId_admin((((Integer) getCellValue(nextCell)).intValue())); Admin a = serviceAdmin.findAdminById(ad.getId_admin()); med.setAdmin(a); break; case 1: s.setId_utilisateur((((Integer) getCellValue(nextCell)).intValue())); Medecin sa = serviceMedecin.findMedecinById(s.getId_utilisateur()); med.setMedecin(sa); break; case 2: med.setAdresse((String) getCellValue(nextCell)); break; case 3: med.setDate_naissance((String) getCellValue(nextCell)); break; case 4: med.setLogin((String) getCellValue(nextCell)); break; case 5: med.setNom((String) getCellValue(nextCell)); break; case 6: med.setNumero_telephone((String) getCellValue(nextCell)); break; case 7: med.setPassword((String) getCellValue(nextCell)); break; case 8: med.setPrenom((String) getCellValue(nextCell)); break; } } listMed.add(med); } file.close(); return listMed; }
From source file:FileHelper.ExcelHelper.java
public DataSheet ReadTestCaseFileFromSheet(String fileName, String sheetName, MyDataHash myDataHash, String rawData) {// ww w .j a va 2 s.c o m try { File excel = new File(fileName); FileInputStream fis = new FileInputStream(excel); XSSFWorkbook book = new XSSFWorkbook(fis); XSSFSheet sheet = book.getSheet(sheetName); Iterator<Row> itr = sheet.iterator(); DataSheet dataSheet = new DataSheet(); ArrayList<RowDataFromFile> datas = new ArrayList<RowDataFromFile>(); ArrayList<DataHash> dataHash = new ArrayList<>(); int colmnDataStart = 0, colmnDataStop = 0, numReal = 0; ArrayList<NameDynamic> nameDynamic = new ArrayList<NameDynamic>(); ArrayList<DataInput> listDataInput = new ArrayList<>(); ArrayList<DataInputLevel2> dataInputLevel2 = new ArrayList<>(); while (itr.hasNext()) { RowDataFromFile dataRow = new RowDataFromFile(); JsonObject jObjReq = new JsonObject(); String caller = ""; Row row = itr.next(); Iterator<Cell> cellIterator = row.cellIterator(); Cell cell = cellIterator.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: { String str = cell.getStringCellValue(); if (str.equals("STT")) { while (cellIterator.hasNext()) { Cell cell1 = cellIterator.next(); switch (cell1.getCellType()) { case Cell.CELL_TYPE_STRING: { // System.out.println(cell1.getStringCellValue()); if (cell1.getStringCellValue().equals("Data Request")) { colmnDataStart = cell1.getColumnIndex(); } if (cell1.getStringCellValue().equals("Threads")) { colmnDataStop = cell1.getColumnIndex() - 1; } if (cell1.getStringCellValue().equals("Result Real")) { // System.out.println("Colmn Reail: " + cell1.getColumnIndex()); numReal = cell1.getColumnIndex(); } break; } case Cell.CELL_TYPE_NUMERIC: { System.out.println(cell1.getNumericCellValue()); break; } } } Row row1 = sheet.getRow(1); Row row2 = sheet.getRow(2); Row row3 = sheet.getRow(3); Row row4 = sheet.getRow(4); Cell cellColmn; Cell cellColmn2; int numColmn = colmnDataStart; while (numColmn <= colmnDataStop) { cellColmn = row1.getCell(numColmn); String temp = GetValueStringFromCell(cellColmn); cellColmn2 = row2.getCell(numColmn); NameDynamic nameDy = CutStrGetNameDynamic(GetValueStringFromCell(cellColmn2)); if (nameDy.getIsDyn().equals("1")) { // Check Data is change when run Thread nameDynamic.add(nameDy); } // Add to list save data api listDataInput.add(new DataInput(temp, nameDy.getName())); DataHash dataHt = myDataHash.CheckNameDataIsHash(sheetName, nameDy.getName()); if (dataHt != null) { dataHt.setNumColumn(numColmn); dataHash.add(dataHt); } if (temp.equals("Object")) { // Exist object group datas name ArrayList<DataInput> listDataIputLevel2 = new ArrayList<>(); cellColmn = row3.getCell(numColmn); cellColmn2 = row4.getCell(numColmn); String tempT = GetValueStringFromCell(cellColmn); if (!tempT.equals("")) { while (!GetValueStringFromCell(cellColmn).equals("")) { nameDy = CutStrGetNameDynamic(GetValueStringFromCell(cellColmn2)); if (nameDy.getIsDyn().equals("1")) { // Check Data is change when run Thread nameDynamic.add(nameDy); } dataHt = myDataHash.CheckNameDataIsHash(sheetName, nameDy.getName()); if (dataHt != null) { dataHt.setNumColumn(numColmn); dataHash.add(dataHt); } listDataIputLevel2.add( new DataInput(GetValueStringFromCell(cellColmn), nameDy.getName())); numColmn++; cellColmn = row3.getCell(numColmn); cellColmn2 = row4.getCell(numColmn); } numColmn--; dataInputLevel2.add(new DataInputLevel2(listDataIputLevel2)); } else { dataInputLevel2.add(new DataInputLevel2(listDataIputLevel2)); } } numColmn++; } Gson gson = new Gson(); System.out.println(gson.toJson(listDataInput)); System.out.println(gson.toJson(dataHash)); } break; } case Cell.CELL_TYPE_NUMERIC: { // System.out.println(cell.getNumericCellValue()); if (cell.getNumericCellValue() > 0) { dataRow.setId(row.getRowNum()); String isSecutiry = "no"; int arrIndex = 0; int arrIndexReq = 0; // Object con int arrIndexRow = 0; while (cellIterator.hasNext()) { Cell cell1 = cellIterator.next(); if ((cell1.getColumnIndex() >= colmnDataStart) && (cell1.getColumnIndex() < colmnDataStop)) { if (listDataInput.get(arrIndex).getType().equals("Object")) { JsonObject jObj = new JsonObject(); int i = 0; int size = dataInputLevel2.get(arrIndexReq).getListDataIputLevel2().size(); while (i < size) { if (dataInputLevel2.get(arrIndexReq).getListDataIputLevel2().get(i) .getType().equals("String")) { String value = GetValueStringFromCell(cell1); if (!dataHash.isEmpty()) { for (DataHash dataH : dataHash) { if (dataH.getNumColumn() == cell1.getColumnIndex()) { value = EncryptHelper.EncryptData(value, dataH.getAlgorithm(), dataH.getKey(), dataH.getIv()); } } } jObj.addProperty(dataInputLevel2.get(arrIndexReq) .getListDataIputLevel2().get(i).getName(), value); } else if (dataInputLevel2.get(arrIndexReq).getListDataIputLevel2().get(i) .getType().equals("Integer")) { int value = GetValueIntegerFromCell(cell1); jObj.addProperty(dataInputLevel2.get(arrIndexReq) .getListDataIputLevel2().get(i).getName(), value); } else if (dataInputLevel2.get(arrIndexReq).getListDataIputLevel2().get(i) .getType().equals("Object")) { String value = GetValueStringFromCell(cell1); Gson gson = new Gson(); JsonObject obj = gson.fromJson(value, JsonObject.class); jObj.add(dataInputLevel2.get(arrIndexReq).getListDataIputLevel2().get(i) .getName(), obj); } i++; if (i < size) { cell1 = cellIterator.next(); } } arrIndexReq++; jObjReq.add(listDataInput.get(arrIndex).getName(), jObj); } else if (listDataInput.get(arrIndex).getType().equals("String")) { String value = GetValueStringFromCell(cell1); if (!dataHash.isEmpty()) { for (DataHash dataH : dataHash) { if (dataH.getNumColumn() == cell1.getColumnIndex()) { value = EncryptHelper.EncryptData(value, dataH.getAlgorithm(), dataH.getKey(), dataH.getIv()); } } } jObjReq.addProperty(listDataInput.get(arrIndex).getName(), value); } else if (listDataInput.get(arrIndex).getType().equals("Integer")) { int value = GetValueIntegerFromCell(cell1); jObjReq.addProperty(listDataInput.get(arrIndex).getName(), value); } arrIndex++; } else if (cell1.getColumnIndex() == colmnDataStop) { isSecutiry = GetValueStringFromCell(cell1); dataRow.setNameAlgorithm(isSecutiry); } else if (cell1.getColumnIndex() > colmnDataStop) { if (arrIndexRow == 0) { dataRow.setThread(GetValueIntegerFromCell(cell1)); } else if (arrIndexRow == 1) { dataRow.setResultExpect(GetValueStringFromCell(cell1)); } arrIndexRow++; } } // System.out.println("data: " + jObj.toString()); // System.out.println("data Req: " + jObjReq.toString()); String[] arrR = rawData.split(","); String rawDataNew = ""; char a = '"'; for (String str : arrR) { if (str.charAt(0) == a) { String value = str.substring(1, str.length() - 1); rawDataNew += value; } else { JsonElement je = jObjReq.get(str); if (je.isJsonObject()) { String value = je.toString(); rawDataNew += value; } else { String value = je.getAsString(); rawDataNew += value; } } } String[] arr = isSecutiry.split("-"); if (arr[0].equals("chksum")) { String chksum = CheckSumInquireCard.createCheckSum(isSecutiry, rawDataNew); // System.out.println("chksum: " + chksum); jObjReq.addProperty(listDataInput.get(arrIndex).getName(), chksum); } else if (arr[0].equals("signature")) { String signature = RSASHA1Signature.getSignature(isSecutiry, rawDataNew); // System.out.println("signature: " + signature); jObjReq.addProperty(listDataInput.get(arrIndex).getName(), signature); } // System.out.println("data Request: " + jObjReq.toString()); dataRow.setData(jObjReq); dataRow.setNumReal(numReal); Gson gson = new Gson(); System.out.println("data row: " + gson.toJson(dataRow)); datas.add(dataRow); } break; } } } dataSheet.setDatas(datas); dataSheet.setNameDynamic(nameDynamic); dataSheet.setListDataInput(listDataInput); dataSheet.setDataInputLevel2(dataInputLevel2); Gson gson = new Gson(); // System.out.println("save data: " + gson.toJson(datas)); fis.close(); return dataSheet; } catch (Throwable t) { System.out.println("Throwsable: " + t.getMessage()); return new DataSheet(); } }
From source file:fr.paris.lutece.plugins.appointment.service.ClosingDayService.java
License:Open Source License
/** * Import the closing dates of a given file * /*from w w w. j av a 2 s.c om*/ * @param item * the file in input * @return the list of the closing dates in the file * @throws IOException * if error during reading file */ public static List<LocalDate> getImportClosingDays(FileItem item) throws IOException { HashSet<LocalDate> listDays = new HashSet<LocalDate>(); FileInputStream fis = null; Workbook workbook = null; String strExtension = FilenameUtils.getExtension(item.getName()); if (StringUtils.equals(MARK_EXCEL_EXTENSION_XLSX, strExtension)) { try { fis = (FileInputStream) item.getInputStream(); // Using XSSF for xlsx format, for xls use HSSF workbook = new XSSFWorkbook(fis); int numberOfSheets = workbook.getNumberOfSheets(); // looping over each workbook sheet for (int i = 0; i < numberOfSheets; i++) { Sheet sheet = workbook.getSheetAt(i); Iterator<Row> rowIterator = sheet.iterator(); // iterating over each row while (rowIterator.hasNext()) { Row row = (Row) rowIterator.next(); if (row.getRowNum() > 1) { Iterator<Cell> cellIterator = row.cellIterator(); // Iterating over each cell (column wise) in a // particular row. while (cellIterator.hasNext()) { Cell cell = (Cell) cellIterator.next(); // The Cell Containing String will is name. if (cell.getColumnIndex() == 3) { String strdate = StringUtils.EMPTY; if (cell.getCellType() == 0) { Instant instant = cell.getDateCellValue().toInstant(); LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate(); strdate = localDate.format(Utilities.getFormatter()); } if (StringUtils.isNotEmpty(strdate) && strdate.matches(MARK_FORMAT_DATE_REGEX)) { LocalDate date = LocalDate.parse(strdate, Utilities.getFormatter()); listDays.add(date); } } } } } } } finally { if (fis != null) { fis.close(); } if (workbook != null) { workbook.close(); } } } return new ArrayList<LocalDate>(listDays); }