List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook close
@Override public void close() throws IOException
From source file:data.services.ColorService.java
public void updateFromXml(File fl) { try {// www.j a v a 2 s.c om 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));*/ 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"; } } Color cl = colorDao.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)) { colorDao.update(cl); } } } workbook.close(); } catch (Exception e) { addError(StringAdapter.getStackTraceException(e)); } fi.close(); } catch (Exception e) { addError(" xml"); addError(e.getMessage()); } }
From source file:data.services.FeatureService.java
public void updateFromXml(File fl) { try {//www . j a v a 2s.co m FileInputStream fi = new FileInputStream(fl); int rownumber = 1; HSSFWorkbook workbook = new HSSFWorkbook(fi); try { HSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> it = sheet.iterator(); it.next(); while (it.hasNext()) { rownumber++; Row row = it.next(); Cell idc = row.getCell(0); Long id = null; if (idc != null) { id = StringAdapter.toLong(StringAdapter.HSSFSellValue(row.getCell(0))); } if (id != null) { Cell uidc = row.getCell(5); 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(6); Double val = (double) 0; if (valc != null) { String valstr = StringAdapter.HSSFSellValue(valc); val = StringAdapter.toDouble(valstr); } Cell percc = row.getCell(7); 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(8); 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(9); 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(10); 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(11); String k = "0"; if (kc != null) { k = StringAdapter.HSSFSellValue(kc); if (k.contains(".")) { int point = k.indexOf("."); k = k.substring(0, point); } if (k.equals("")) { k = "0"; } } Feature cl = featureDao.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, " " + rownumber + "; ")) { featureDao.update(cl); } } } } } catch (NumberFormatException e) { addError(" " + rownumber + "; " + StringAdapter.getStackTraceException(e)); } workbook.close(); fi.close(); } catch (IOException e) { addError(" xml"); addError(e.getMessage()); } }
From source file:data.services.FreeOptionService.java
public void updateFromXml(File fl) { try {//from w ww . j a v a 2 s . c o m FileInputStream fi = new FileInputStream(fl); int i = 1; String listName = "? ."; int s = 39191091; List<FreeOption> foForSave = new ArrayList(); List<FreeOption> foForUpd = new ArrayList(); try { HSSFWorkbook workbook = new HSSFWorkbook(fi); int sheetNumber = workbook.getNumberOfSheets(); while (i < sheetNumber) { HSSFSheet sheet = workbook.getSheetAt(i); i++; listName = sheet.getSheetName(); Iterator<Row> it = sheet.iterator(); Car car = new Car(); s = 0; while (it.hasNext()) { Row row = it.next(); s++; Cell idCell = row.getCell(0); if (idCell.getCellType() == Cell.CELL_TYPE_STRING) { String nameCell = idCell.getStringCellValue().trim(); if (nameCell.equals("CAR_ID")) { row = it.next(); s++; Cell carIdCell = row.getCell(0); String carIdstr = StringAdapter.HSSFSellValue(carIdCell); if (carIdstr.contains(".")) { int point = carIdstr.indexOf("."); carIdstr = carIdstr.substring(0, point); } Long carId = StringAdapter.toLong(carIdstr); car = carDao.find(carId); //throw new Exception(" carIdstr="+carIdstr+"; carId="+carId+"; "); } else if (nameCell.equals("OPTION_ID")) { while (it.hasNext()) { row = it.next(); s++; Cell optIdCell = row.getCell(0); if (optIdCell != null) { if (optIdCell.getCellType() == Cell.CELL_TYPE_STRING) { String optIdstr = optIdCell.getStringCellValue().trim(); if (optIdstr.equals("CAR_ID")) { /*it.remove(); break;*/ row = it.next(); s++; Cell carIdCell = row.getCell(0); String carIdstr = StringAdapter.HSSFSellValue(carIdCell); if (carIdstr.contains(".")) { int point = carIdstr.indexOf("."); carIdstr = carIdstr.substring(0, point); } Long carId = StringAdapter.toLong(carIdstr); car = carDao.find(carId); it.next(); s++; } else { String oIdstr = StringAdapter.HSSFSellValue(optIdCell); if (oIdstr.contains(".")) { int point = oIdstr.indexOf("."); oIdstr = oIdstr.substring(0, point); } Long optId = Long.valueOf(oIdstr); FreeOption fored = freeOptionDao.find(optId); if (fored != null) { FreeOption supfo = getOptFromRow(row); fored.setAudial(supfo.getAudial()); fored.setDescription(supfo.getDescription()); fored.setKinestetic(supfo.getKinestetic()); fored.setParamValue(supfo.getParamValue()); fored.setPercentValue(supfo.getPercentValue()); fored.setPrice(supfo.getPrice()); fored.setRadical(supfo.getRadical()); fored.setTitle(supfo.getTitle()); fored.setType(supfo.getType()); fored.setUid(supfo.getUid()); fored.setVisual(supfo.getVisual()); //throw new Exception("4!"); if (validate(fored)) { //freeOptionDao.update(fored); foForUpd.add(fored); } } else { FreeOption fo = getOptFromRow(row); if (car != null) { fo.setCar(car); if (validate(fo)) { foForSave.add(fo); } } //addError(": ? , ."); } } } else if (optIdCell.getCellType() == Cell.CELL_TYPE_NUMERIC) { String oIdstr = StringAdapter.HSSFSellValue(optIdCell); if (oIdstr.contains(".")) { int point = oIdstr.indexOf("."); oIdstr = oIdstr.substring(0, point); } Long optId = Long.valueOf(oIdstr); //Long optId = StringAdapter.toLong(StringAdapter.getString(optIdCell.getNumericCellValue())); FreeOption fored = freeOptionDao.find(optId); if (fored != null) { FreeOption supfo = getOptFromRow(row); fored.setAudial(supfo.getAudial()); fored.setDescription(supfo.getDescription()); fored.setKinestetic(supfo.getKinestetic()); fored.setParamValue(supfo.getParamValue()); fored.setPercentValue(supfo.getPercentValue()); fored.setPrice(supfo.getPrice()); fored.setRadical(supfo.getRadical()); fored.setTitle(supfo.getTitle()); fored.setType(supfo.getType()); fored.setUid(supfo.getUid()); fored.setVisual(supfo.getVisual()); //throw new Exception("3!"); if (validate(fored)) { //freeOptionDao.update(fored); foForUpd.add(fored); } } else { FreeOption fo = getOptFromRow(row); if (car != null) { fo.setCar(car); if (validate(fo)) { foForSave.add(fo); } } } } else if (optIdCell.getCellType() == Cell.CELL_TYPE_BLANK) { if (car != null) { FreeOption fo = getOptFromRow(row); fo.setCar(car); //throw new Exception("2!"); if (validate(fo)) { foForSave.add(fo); } } } } else { if (car != null) { FreeOption fo = getOptFromRow(row); fo.setCar(car); //throw new Exception("1! rad="+fo.getRadical()+"; a="+fo.getAudial()+"; v="+fo.getVisual()+"; perc="+fo.getPercentValue()+"; val="+fo.getParamValue()+"; price="+fo.getPrice()+"; "); if (validate(fo)) { foForSave.add(fo); } } } } } } } } workbook.close(); } catch (Exception e) { addError(": ?:" + i + ", " + listName + ", ?:" + s + ", " + StringAdapter.getStackTraceException(e)); } fi.close(); for (FreeOption fo : foForSave) { freeOptionDao.save(fo); } for (FreeOption fo : foForUpd) { freeOptionDao.update(fo); } } catch (Exception e) { addError(" xml"); addError(e.getMessage()); } }
From source file:data.services.PropertyNameService.java
public void updateFromXml(File fl) throws Exception { try {//from w ww .j a v a2 s.c om FileInputStream fi = new FileInputStream(fl); int i = 0; int m = 0; 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(); Long cpid = StringAdapter.toLong(StringAdapter.HSSFSellValue(row.getCell(0))); Cell pnValc = row.getCell(3); String pnVal = ""; if (pnValc != null) { pnVal = StringAdapter.HSSFSellValue(pnValc).trim(); } Cell radc = row.getCell(4); String rad = ""; if (radc != null) { rad = StringAdapter.HSSFSellValue(radc); if (rad.contains(".")) { int point = rad.indexOf("."); rad = rad.substring(0, point); } if (rad.trim().equals("0")) { rad = ""; } else { rad = rad.replace(" ", ""); } } 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 valc = row.getCell(6); Double val = (double) 0; if (valc != null) { String valstr = StringAdapter.HSSFSellValue(valc).replace(",", ".").trim(); val = StringAdapter.toDouble(valstr); } Cell audc = row.getCell(7); Long a = (long) 0; if (audc != null) { String supstr = StringAdapter.HSSFSellValue(audc); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } a = Long.valueOf(supstr); } Cell visc = row.getCell(8); Long v = (long) 0; if (visc != null) { String supstr = StringAdapter.HSSFSellValue(visc); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } v = Long.valueOf(supstr); } Cell kinc = row.getCell(9); Long k = (long) 0; if (kinc != null) { String supstr = StringAdapter.HSSFSellValue(kinc); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } k = Long.valueOf(supstr); } /*Cell aCell = row.getCell(7); Long a=(long)0; if(aCell!=null){ if(aCell.getCellType()==Cell.CELL_TYPE_NUMERIC){ a=StringAdapter.toLong(StringAdapter.getString(aCell.getNumericCellValue())); }else if(aCell.getCellType()==Cell.CELL_TYPE_STRING){ a=StringAdapter.toLong(aCell.getStringCellValue().trim()); } } Cell vCell = row.getCell(8); Long v=(long)0; if(vCell!=null){ if(vCell.getCellType()==Cell.CELL_TYPE_NUMERIC){ v=StringAdapter.toLong(StringAdapter.getString(vCell.getNumericCellValue())); }else if(vCell.getCellType()==Cell.CELL_TYPE_STRING){ v=StringAdapter.toLong(vCell.getStringCellValue().trim()); } } Cell kCell = row.getCell(9); Long k=(long)0; if(kCell!=null){ if(kCell.getCellType()==Cell.CELL_TYPE_NUMERIC){ k=StringAdapter.toLong(StringAdapter.getString(kCell.getNumericCellValue())); }else if(kCell.getCellType()==Cell.CELL_TYPE_STRING){ k=StringAdapter.toLong(kCell.getStringCellValue().trim()); } }*/ CarProperty cp = carPropertyDao.find(cpid); PropertyName suppn = new PropertyName(); suppn.setPropertyNameValue(pnVal); suppn.setCarProperty(cp); List<PropertyName> pnlist = propertyNameDao.findByPropertyAndPnValue(suppn); if (!pnlist.isEmpty()) { for (PropertyName pn : pnlist) { if (!(pn.getPercentValue().equals(perc) && pn.getParamValue().equals(val) && pn.getRadical().equals(rad) && pn.getAudial().equals(a) && pn.getVisual().equals(v) && pn.getKinestet().equals(k))) { pn.setPercentValue(perc); pn.setParamValue(val); pn.setRadical(rad); pn.setVisual(v); pn.setAudial(a); pn.setKinestet(k); if (validate(pn)) { propertyNameDao.update(pn); } i++; } 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.SceneService.java
public void updateFromXml(File fl, Long sceneId) throws Exception { try {/*from w w w. j a v a 2s . c o m*/ Scene scene = sceneDao.find(sceneId); if (scene != null) { FileInputStream fi = new FileInputStream(fl); int i = 0; int m = 0; try { List<ValueRange> newVrList = new ArrayList(); 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 aminCell = row.getCell(2); Long amin = (long) 0; if (aminCell != null) { String supstr = StringAdapter.HSSFSellValue(aminCell); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } if (!supstr.equals("")) { amin = StringAdapter.toLong(supstr); } } Cell minCell = row.getCell(3); Long min = (long) 0; if (minCell != null) { String supstr = StringAdapter.HSSFSellValue(minCell); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } if (!supstr.equals("")) { min = StringAdapter.toLong(supstr); } } Cell maxCell = row.getCell(4); Long max = (long) 0; if (maxCell != null) { String supstr = StringAdapter.HSSFSellValue(maxCell); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } if (!supstr.equals("")) { max = StringAdapter.toLong(supstr); } } Cell amaxCell = row.getCell(5); Long amax = (long) 0; if (amaxCell != null) { String supstr = StringAdapter.HSSFSellValue(amaxCell); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } if (!supstr.equals("")) { amax = StringAdapter.toLong(supstr); } } ValueRange vr = new ValueRange(); vr.setUid(uid); vr.setAmin(amin); vr.setValueMin(min); vr.setValueMax(max); vr.setAmax(amax); vr.setScene(scene); newVrList.add(vr); } List<ValueRange> oldVrList = scene.getValueRanges(); for (ValueRange vr : oldVrList) { valueRangeService.delete(vr.getId()); } for (ValueRange vr : newVrList) { valueRangeService.create(vr); } workbook.close(); } 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.SequenceService.java
public void updateFromXml(File fl, Long seqId) throws Exception { try {/* w w w. j a va2s . c o m*/ Sequence seq = sequenceDao.find(seqId); if (seq != null) { FileInputStream fi = new FileInputStream(fl); int i = 0; int m = 1; try { List<SequenceValueRange> newSVrList = new ArrayList(); HSSFWorkbook workbook = new HSSFWorkbook(fi); HSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> it = sheet.iterator(); it.next(); while (it.hasNext()) { m++; Row row = it.next(); Cell uidc = row.getCell(0); String uid = ""; if (uidc != null) { uid = StringAdapter.HSSFSellValue(uidc).replace(" ", "").trim(); if (uid.contains(".")) { int point = uid.indexOf("."); uid = uid.substring(0, point); } } Cell aminCell = row.getCell(1); Long amin = null; if (aminCell != null) { String supstr = StringAdapter.HSSFSellValue(aminCell); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } if (!supstr.equals("")) { amin = StringAdapter.toLong(supstr); } } Cell minCell = row.getCell(2); Long min = null; if (minCell != null) { String supstr = StringAdapter.HSSFSellValue(minCell); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } if (!supstr.equals("")) { min = StringAdapter.toLong(supstr); } } Cell maxCell = row.getCell(3); Long max = null; if (maxCell != null) { String supstr = StringAdapter.HSSFSellValue(maxCell); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } if (!supstr.equals("")) { max = StringAdapter.toLong(supstr); } } Cell amaxCell = row.getCell(4); Long amax = null; if (amaxCell != null) { String supstr = StringAdapter.HSSFSellValue(amaxCell); if (supstr.contains(".")) { int point = supstr.indexOf("."); supstr = supstr.substring(0, point); } if (!supstr.equals("")) { amax = StringAdapter.toLong(supstr); } } BaseParam bp = baseParamService.getBaseParam(uid); if (bp != null) { SequenceValueRange vr = new SequenceValueRange(); vr.setUid(uid); vr.setName(bp.getName()); vr.setAmin(amin); vr.setValueMin(min); vr.setValueMax(max); vr.setAmax(amax); vr.setSequence(seq); if (validate(vr, "??? , ? " + m + "; ")) { newSVrList.add(vr); } } } List<SequenceValueRange> oldSVrList = seq.getSequenceValueRanges(); for (SequenceValueRange vr : oldSVrList) { sequenceValueRangeService.delete(vr.getId()); } for (SequenceValueRange vr : newSVrList) { sequenceValueRangeService.create(vr); } workbook.close(); } catch (Exception e) { //addError(StringAdapter.getStackTraceException(e) + "str:"+i+"; "); throw new Exception(StringAdapter.getStackTraceException(e) + "str: " + m + "; "); } fi.close(); } } catch (Exception e) { //addError(" xml"); //addError(e.getMessage()); throw new Exception(StringAdapter.getStackTraceException(e)); } }
From source file:de.alpharogroup.export.excel.poi.ExportExcelExtensions.java
License:Open Source License
/** * Exportiert die bergebene excel-Datei in eine Liste mit zweidimensionalen Arrays fr jeweils * ein sheet in der excel-Datei.// w w w . j ava 2 s .co m * * @param excelSheet * Die excel-Datei. * @return Gibt eine Liste mit zweidimensionalen Arrays fr jeweils ein sheet in der excel-Datei * zurck. * @throws IOException * Fals ein Fehler beim Lesen aufgetreten ist. * @throws FileNotFoundException * Fals die excel-Datei nicht gefunden wurde. */ public static List<String[][]> exportWorkbook(final File excelSheet) throws IOException, FileNotFoundException { final POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(excelSheet)); final HSSFWorkbook wb = new HSSFWorkbook(fs); final int numberOfSheets = wb.getNumberOfSheets(); final List<String[][]> sheetList = new ArrayList<>(); for (int sheetNumber = 0; sheetNumber < numberOfSheets; sheetNumber++) { HSSFSheet sheet = null; sheet = wb.getSheetAt(sheetNumber); final int rows = sheet.getLastRowNum(); final int columns = sheet.getRow(0).getLastCellNum(); String[][] excelSheetInTDArray = null; excelSheetInTDArray = new String[rows + 1][columns]; for (int i = 0; i <= rows; i++) { final HSSFRow row = sheet.getRow(i); if (null != row) { for (int j = 0; j < columns; j++) { final HSSFCell cell = row.getCell(j); if (null == cell) { excelSheetInTDArray[i][j] = ""; } else { final int cellType = cell.getCellType(); if (cellType == Cell.CELL_TYPE_BLANK) { excelSheetInTDArray[i][j] = ""; } else if (cellType == Cell.CELL_TYPE_BOOLEAN) { excelSheetInTDArray[i][j] = Boolean.toString(cell.getBooleanCellValue()); } else if (cellType == Cell.CELL_TYPE_ERROR) { excelSheetInTDArray[i][j] = ""; } else if (cellType == Cell.CELL_TYPE_FORMULA) { excelSheetInTDArray[i][j] = cell.getCellFormula(); } else if (cellType == Cell.CELL_TYPE_NUMERIC) { excelSheetInTDArray[i][j] = Double.toString(cell.getNumericCellValue()); } else if (cellType == Cell.CELL_TYPE_STRING) { excelSheetInTDArray[i][j] = cell.getRichStringCellValue().getString(); } } } } } sheetList.add(excelSheetInTDArray); } wb.close(); return sheetList; }
From source file:de.alpharogroup.export.excel.poi.ExportExcelExtensions.java
License:Open Source License
/** * Exportiert die bergebene excel-Datei in eine geschachtelte Liste mit Listen von sheets und * Listen von den Zeilen der sheets von der excel-Datei. * * @param excelSheet/* w ww . ja v a 2s .c o m*/ * Die excel-Datei. * @return Gibt eine Liste mit Listen von den sheets in der excel-Datei zurck. Die Listen mit * den sheets beinhalten weitere Listen mit String die jeweils eine Zeile * reprsentieren. * @throws IOException * Fals ein Fehler beim Lesen aufgetreten ist. * @throws FileNotFoundException * Fals die excel-Datei nicht gefunden wurde. */ public static List<List<List<String>>> exportWorkbookAsStringList(final File excelSheet) throws IOException, FileNotFoundException { final POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(excelSheet)); final HSSFWorkbook wb = new HSSFWorkbook(fs); final int numberOfSheets = wb.getNumberOfSheets(); final List<List<List<String>>> sl = new ArrayList<>(); for (int sheetNumber = 0; sheetNumber < numberOfSheets; sheetNumber++) { HSSFSheet sheet = null; sheet = wb.getSheetAt(sheetNumber); final int rows = sheet.getLastRowNum(); final int columns = sheet.getRow(0).getLastCellNum(); final List<List<String>> excelSheetList = new ArrayList<>(); for (int i = 0; i <= rows; i++) { final HSSFRow row = sheet.getRow(i); if (null != row) { final List<String> reihe = new ArrayList<>(); for (int j = 0; j < columns; j++) { final HSSFCell cell = row.getCell(j); if (null == cell) { reihe.add(""); } else { final int cellType = cell.getCellType(); if (cellType == Cell.CELL_TYPE_BLANK) { reihe.add(""); } else if (cellType == Cell.CELL_TYPE_BOOLEAN) { reihe.add(Boolean.toString(cell.getBooleanCellValue())); } else if (cellType == Cell.CELL_TYPE_ERROR) { reihe.add(""); } else if (cellType == Cell.CELL_TYPE_FORMULA) { reihe.add(cell.getCellFormula()); } else if (cellType == Cell.CELL_TYPE_NUMERIC) { reihe.add(Double.toString(cell.getNumericCellValue())); } else if (cellType == Cell.CELL_TYPE_STRING) { reihe.add(cell.getRichStringCellValue().getString()); } } } excelSheetList.add(reihe); } } sl.add(excelSheetList); } wb.close(); return sl; }
From source file:energy.usef.pbcfeeder.PbcFeeder.java
License:Apache License
/** * This method reads the excel file based on the location given in the config file. The method started when the during * deployment and fills the field stubColInputMap and stubRowInputList; *///from w w w . j av a 2 s.c o m public void readFile(Path pathToExcelSheet) { LOGGER.debug("Looking for excel sheet filename: {}", pathToExcelSheet); try (InputStream pbcInput = new FileInputStream(pathToExcelSheet.toFile())) { HSSFWorkbook pbcWorkbook = new HSSFWorkbook(pbcInput); HSSFSheet pbcDataSheet = pbcWorkbook.getSheet(DATA_SHEET); HSSFSheet pbcCongestionPointLimitsSheet = pbcWorkbook.getSheet(CPLIMITS_SHEET); fillColStubInputMap(pbcDataSheet); fillCongestionPointLimitsMaps(pbcCongestionPointLimitsSheet); fillStubRowInputList(pbcDataSheet); pbcWorkbook.close(); LOGGER.debug("Created step data based on excel sheet."); } catch (IOException e) { LOGGER.error("Caught exception while parsing the PBC feeder data sheet.", e); } }
From source file:hjow.libreference.proxy.PHWorkbook.java
License:Apache License
public PHWorkbook(String sheetName, FileInputStream stream) throws IOException { // TODO : ?? HSSFWorkbook workbook = null; try {// w w w . ja va2 s. com PSheet newSheet = new PSheet(); workbook = new HSSFWorkbook(stream); Sheet sheet = workbook.getSheetAt(0); for (Row r : sheet) { HgRow newRow = new PRow(); for (Cell c : r) { PCell newCell = new PCell(); if (((Cell) c).getCellType() == Column.TYPE_BLANK) { newCell.setCellValue(""); newCell.setType(Column.TYPE_BLANK); } else if (((Cell) c).getCellType() == Column.TYPE_BOOLEAN) { newCell.setCellValue(((Cell) c).getBooleanCellValue()); newCell.setType(Column.TYPE_BOOLEAN); } else if (((Cell) c).getCellType() == Column.TYPE_DATE) { newCell.setCellValue(((Cell) c).getDateCellValue()); newCell.setType(Column.TYPE_DATE); } else if (((Cell) c).getCellType() == Column.TYPE_ERROR) { newCell.setCellValue(""); newCell.setType(Column.TYPE_ERROR); } else if (((Cell) c).getCellType() == Column.TYPE_FLOAT) { newCell.setCellValue(((Cell) c).getNumericCellValue()); newCell.setType(Column.TYPE_FLOAT); } else if (((Cell) c).getCellType() == Column.TYPE_NUMERIC) { newCell.setCellValue(((Cell) c).getNumericCellValue()); newCell.setType(Column.TYPE_NUMERIC); } else if (((Cell) c).getCellType() == Column.TYPE_FORMULA) { newCell.setCellValue(((Cell) c).getCellFormula()); newCell.setType(Column.TYPE_FORMULA); } else if (((Cell) c).getCellType() == Column.TYPE_INTEGER) { newCell.setCellValue((int) ((Cell) c).getNumericCellValue()); newCell.setType(Column.TYPE_INTEGER); } else { newCell.setCellValue(((Cell) c).getStringCellValue()); newCell.setType(Column.TYPE_STRING); } newRow.add(newCell); } newSheet.add(newRow); } newSheet.setName(sheetName); sheets.add(newSheet); } catch (IOException e) { throw e; } finally { try { workbook.close(); } catch (Exception e) { } } }