List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook getSheetAt
@Override public HSSFSheet getSheetAt(int index)
From source file:controller.ExternalIOController.java
public static void gravarResultadoTeste(QueenSolver solver) throws IOException { File f = new File("ResultadoExperimento.xls"); HSSFWorkbook workbook = null; HSSFSheet sheet = null;//from w ww .j a v a2 s .com FileOutputStream fileOut = null; HSSFRow row = null; if (f.isFile() && f.canRead()) { workbook = new HSSFWorkbook(new FileInputStream(f)); sheet = workbook.getSheetAt(0); row = sheet.createRow(sheet.getLastRowNum() + 1); row.createCell(0).setCellValue(sheet.getLastRowNum()); row.createCell(1).setCellValue(solver.getN()); row.createCell(2).setCellValue(solver.getIteracoes()); row.createCell(3).setCellValue(solver.getUltimoTempo()); fileOut = new FileOutputStream(f); } else { workbook = new HSSFWorkbook(); sheet = workbook.createSheet("TestSheet"); HSSFRow rowhead = sheet.createRow(0); rowhead.createCell(0).setCellValue("Numero"); rowhead.createCell(1).setCellValue("N"); rowhead.createCell(2).setCellValue("Iteraes"); rowhead.createCell(3).setCellValue("Tempo de Servio (MS)"); row = sheet.createRow(1); row.createCell(0).setCellValue(sheet.getLastRowNum()); row.createCell(1).setCellValue(solver.getN()); row.createCell(2).setCellValue(solver.getIteracoes()); row.createCell(3).setCellValue(solver.getUltimoTempo()); fileOut = new FileOutputStream(new File("ResultadoExperimento.xls")); } workbook.write(fileOut); fileOut.close(); }
From source file:controller.ExternalIOController.java
o() throws IOException{ File f = new File("ResultadoExperimento.xls"); HSSFWorkbook workbook = null; HSSFSheet sheet = null; /* ww w .ja va 2 s . c om*/ FileOutputStream fileOut = null; HSSFRow row = null; if(f.isFile() && f.canRead()){ workbook = new HSSFWorkbook(new FileInputStream(f)); sheet = workbook.getSheetAt(0); row = sheet.getRow(0); row.createCell(4).setCellValue("Nmeros Gerados por Distribuio"); for (int i = 0; i < DistributionController.getNumerosGerados().size(); i++) { row = sheet.getRow(i + 1); if(row == null){ row = sheet.createRow(sheet.getLastRowNum() + 1); } row.createCell(4).setCellValue(DistributionController.getNumerosGerados().get(i)); } fileOut = new FileOutputStream(f); }else{ throw new IOException(); } workbook.write(fileOut); fileOut.close(); }
From source file:Controller.importarController.java
/** * funo para ler um arquivo em Excel/*from w ww . j av a 2 s. c om*/ * * @param fileName * @param myInput * @return */ @SuppressWarnings("unchecked") public List ReadFile(String fileName, FileInputStream myInput) { List cellVectorHolder = new ArrayList(); try { //FileInputStream myInput = new FileInputStream(fileName); POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput); HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem); HSSFSheet mySheet = myWorkBook.getSheetAt(0); Iterator rowIter = mySheet.rowIterator(); while (rowIter.hasNext()) { HSSFRow myRow = (HSSFRow) rowIter.next(); Iterator cellIter = myRow.cellIterator(); List cellStoreVector = new ArrayList(); while (cellIter.hasNext()) { HSSFCell myCell = (HSSFCell) cellIter.next(); cellStoreVector.add(myCell); } cellVectorHolder.add(cellStoreVector); } } catch (Exception e) { } return cellVectorHolder; }
From source file:converttooem.ConvertToOemFrame.java
private void convertButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_convertButtonActionPerformed progressBar.setValue(0);//from w w w . j a v a2s .co 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:Creator.TaskManagerPanel.java
/** * Reads a file and returns a list of strings which contain all the variable * names/*from w ww . jav a 2 s.c o m*/ * * @param filename */ public void readXFile(String filename) { try { POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename)); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row; HSSFCell cell; int rows; // No of rows rows = sheet.getPhysicalNumberOfRows(); int cols = 0; // No of columns int tmp = 0; int idCol = -1, idName = -1; // This trick ensures that we get the data properly even if it doesn't start from first few rows for (int i = 0; i < 1; i++) { row = sheet.getRow(i); if (row != null) { tmp = sheet.getRow(i).getPhysicalNumberOfCells(); if (tmp > cols) { cols = tmp; } } if (!sheet.getRow(i).getCell(0).toString().equals("io_id")) { for (int c = 1; c < cols; c++) { if (sheet.getRow(i).getCell(c).equals("io_id")) { idCol = c; break; } } } else { idCol = 0; } if (!sheet.getRow(i).getCell(1).toString().equals("io_name")) { for (int c = 0; c < cols; c++) { if (sheet.getRow(i).getCell(c).equals("io_name")) { idName = c; break; } } } else { idName = 1; } if (!sheet.getRow(i).getCell(2).toString().equals("io_station_id")) { for (int c = 0; c < cols; c++) { if (sheet.getRow(i).getCell(c).equals("io_station_id")) { stationID = (int) sheet.getRow(1).getCell(c).getNumericCellValue(); break; } } } else { stationID = (int) sheet.getRow(1).getCell(2).getNumericCellValue(); } } if (idName == -1 || idCol == -1) { System.out.println("Could not locate io_name or io_id in excel header"); return; } if (stationID == -1) { System.out.println("Couldnt locate station id"); return; } importedIOVariables = new TreeMap<>(); int io_id; String io_name; for (int r = 1; r < rows; r++) { row = sheet.getRow(r); if (row != null) { cell = row.getCell(idCol); if (cell != null) { io_id = (int) cell.getNumericCellValue(); cell = row.getCell(idName); if (cell != null) { io_name = cell.toString().replace("\"", ""); // Read both name and id importedIOVariables.put(io_name, io_id); } } } } fs.close(); mf.loadImportedIos(importedIOVariables, 2, stationID); } catch (Exception e) { System.out.println("Error reading excel file " + e.getMessage()); } }
From source file:Creator.WidgetPanel.java
/** * Reads a file and returns a list of strings which contain all the variable * names/*from www . ja v a 2 s . c om*/ * * @param filename */ public void readXFile(String filename) { try { POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename)); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row; HSSFCell cell; int rows; // No of rows rows = sheet.getPhysicalNumberOfRows(); int cols = 0; // No of columns int tmp = 0; int idCol = -1, idName = -1; // This trick ensures that we get the data properly even if it doesn't start from first few rows for (int i = 0; i < 1; i++) { row = sheet.getRow(i); if (row != null) { tmp = sheet.getRow(i).getPhysicalNumberOfCells(); if (tmp > cols) { cols = tmp; } } if (!sheet.getRow(i).getCell(0).toString().equals("io_id")) { for (int c = 1; c < cols; c++) { if (sheet.getRow(i).getCell(c).equals("io_id")) { idCol = c; break; } } } else { idCol = 0; } if (!sheet.getRow(i).getCell(1).toString().equals("io_name")) { for (int c = 1; c < cols; c++) { if (sheet.getRow(i).getCell(c).equals("io_name")) { idName = c; break; } } } else { idName = 1; } if (!sheet.getRow(i).getCell(2).toString().equals("io_station_id")) { for (int c = 0; c < cols; c++) { if (sheet.getRow(i).getCell(c).equals("io_station_id")) { stationID = (int) sheet.getRow(1).getCell(c).getNumericCellValue(); break; } } } else { stationID = (int) sheet.getRow(1).getCell(2).getNumericCellValue(); } } if (idName == -1 || idCol == -1) { System.out.println("Could not locate io_name or io_id in excel header"); return; } if (stationID == -1) { System.out.println("Couldnt locate station id"); return; } importedIOVariables = new TreeMap<>(); int io_id; String io_name; for (int r = 1; r < rows; r++) { row = sheet.getRow(r); if (row != null) { cell = row.getCell(idCol); if (cell != null) { io_id = (int) cell.getNumericCellValue(); cell = row.getCell(idName); if (cell != null) { io_name = cell.toString().replace("\"", ""); // Read both name and id importedIOVariables.put(io_name, io_id); } } } } fs.close(); mf.loadImportedIos(importedIOVariables, 1, stationID); } catch (Exception e) { System.out.println("Error reading excel file " + e.getMessage()); } }
From source file:data.services.BaseParamService.java
public void updateFromXml(File fl) { try {// ww w .j av a 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(); 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 w w w . ja va 2 s .co 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 {/*from w w w .j a va 2 s . c om*/ 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 w w w .j a v 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(); 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)); } }