List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook getSheet
@Override
public XSSFSheet getSheet(String name)
From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java
License:Apache License
/** * [Flow #-6] ? : ? ?(?, ? )? //w w w . j av a2 s .c om */ @Test public void testModifyCellAttribute() throws Exception { try { LOGGER.debug("testModifyCellAttribute start...."); StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testModifyCellAttribute.xlsx"); if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); LOGGER.debug("Delete file....{}", sb.toString()); } Workbook wbTmp = new XSSFWorkbook(); wbTmp.createSheet(); // ? ? excelService.createWorkbook(wbTmp, sb.toString()); // ? XSSFWorkbook wb = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook()); LOGGER.debug("testModifyCellAttribute after loadWorkbook...."); Sheet sheet = wb.createSheet("cell test sheet2"); sheet.setColumnWidth((short) 3, (short) 200); // column Width CellStyle cs = wb.createCellStyle(); XSSFFont font = wb.createFont(); font.setFontHeight(16); font.setBoldweight((short) 3); font.setFontName("fixedsys"); cs.setFont(font); cs.setAlignment(XSSFCellStyle.ALIGN_RIGHT); // cell cs.setWrapText(true); for (int i = 0; i < 100; i++) { Row row = sheet.createRow(i); row.setHeight((short) 300); // row? height for (int j = 0; j < 5; j++) { Cell cell = row.createCell(j); cell.setCellValue(new XSSFRichTextString("row " + i + ", cell " + j)); cell.setCellStyle(cs); } } // ? FileOutputStream out = new FileOutputStream(sb.toString()); wb.write(out); out.close(); ////////////////////////////////////////////////////////////////////////// // ? XSSFWorkbook wbT = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook()); Sheet sheetT = wbT.getSheet("cell test sheet2"); LOGGER.debug("getNumCellStyles : {}", wbT.getNumCellStyles()); XSSFCellStyle cs1 = (XSSFCellStyle) wbT.getCellStyleAt((short) (wbT.getNumCellStyles() - 1)); XSSFFont fontT = cs1.getFont(); LOGGER.debug("font getFontHeight : {}", fontT.getFontHeight()); LOGGER.debug("font getBoldweight : {}", fontT.getBoldweight()); LOGGER.debug("font getFontName : {}", fontT.getFontName()); LOGGER.debug("getAlignment : {}", cs1.getAlignment()); LOGGER.debug("getWrapText : {}", cs1.getWrapText()); for (int i = 0; i < 100; i++) { Row row1 = sheetT.getRow(i); for (int j = 0; j < 5; j++) { Cell cell1 = row1.getCell(j); LOGGER.debug("row {}, cell {} : {}", i, j, cell1.getRichStringCellValue()); assertEquals(320, fontT.getFontHeight()); assertEquals(400, fontT.getBoldweight()); LOGGER.debug("fontT.getBoldweight()? ? 400? ?"); assertEquals(XSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment()); assertTrue(cs1.getWrapText()); } } } catch (Exception e) { LOGGER.error(e.toString()); throw new Exception(e); } finally { LOGGER.debug("testModifyCellAttribute end...."); } }
From source file:egovframework.rte.fdl.excel.impl.EgovExcelServiceImpl.java
License:Apache License
/** * xlsx ?? DB? ?.<br/>//from w ww . j a va 2s. c o m * ? . * * @param queryId * @param fileIn * @param sheetName * @param start (default : 0) * @param commitCnt (default : 0) * @param wb * @return * @throws Exception */ public Integer uploadExcel(String queryId, InputStream fileIn, String sheetName, int start, long commitCnt, XSSFWorkbook wb) throws BaseException, Exception { wb = loadWorkbook(fileIn, wb); Sheet sheet = wb.getSheet(sheetName); return uploadExcel(queryId, sheet, start, commitCnt); }
From source file:eremeykin.pete.loader.xlsxdao.XlsxModelDao.java
private String getTableContent(String table) throws DaoException { FileInputStream excelFile = null; try {//from w w w. ja v a2s . c om excelFile = new FileInputStream(source); XSSFWorkbook wb = new XSSFWorkbook(excelFile); XSSFSheet sheet = wb.getSheet(table); return sheet.getRow(1).getCell(0).getStringCellValue(); } catch (FileNotFoundException ex) { throw new DaoException("Can't find excel file " + source, ex); } catch (IOException ex) { throw new DaoException("Can't open excel file " + source, ex); } finally { try { if (excelFile != null) { excelFile.close(); } } catch (IOException ex) { throw new DaoException("Can't close excel file " + source, ex); } } }
From source file:eremeykin.pete.loader.xlsxdao.XlsxModelDao.java
private String getTableTillEndContent(String table) throws DaoException { FileInputStream excelFile = null; try {// w ww. j av a 2 s. c o m excelFile = new FileInputStream(source); XSSFWorkbook wb = new XSSFWorkbook(excelFile); XSSFSheet sheet = wb.getSheet(table); Integer numRow = sheet.getPhysicalNumberOfRows(); StringBuffer sb = new StringBuffer(); for (int i = 1; i < numRow; i++) { String s = sheet.getRow(i).getCell(0).getStringCellValue(); sb.append(sheet.getRow(i).getCell(0).getStringCellValue()); if (!s.endsWith("\n")) { sb.append("\n"); } } System.out.println(sb.toString()); return sb.toString(); // return sheet.getRow(1).getCell(0).getStringCellValue(); } catch (FileNotFoundException ex) { throw new DaoException("Can't find excel file " + source, ex); } catch (IOException ex) { throw new DaoException("Can't open excel file " + source, ex); } finally { try { if (excelFile != null) { excelFile.close(); } } catch (IOException ex) { throw new DaoException("Can't close excel file " + source, ex); } } }
From source file:eremeykin.pete.loader.xlsxdao.XlsxModelParameterDao.java
@Override protected Map<ParameterEntry, ModelParameter> getORMap() throws DaoException { FileInputStream excelFile = null; try {// www . ja va 2s .c o m excelFile = new FileInputStream(source); XSSFWorkbook wb = new XSSFWorkbook(excelFile); XSSFSheet sheet = wb.getSheet(XlsxConstants.PARAMETERS_SHEET); Map<ParameterEntry, ModelParameter> orMap = new HashMap<>(); XlsxResultSet rs = new XlsxResultSet(sheet); while (rs.next()) { String id = rs.getString(XlsxConstants.ID_COLUMN); String name = rs.getString(XlsxConstants.NAME_COLUMN); String parent = rs.getString(XlsxConstants.PARENT_COLUMN); String scriptArg = rs.getString(XlsxConstants.SCRIPTARG_COLUMN); String value = rs.getString(XlsxConstants.VALUE_COLUMN); String comment = rs.getString(XlsxConstants.COMMENT_COLUMN); String editorType = rs.getString(XlsxConstants.EDITOR_TYPE_COLUMN); String master = rs.getString(XlsxConstants.MASTER_COLUMN); String editorTable = rs.getString(XlsxConstants.EDITOR_TABLE_COLUMN); String editorColumn = rs.getString(XlsxConstants.EDITOR_COLUMN_COLUMN); ParameterEntry pEntry = new ParameterEntry(id, name, parent, scriptArg, value, comment, editorType, master, editorTable, editorColumn); ModelParameter parameter = buildModelParameter(pEntry); orMap.put(pEntry, parameter); } return orMap; } catch (FileNotFoundException ex) { throw new DaoException("Can't find excel file " + source, ex); } catch (IOException ex) { throw new DaoException("Can't open excel file " + source, ex); } finally { try { if (excelFile != null) { excelFile.close(); } } catch (IOException ex) { throw new DaoException("Can't close file " + source, ex); } } }
From source file:eremeykin.pete.loader.xlsxdao.XlsxValueDao.java
@Override public List<Value> getAllSuitable(String table, String column, String key) throws DaoException { InputStream excelFile = null; try {//from w w w . j a v a 2 s. c o m excelFile = new FileInputStream(source); XSSFWorkbook wb = new XSSFWorkbook(excelFile); XSSFSheet sheet = wb.getSheet(table); XlsxResultSet rs = new XlsxResultSet(sheet); List<Value> valuesList = new ArrayList<>(); while (rs.next()) { String k = rs.getString(key);//See sql alials String v = rs.getString(column);//See sql alials Value value = new Value(k, v); valuesList.add(value); } return valuesList; } catch (FileNotFoundException ex) { throw new DaoException("Can't find excel file", ex); } catch (IOException ex) { throw new DaoException("Can't open excel file", ex); } finally { try { if (excelFile != null) { excelFile.close(); } } catch (IOException ex) { throw new DaoException("Can't close excel file", ex); } } }
From source file:eu.riscoss.server.EntityManager.java
License:Apache License
private void readImportFile(RiscossDB db) throws Exception { //Load importing config xml file DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); FileInputStream f = new FileInputStream("resources/importation_config.xml"); Document doc = builder.parse(f); Element element = doc.getDocumentElement(); //Get relationships config info NodeList importNodes = element.getElementsByTagName("relationships"); Element e = (Element) importNodes.item(0); String sheet = e.getElementsByTagName("sheet_name").item(0).getTextContent(); List<Integer> entitiesColumns = new ArrayList<>(); NodeList ent = e.getElementsByTagName("layer"); while (ent != null) { Element el = (Element) ent.item(0); if (el != null) { entitiesColumns.add(Integer.valueOf(el.getAttribute("entity_column")) - 1); ent = el.getElementsByTagName("layer"); } else// w w w . j ava 2 s. co m break; } List<ConfigItem> config = new ArrayList<>(); //Get imported entitites config info NodeList cf = element.getElementsByTagName("entities"); Element impEnt = (Element) cf.item(0); NodeList configNodes = impEnt.getElementsByTagName("imported_entity"); for (int i = 0; i < configNodes.getLength(); ++i) { ConfigItem conf = new ConfigItem(); Element entity = (Element) configNodes.item(i); conf.sheet = entity.getElementsByTagName("sheet_name").item(0).getTextContent(); conf.nameColumn = Integer.parseInt(entity.getElementsByTagName("name_column").item(0).getTextContent()) - 1; List<Pair<String, Pair<Integer, Integer>>> definedIdItem = new ArrayList<>(); List<Pair<String, Integer>> definedValueItem = new ArrayList<>(); NodeList p = entity.getElementsByTagName("custom_information"); Element ee = (Element) p.item(0); NodeList prop = ee.getElementsByTagName("custom_field"); for (int j = 0; j < prop.getLength(); ++j) { Element b = (Element) prop.item(j); if (b.getElementsByTagName("id").item(0) != null) { String id = b.getElementsByTagName("id").item(0).getTextContent(); int column = Integer.parseInt(b.getElementsByTagName("value_column").item(0).getTextContent()) - 1; definedValueItem.add(new Pair<>(id, column)); } else { int column = Integer.parseInt(b.getElementsByTagName("id_column").item(0).getTextContent()) - 1; int val = Integer.parseInt(b.getElementsByTagName("value").item(0).getTextContent()); String prefix = b.getElementsByTagName("prefix").item(0).getTextContent(); definedIdItem.add(new Pair<>(prefix, new Pair<>(column, val))); } } conf.definedIdItem = definedIdItem; conf.definedValueItem = definedValueItem; config.add(conf); } File xlsx = new File("resources/entities_info.xlsx"); FileInputStream fis = new FileInputStream(xlsx); XSSFWorkbook wb = new XSSFWorkbook(fis); XSSFSheet ws = wb.getSheet(sheet); Map<String, Pair<String, String>> list = new HashMap<>(); Map<Integer, List<String>> entities = new HashMap<>(); List<Pair<String, String>> relationships = new ArrayList<>(); boolean read = true; int i = 6; while (read) { //For every valid row in xlsx file XSSFRow row = ws.getRow(i); if (row == null || row.getCell(0).toString().equals("")) read = false; else { //For every custom entity defined in i row for (int j = 0; j < config.size(); ++j) { String parent = row.getCell(config.get(j).nameColumn).toString(); if (!parent.equals("")) { int x = 0; while (x < entitiesColumns.size()) { if (entitiesColumns.get(x) == config.get(j).nameColumn) break; else ++x; } if (x > 0) relationships .add(new Pair<>(row.getCell(entitiesColumns.get(x - 1)).toString(), parent)); if (entities.containsKey(config.get(j).nameColumn)) entities.get(config.get(j).nameColumn).add(parent); else { List<String> n = new ArrayList<>(); n.add(parent); entities.put(config.get(j).nameColumn, n); } String prefix = ""; //For every custom info defined for j entity in i row for (int k = 0; k < config.get(j).definedIdItem.size(); ++k) { prefix = config.get(j).definedIdItem.get(k).getLeft(); if (!row.getCell(config.get(j).definedIdItem.get(k).getRight().getLeft()).toString() .equals("")) { checkNewInfo(parent, prefix + row .getCell(config.get(j).definedIdItem.get(k).getRight().getLeft()) .toString(), config.get(j).definedIdItem.get(k).getRight().getRight().toString(), list, db); } } for (int k = 0; k < config.get(j).definedValueItem.size(); ++k) { if (!row.getCell(config.get(j).definedValueItem.get(k).getRight()).toString() .equals("")) { String value = row.getCell(config.get(j).definedValueItem.get(k).getRight()) .toString(); checkNewInfo(parent, config.get(j).definedValueItem.get(k).getLeft(), value, list, db); } } } } ++i; } } Map<String, String> en = importEntities(entitiesColumns, entities, relationships, db); //Delete old imported data for entities Set<String> all = new HashSet<>(); for (List<String> s : entities.values()) all.addAll(s); for (String target : all) { for (String id : db.listRiskData(target)) { JsonObject o = (JsonObject) new JsonParser().parse(db.readRiskData(target, id)); if (o.get("type").toString().equals("\"imported\"")) { JsonObject delete = new JsonObject(); delete.addProperty("id", id); delete.addProperty("target", target); JsonArray array = new JsonArray(); array.add(delete); db.storeRiskData(delete.toString()); } } } for (String child : list.keySet()) { if (!list.get(child).getLeft().equals("") && !list.get(child).getRight().equals("")) storeRDR(child.split("@")[0], en.get(child.split("@")[0]), list.get(child).getLeft(), list.get(child).getRight(), db); } }
From source file:fenix.util.convert.InvoiceConverter.java
License:Open Source License
/** * .xslx-./*from w w w.j av a 2s . co m*/ * @param file - . * @return - ?? ?. * @throws java.io.FileNotFoundException */ public static List<Entry> extract(File file) throws FileNotFoundException, IOException { List<Entry> list = new ArrayList<>(); InputStream is = new FileInputStream(file); XSSFWorkbook workbook = new XSSFWorkbook(is); Sheet sheet = workbook.getSheet("??"); Iterator<Row> itr = sheet.iterator(); itr.next(); while (itr.hasNext()) { Row row = itr.next(); Entry entry = new Entry(); entry.setName(validateString(row.getCell(1))); Cell cell = row.getCell(2); if (cell != null) { entry.setQuantity(validateInt(cell)); } entry.setPrice(validateDouble(row.getCell(3))); list.add(entry); } return list; }
From source file:FileHelper.ExcelHelper.java
public DataSheet ReadTestCaseFileFromSheet(String fileName, String sheetName, MyDataHash myDataHash, String rawData) {/*w ww . j ava 2s . co 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:FileHelper.ExcelHelper.java
public URLs ReadURLS(String fileName, String sheetName) { try {//from w w w.j av a 2 s . c o m 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(); URLs urls = new URLs(); ArrayList<DataURL> dataUrls = new ArrayList<DataURL>(); Row row = itr.next(); while (itr.hasNext()) { row = itr.next(); DataURL dataUrl = new DataURL(); Cell cell = row.getCell(0); if ((cell != null) && (!GetValueStringFromCell(cell).equals(""))) { dataUrl.setNameSheet(GetValueStringFromCell(cell)); cell = row.getCell(1); dataUrl.setUrl(GetValueStringFromCell(cell)); cell = row.getCell(2); dataUrl.setAcceptType(GetValueStringFromCell(cell)); cell = row.getCell(3); dataUrl.setContentType(GetValueStringFromCell(cell)); cell = row.getCell(4); dataUrl.setRawData(GetValueStringFromCell(cell)); dataUrls.add(dataUrl); } // Gson gson = new Gson(); // System.out.println("url: " + gson.toJson(dataUrl)); } urls.setUrls(dataUrls); return urls; } catch (Throwable t) { System.out.println("Throwsable: " + t.getMessage()); return new URLs(); } }