List of usage examples for org.apache.poi.ss.usermodel Sheet getSheetName
String getSheetName();
From source file:com.ibm.db2j.GExcel.java
License:Open Source License
/** * Finds the spreadsheet defined by the name given in parameter and return it if found. * Else return null.//from ww w . ja v a 2s. co m * * @param workbook * @param spreadsheetName * @return the spreadsheet * @throws SQLException */ private Sheet findSpreadsheet(Workbook workbook, String spreadsheetName) throws SQLException { boolean sheetFound = false; Sheet sheetTmp = null; for (int i = 0; i < workbook.getNumberOfSheets() && !sheetFound; ++i) { sheetTmp = workbook.getSheetAt(i); if (sheetTmp.getSheetName().equals(spreadsheetName)) sheetFound = true; } if (sheetFound == false && sheet == null) { throw new SQLException("The file does not contain a spreadsheet named : " + spreadsheetName); } return sheetTmp; }
From source file:com.inspiracode.nowgroup.scspro.xl.source.ExcelFile.java
License:Open Source License
private List<LogMessage> validateFieldNames(Sheet sheet) { List<LogMessage> result = new ArrayList<LogMessage>(); String nombreHoja = sheet.getSheetName(); String errDescription = ""; Row headingRow = sheet.getRow(HEADING_ROW); Properties prop = new Properties(); String propFileName = "excel/column_names.properties"; InputStream is = null;//www.j a v a2s. c o m try { is = getClass().getClassLoader().getResourceAsStream(propFileName); if (is != null) { prop.load(is); for (int i = 1; i <= HEADING_COUNT; i++) { String expected = prop.getProperty(Integer.toString(i)); log.debug("Validando [" + Integer.toString(i) + "] validada como [" + headingRow.getCell(i - 1) + "]"); String current = headingRow.getCell(i - 1) == null || headingRow.getCell(i - 1).getStringCellValue() == null ? "" : headingRow.getCell(i - 1).getStringCellValue(); if (!expected.equals(current)) { int charValue = 64 + i; boolean aValue = false; if (charValue > 90) { charValue -= 25; aValue = true; } String columnName = aValue ? "A" : ""; columnName += Character.toString((char) charValue); errDescription = "La columna [" + nombreHoja + "]!" + columnName + " tiene el ttulo [" + current + "], " + " se esperaba: [" + expected + "]"; log.info(errDescription); result.add(new LogMessage("Validacin de encabezados", errDescription)); } else { log.debug("columna [" + expected + "] validada"); } } } else { errDescription = "Imposible abrir configuracin de campos de excel (column_names.properties)"; log.info(errDescription); result.add(new LogMessage("Validacin de encabezados", errDescription)); } } catch (Exception e) { errDescription = "Error al validar campos en la hoja [" + nombreHoja + "]: [" + e.getMessage() + "]"; log.error(errDescription, e); result.add(new LogMessage("Validacin de encabezados", errDescription)); } finally { if (is != null) { try { is.close(); } catch (Exception e) { log.error(e.getMessage(), e); } } } return result; }
From source file:com.jbuncle.exceltomysql.SheetPathFilter.java
License:Open Source License
@Override public boolean accept(Sheet sheet) { final String sheetName = Utils.cleanUp(sheet.getSheetName()); for (String str : this.acceptedPaths) { if (str.startsWith("*.") || str.equals(sheetName) || str.startsWith(sheetName + ".")) { return true; }// w w w .j a v a 2 s . c o m } return false; }
From source file:com.jbuncle.exceltomysql.SheetPathFilter.java
License:Open Source License
@Override public boolean accept(Sheet sheet, String column) { final String sheetName = Utils.cleanUp(sheet.getSheetName()); //Column name path {sheet}.{column} or {sheet}.* for (String str : acceptedPaths) { if (str.equals("*.*")) { return true; }/* w ww.j av a 2 s. c o m*/ if (str.startsWith(sheetName)) { final String columnPath = str.substring(sheetName.length() + 1); if (columnPath.equals("*") || columnPath.equals(column)) { return true; } } } return false; }
From source file:com.jkoolcloud.tnt4j.streams.inputs.AbstractExcelStream.java
License:Apache License
/** * Returns {@link Workbook} next {@link Sheet} which name matches configuration defined (property * '{@value com.jkoolcloud.tnt4j.streams.configure.MsOfficeStreamProperties#PROP_SHEETS}') sheets name filtering * mask. If no more sheets matching name filter mask is available in workbook, then {@code null} is returned. * * @param countSkips// ww w . j av a 2s . c om * flag indicating whether unmatched sheets has to be added to stream skipped activities count * * @return next workbook sheet matching name filter mask, or {@code null} if no more sheets matching name mask * available in this workbook. */ protected Sheet getNextNameMatchingSheet(boolean countSkips) { while (true) { if (sheetIterator == null || !sheetIterator.hasNext()) { logger().log(OpLevel.DEBUG, StreamsResources.getString(MsOfficeStreamConstants.RESOURCE_BUNDLE_NAME, "AbstractExcelStream.no.more.sheets")); return null; } Sheet sheet = sheetIterator.next(); boolean match = sheetNameMatcher == null || sheetNameMatcher.matcher(sheet.getSheetName()).matches(); if (!match) { if (countSkips) { skipFilteredActivities(); } continue; } activityPosition = workbook.getSheetIndex(sheet); logger().log(OpLevel.DEBUG, StreamsResources.getString(MsOfficeStreamConstants.RESOURCE_BUNDLE_NAME, "AbstractExcelStream.sheet.to.process"), sheet.getSheetName()); return sheet; } }
From source file:com.lnganalysis.fileupload.util.ReadExcelFile.java
public Map<String, List> readExcelData(Workbook wb, List<Tab> tabsList) { logger.info("Class - ReadExcelFile - readExcelData()"); int sheetCount = wb.getNumberOfSheets(); Map<String, List> populatedData = new HashMap<String, List>(); for (int i = 0; i < sheetCount; i++) { Sheet sheet = wb.getSheetAt(i); if (sheet.getSheetName().toLowerCase().equalsIgnoreCase(LngData.EXPLORATION.toString())) { Tab tab = new Tab(); List<Exploration> explorationList = populateExplorationData(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab);//w ww .j a v a2s . co m populatedData.put(sheet.getSheetName().toLowerCase(), explorationList); } else if (sheet.getSheetName().toLowerCase().equalsIgnoreCase(LngData.REFINERIES.toString())) { Tab tab = new Tab(); List<Refinery> refineryList = populateRefineryData(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName().toLowerCase(), refineryList); } else if (sheet.getSheetName().toLowerCase().equalsIgnoreCase(LngData.STORAGE.toString())) { Tab tab = new Tab(); List<Storage> storageList = populateStorageData(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName().toLowerCase(), storageList); } else if (sheet.getSheetName().toLowerCase().equalsIgnoreCase(LngData.LNG.toString())) { Tab tab = new Tab(); List<Lng> lngList = populateLngData(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName().toLowerCase(), lngList); } else if (sheet.getSheetName().toLowerCase().equalsIgnoreCase(LngData.PIPELINES.toString())) { Tab tab = new Tab(); List<PipeLine> pipeLineList = populatePipeLinesData(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName().toLowerCase(), pipeLineList); } else if (sheet.getSheetName().toLowerCase().equalsIgnoreCase(LngData.CRUDEOIL.toString())) { Tab tab = new Tab(); List<CrudeOil> crudeOilList = populateCrudeOilData(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName().toLowerCase(), crudeOilList); } else if (sheet.getSheetName().toLowerCase().equalsIgnoreCase(LngData.NATURALGAS.toString())) { Tab tab = new Tab(); List<NaturalGas> naturalGasList = populateNaturalGasData(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName().toLowerCase(), naturalGasList); } else if (sheet.getSheetName().toLowerCase().equalsIgnoreCase(LngData.SUPPLYDEMAND.toString())) { Tab tab = new Tab(); List<SupplyDemand> supplyDemandList = populateSupplyDemandData(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName(), supplyDemandList); } else if (sheet.getSheetName().equalsIgnoreCase(LngData.CONTRACTS.toString())) { Tab tab = new Tab(); List<Contracts> contractsList = populateContractsData(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName(), contractsList); } else if (sheet.getSheetName().equalsIgnoreCase(LngData.PRODUCTION_COMPANY_OILGAS.toString())) { Tab tab = new Tab(); List<CompanyOilGas> companyOilGasList = populateProductionCompanyOilGas(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName(), companyOilGasList); } else if (sheet.getSheetName().equalsIgnoreCase(LngData.SMALLSCALELNG.toString())) { Tab tab = new Tab(); List<SmallScaleLng> smallScaleLngList = populateSmallScaleLng(sheet, tab); if (tab != null && tab.getTotalRecords() > 0) tabsList.add(tab); populatedData.put(sheet.getSheetName(), smallScaleLngList); } } return populatedData; }
From source file:com.lnganalysis.fileupload.util.ReadExcelFile.java
private List<SmallScaleLng> populateSmallScaleLng(Sheet sheet, Tab tab) { logger.info("Class - ReadExcelFile - populateSmallScaleLng()"); int columnNo = 0; List<SmallScaleLng> smallScaleLngList = new ArrayList<SmallScaleLng>(); int rowCount = sheet.getLastRowNum(); int totalRecords = 0; StringBuffer recordsList = new StringBuffer(); Set<String> columnNamesSet = new HashSet<String>(); // DataFormatter df=new DataFormatter(); int linebreak = 1; for (int i = 1; i <= rowCount; i++) { Row row = sheet.getRow(i);//www. j av a 2 s .co m SmallScaleLng smallScaleLng = new SmallScaleLng(); try { columnNo = 0; smallScaleLng.setStatus(null == row.getCell(0) || null == df.formatCellValue(row.getCell(0)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(0))) ? BLANK : df.formatCellValue(row.getCell(0))); columnNo = 1; smallScaleLng.setType(null == row.getCell(1) || null == df.formatCellValue(row.getCell(1)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(1))) ? BLANK : df.formatCellValue(row.getCell(1))); columnNo = 2; smallScaleLng.setCountry(null == row.getCell(2) || null == df.formatCellValue(row.getCell(2)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(2))) ? BLANK : df.formatCellValue(row.getCell(2))); columnNo = 3; smallScaleLng.setRegion(null == row.getCell(3) || null == df.formatCellValue(row.getCell(3)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(3))) ? BLANK : df.formatCellValue(row.getCell(3))); columnNo = 4; smallScaleLng.setLocation(null == row.getCell(4) || null == df.formatCellValue(row.getCell(4)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(4))) ? BLANK : df.formatCellValue(row.getCell(4))); columnNo = 5; smallScaleLng.setTerminalName(null == row.getCell(5) || null == df.formatCellValue(row.getCell(5)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(5))) ? BLANK : df.formatCellValue(row.getCell(5))); columnNo = 6; smallScaleLng.setStartDate(null == row.getCell(6) || null == df.formatCellValue(row.getCell(6)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(6))) ? 0 : Integer.valueOf(df.formatCellValue(row.getCell(6)))); columnNo = 7; smallScaleLng.setCompany(null == row.getCell(7) || null == df.formatCellValue(row.getCell(7)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(7))) ? BLANK : df.formatCellValue(row.getCell(7))); columnNo = 8; smallScaleLng.setTechnologyProviderCompany( null == row.getCell(8) || null == df.formatCellValue(row.getCell(8)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(8))) ? BLANK : df.formatCellValue(row.getCell(8))); columnNo = 9; smallScaleLng.setTechnology(null == row.getCell(9) || null == df.formatCellValue(row.getCell(9)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(9))) ? BLANK : df.formatCellValue(row.getCell(9))); columnNo = 10; smallScaleLng.setLiquefactionCapacity( null == row.getCell(10) || null == df.formatCellValue(row.getCell(10)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(10))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(10)))); columnNo = 11; smallScaleLng.setLiquefactionCapcityUnit( null == row.getCell(11) || null == df.formatCellValue(row.getCell(11)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(11))) ? BLANK : df.formatCellValue(row.getCell(11))); columnNo = 12; smallScaleLng.setRegasificationCapacity( null == row.getCell(12) || null == df.formatCellValue(row.getCell(12)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(12))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(12)))); columnNo = 13; smallScaleLng.setRegasificationCapcityUnit( null == row.getCell(13) || null == df.formatCellValue(row.getCell(13)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(13))) ? BLANK : df.formatCellValue(row.getCell(13))); columnNo = 14; smallScaleLng .setBunkeringCapacity(null == row.getCell(14) || null == df.formatCellValue(row.getCell(14)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(14))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(14)))); columnNo = 15; smallScaleLng.setBunkeringCapacityUnit( null == row.getCell(15) || null == df.formatCellValue(row.getCell(15)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(15))) ? BLANK : df.formatCellValue(row.getCell(15))); columnNo = 16; smallScaleLng.setSource(null == row.getCell(16) || null == df.formatCellValue(row.getCell(16)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(16))) ? BLANK : df.formatCellValue(row.getCell(16))); columnNo = 17; smallScaleLng .setStorageCapacity(null == row.getCell(17) || null == df.formatCellValue(row.getCell(17)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(17))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(17)))); columnNo = 18; smallScaleLng.setEpc(null == row.getCell(18) || null == df.formatCellValue(row.getCell(18)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(18))) ? BLANK : df.formatCellValue(row.getCell(18))); columnNo = 19; smallScaleLng.setCapex(null == row.getCell(19) || null == df.formatCellValue(row.getCell(19)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(19))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(19)))); columnNo = 20; smallScaleLng .setDistributionType(null == row.getCell(20) || null == df.formatCellValue(row.getCell(20)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(20))) ? BLANK : df.formatCellValue(row.getCell(20))); columnNo = 21; smallScaleLng.setOtherDetails(null == row.getCell(21) || null == df.formatCellValue(row.getCell(21)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(21))) ? BLANK : df.formatCellValue(row.getCell(21))); columnNo = 22; smallScaleLng.setSources(null == row.getCell(22) || null == df.formatCellValue(row.getCell(22)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(22))) ? BLANK : df.formatCellValue(row.getCell(22))); columnNo = 23; smallScaleLng .setTerminalOtherName(null == row.getCell(23) || null == df.formatCellValue(row.getCell(23)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(23))) ? BLANK : df.formatCellValue(row.getCell(23))); columnNo = 24; smallScaleLng .setContactOrEmailId(null == row.getCell(24) || null == df.formatCellValue(row.getCell(24)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(24))) ? BLANK : df.formatCellValue(row.getCell(24))); smallScaleLngList.add(smallScaleLng); } catch (Exception e) { logger.info("Class - ReadExcelFile - populateSmallScaleLng():" + e); totalRecords++; String columnName = getHeaderValues(sheet, columnNo); recordsList.append((row.getRowNum() + 1) + COMMA); if (totalRecords == (12 * linebreak)) { recordsList.append(SPACE);// Adding space for rendering in front end; linebreak++; } columnNamesSet.add(columnName); } } if (totalRecords > 0) { createTabData(tab, sheet.getSheetName().toUpperCase(), totalRecords, recordsList, columnNamesSet); logger.info("smallScaleLng reading excel failure"); logger.info("smallScaleLng totalRecords:" + totalRecords + "recordsList:" + recordsList); } return smallScaleLngList; }
From source file:com.lnganalysis.fileupload.util.ReadExcelFile.java
private List<CompanyOilGas> populateProductionCompanyOilGas(Sheet sheet, Tab tab) { logger.info("Class - ReadExcelFile - populateProductionCompanyOilGas()"); int columnNo = 0; List<CompanyOilGas> companyOilGasList = new ArrayList<CompanyOilGas>(); int rowCount = sheet.getLastRowNum(); int totalRecords = 0; StringBuffer recordsList = new StringBuffer(); Set<String> columnNamesSet = new HashSet<String>(); // DataFormatter df=new DataFormatter(); int linebreak = 1; for (int i = 1; i <= rowCount; i++) { Row row = sheet.getRow(i);/* w w w .j a va 2 s.c om*/ CompanyOilGas companyOilGas = new CompanyOilGas(); try { columnNo = 0; companyOilGas.setName(null == row.getCell(0) || null == df.formatCellValue(row.getCell(0)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(0))) ? BLANK : df.formatCellValue(row.getCell(0))); columnNo = 1; companyOilGas.setRegion(null == row.getCell(1) || null == df.formatCellValue(row.getCell(1)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(1))) ? BLANK : df.formatCellValue(row.getCell(1))); columnNo = 2; companyOilGas.setCountry(null == row.getCell(2) || null == df.formatCellValue(row.getCell(2)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(2))) ? BLANK : df.formatCellValue(row.getCell(2))); columnNo = 3; companyOilGas.setType(null == row.getCell(3) || null == df.formatCellValue(row.getCell(3)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(3))) ? BLANK : df.formatCellValue(row.getCell(3))); columnNo = 4; companyOilGas.setYear2005(null == row.getCell(4) || null == df.formatCellValue(row.getCell(4)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(4))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(4)))); columnNo = 5; companyOilGas.setYear2006(null == row.getCell(5) || null == df.formatCellValue(row.getCell(5)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(5))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(5)))); columnNo = 6; companyOilGas.setYear2007(null == row.getCell(6) || null == df.formatCellValue(row.getCell(6)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(6))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(6)))); columnNo = 7; companyOilGas.setYear2008(null == row.getCell(7) || null == df.formatCellValue(row.getCell(7)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(7))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(7)))); columnNo = 8; companyOilGas.setYear2009(null == row.getCell(8) || null == df.formatCellValue(row.getCell(8)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(8))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(8)))); columnNo = 9; companyOilGas.setYear2010(null == row.getCell(9) || null == df.formatCellValue(row.getCell(9)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(9))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(9)))); columnNo = 10; companyOilGas.setYear2011(null == row.getCell(10) || null == df.formatCellValue(row.getCell(10)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(10))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(10)))); columnNo = 11; companyOilGas.setYear2012(null == row.getCell(11) || null == df.formatCellValue(row.getCell(11)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(11))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(11)))); columnNo = 12; companyOilGas.setYear2013(null == row.getCell(12) || null == df.formatCellValue(row.getCell(12)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(12))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(12)))); columnNo = 13; companyOilGas.setYear2014(null == row.getCell(13) || null == df.formatCellValue(row.getCell(13)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(13))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(13)))); columnNo = 14; companyOilGas.setYear2015(null == row.getCell(14) || null == df.formatCellValue(row.getCell(14)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(14))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(14)))); columnNo = 15; companyOilGas.setYear2016(null == row.getCell(15) || null == df.formatCellValue(row.getCell(15)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(15))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(15)))); columnNo = 16; companyOilGas.setYear2017(null == row.getCell(16) || null == df.formatCellValue(row.getCell(16)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(16))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(16)))); columnNo = 17; companyOilGas.setNotes(null == row.getCell(17) || null == df.formatCellValue(row.getCell(17)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(17))) ? BLANK : df.formatCellValue(row.getCell(17))); columnNo = 18; companyOilGas.setSource2005(null == row.getCell(18) || null == df.formatCellValue(row.getCell(18)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(18))) ? BLANK : df.formatCellValue(row.getCell(18))); columnNo = 19; companyOilGas.setSource2006(null == row.getCell(19) || null == df.formatCellValue(row.getCell(19)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(19))) ? BLANK : df.formatCellValue(row.getCell(19))); columnNo = 20; companyOilGas.setSource2007(null == row.getCell(20) || null == df.formatCellValue(row.getCell(20)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(20))) ? BLANK : df.formatCellValue(row.getCell(20))); columnNo = 21; companyOilGas.setSource2008(null == row.getCell(21) || null == df.formatCellValue(row.getCell(21)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(21))) ? BLANK : df.formatCellValue(row.getCell(21))); columnNo = 22; companyOilGas.setSource2009(null == row.getCell(22) || null == df.formatCellValue(row.getCell(22)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(22))) ? BLANK : df.formatCellValue(row.getCell(22))); columnNo = 23; companyOilGas.setSource2010(null == row.getCell(23) || null == df.formatCellValue(row.getCell(23)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(23))) ? BLANK : df.formatCellValue(row.getCell(23))); columnNo = 24; companyOilGas.setSource2011(null == row.getCell(24) || null == df.formatCellValue(row.getCell(24)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(24))) ? BLANK : df.formatCellValue(row.getCell(24))); columnNo = 25; companyOilGas.setSource2012(null == row.getCell(25) || null == df.formatCellValue(row.getCell(25)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(25))) ? BLANK : df.formatCellValue(row.getCell(25))); columnNo = 26; companyOilGas.setSource2013(null == row.getCell(26) || null == df.formatCellValue(row.getCell(26)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(26))) ? BLANK : df.formatCellValue(row.getCell(26))); columnNo = 27; companyOilGas.setSource2014(null == row.getCell(27) || null == df.formatCellValue(row.getCell(27)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(27))) ? BLANK : df.formatCellValue(row.getCell(27))); columnNo = 28; companyOilGas.setSource2015(null == row.getCell(28) || null == df.formatCellValue(row.getCell(28)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(28))) ? BLANK : df.formatCellValue(row.getCell(28))); columnNo = 29; companyOilGas.setSource2016(null == row.getCell(29) || null == df.formatCellValue(row.getCell(29)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(29))) ? BLANK : df.formatCellValue(row.getCell(29))); columnNo = 30; companyOilGas.setSource2017(null == row.getCell(30) || null == df.formatCellValue(row.getCell(30)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(30))) ? BLANK : df.formatCellValue(row.getCell(30))); companyOilGasList.add(companyOilGas); } catch (Exception e) { logger.info("Class - ReadExcelFile - populateProductionCompanyOilGas():" + e); totalRecords++; String columnName = getHeaderValues(sheet, columnNo); recordsList.append((row.getRowNum() + 1) + COMMA); if (totalRecords == (12 * linebreak)) { recordsList.append(SPACE);// Adding space for rendering in front end; linebreak++; } columnNamesSet.add(columnName); } } if (totalRecords > 0) { createTabData(tab, sheet.getSheetName().toUpperCase(), totalRecords, recordsList, columnNamesSet); logger.info("CompanyOilGas totalRecords:" + totalRecords + "recordsList:" + recordsList); } return companyOilGasList; }
From source file:com.lnganalysis.fileupload.util.ReadExcelFile.java
private List<Contracts> populateContractsData(Sheet sheet, Tab tab) { logger.info("Class - ReadExcelFile - populateContractsData()"); int columnNo = 0; List<Contracts> contractsList = new ArrayList<Contracts>(); int rowCount = sheet.getLastRowNum(); int totalRecords = 0; StringBuffer recordsList = new StringBuffer(BLANK); Set<String> columnNamesSet = new HashSet<String>(); // DataFormatter df=new DataFormatter(); int linebreak = 1; for (int i = 1; i <= rowCount; i++) { Row row = sheet.getRow(i);/*from w w w.j ava 2 s . co m*/ Contracts contracts = new Contracts(); try { columnNo = 0; contracts.setContractIndicator(null == row.getCell(0) || null == df.formatCellValue(row.getCell(0)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(0))) ? BLANK : df.formatCellValue(row.getCell(0))); columnNo = 1; contracts.setYear(null == row.getCell(1) || null == df.formatCellValue(row.getCell(1)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(1))) ? 0 : Integer.parseInt(df.formatCellValue(row.getCell(1)))); columnNo = 2; contracts.setExportTerminal(null == row.getCell(2) || null == df.formatCellValue(row.getCell(2)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(2))) ? BLANK : df.formatCellValue(row.getCell(2))); columnNo = 3; contracts.setExportCountry(null == row.getCell(3) || null == df.formatCellValue(row.getCell(3)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(3))) ? BLANK : df.formatCellValue(row.getCell(3))); columnNo = 4; contracts.setExportCompany(null == row.getCell(4) || null == df.formatCellValue(row.getCell(4)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(4))) ? BLANK : df.formatCellValue(row.getCell(4))); columnNo = 5; contracts.setImportTerminal(null == row.getCell(5) || null == df.formatCellValue(row.getCell(5)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(5))) ? BLANK : df.formatCellValue(row.getCell(5))); columnNo = 6; contracts.setImportCountry(null == row.getCell(6) || null == df.formatCellValue(row.getCell(6)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(6))) ? BLANK : df.formatCellValue(row.getCell(6))); columnNo = 7; contracts.setImportCompany(null == row.getCell(7) || null == df.formatCellValue(row.getCell(7)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(7))) ? BLANK : df.formatCellValue(row.getCell(7))); columnNo = 8; contracts.setContractedQuantity(null == row.getCell(8) || null == df.formatCellValue(row.getCell(8)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(8))) ? 0 : Double.valueOf(df.formatCellValue(row.getCell(8)))); columnNo = 9; contracts.setContractAgreementDate( null == row.getCell(9) || null == df.formatCellValue(row.getCell(9)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(9))) ? BLANK : df.formatCellValue(row.getCell(9))); columnNo = 10; contracts .setContractStartFrom(null == row.getCell(10) || null == df.formatCellValue(row.getCell(10)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(10))) ? 0 : Integer.parseInt(df.formatCellValue(row.getCell(10)))); columnNo = 11; contracts.setContractEndsIn(null == row.getCell(11) || null == df.formatCellValue(row.getCell(11)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(11))) ? 0 : Integer.parseInt(df.formatCellValue(row.getCell(11)))); columnNo = 12; contracts.setTypeOfTransportation( null == row.getCell(12) || null == df.formatCellValue(row.getCell(12)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(12))) ? BLANK : df.formatCellValue(row.getCell(12))); columnNo = 13; contracts.setContractAgreementStatus( null == row.getCell(13) || null == df.formatCellValue(row.getCell(13)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(13))) ? BLANK : df.formatCellValue(row.getCell(13))); columnNo = 14; contracts.setContractAdditionalDetails( null == row.getCell(14) || null == df.formatCellValue(row.getCell(14)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(14))) ? BLANK : df.formatCellValue(row.getCell(14))); columnNo = 15; contracts.setSources(null == row.getCell(15) || null == df.formatCellValue(row.getCell(15)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(15))) ? BLANK : df.formatCellValue(row.getCell(15))); contractsList.add(contracts); } catch (Exception e) { logger.info("Class - ReadExcelFile - populateContractsData():" + e); totalRecords++; String columnName = getHeaderValues(sheet, columnNo); recordsList.append((row.getRowNum() + 1) + COMMA); if (totalRecords == (12 * linebreak)) { recordsList.append(SPACE);// Adding space for rendering in front end; linebreak++; } columnNamesSet.add(columnName); } } if (totalRecords > 0) { createTabData(tab, sheet.getSheetName().toUpperCase(), totalRecords, recordsList, columnNamesSet); logger.info("Contracts totalRecords:" + totalRecords + "recordsList:" + recordsList); } logger.info("Total objects set for NaturalGas:" + contractsList.size()); return contractsList; }
From source file:com.lnganalysis.fileupload.util.ReadExcelFile.java
private List<SupplyDemand> populateSupplyDemandData(Sheet sheet, Tab tab) { logger.info("Class - ReadExcelFile - populateSupplyDemandData"); int columnNo = 0; List<SupplyDemand> supplyDemandList = new ArrayList<SupplyDemand>(); int rowCount = sheet.getLastRowNum(); final String hypen = "-"; int totalRecords = 0; StringBuffer recordsList = new StringBuffer(BLANK); Set<String> columnNamesSet = new HashSet<String>(); int linebreak = 1; // DataFormatter df=new DataFormatter(); for (int i = 1; i <= rowCount; i++) { Row row = sheet.getRow(i);//from ww w. j a v a 2 s . com SupplyDemand sd = new SupplyDemand(); try { columnNo = 0; sd.setTradeType(null == row.getCell(0) || null == df.formatCellValue(row.getCell(0)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(0))) ? BLANK : df.formatCellValue(row.getCell(0))); columnNo = 1; sd.setRegion(null == row.getCell(1) || null == df.formatCellValue(row.getCell(1)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(1))) ? BLANK : df.formatCellValue(row.getCell(1))); columnNo = 2; sd.setCountry(null == row.getCell(2) || null == df.formatCellValue(row.getCell(2)) || (BLANK).equalsIgnoreCase(df.formatCellValue(row.getCell(2))) ? BLANK : df.formatCellValue(row.getCell(2))); columnNo = 3; if (null != row.getCell(3) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(3))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(3)))) sd.setYear2000(Float.valueOf(df.formatCellValue(row.getCell(3)))); columnNo = 4; if (null != row.getCell(4) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(4))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(4)))) sd.setYear2001(Float.valueOf(df.formatCellValue(row.getCell(4)))); columnNo = 5; if (null != row.getCell(5) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(5))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(5)))) sd.setYear2002(Float.valueOf(df.formatCellValue(row.getCell(5)))); columnNo = 6; if (null != row.getCell(6) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(6))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(6)))) sd.setYear2003(Float.valueOf(df.formatCellValue(row.getCell(6)))); columnNo = 7; if (null != row.getCell(7) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(7))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(7)))) sd.setYear2004(Float.valueOf(df.formatCellValue(row.getCell(7)))); columnNo = 8; if (null != row.getCell(8) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(8))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(8)))) sd.setYear2005(Float.valueOf(df.formatCellValue(row.getCell(8)))); columnNo = 9; if (null != row.getCell(9) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(9))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(9)))) sd.setYear2006(Float.valueOf(df.formatCellValue(row.getCell(9)))); columnNo = 10; if (null != row.getCell(10) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(10))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(10)))) sd.setYear2007(Float.valueOf(df.formatCellValue(row.getCell(10)))); columnNo = 11; if (null != row.getCell(11) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(11))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(11)))) sd.setYear2008(Float.valueOf(df.formatCellValue(row.getCell(11)))); columnNo = 12; if (null != row.getCell(12) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(12))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(12)))) sd.setYear2009(Float.valueOf(df.formatCellValue(row.getCell(12)))); columnNo = 13; if (null != row.getCell(13) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(13))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(13)))) sd.setYear2010(Float.valueOf(df.formatCellValue(row.getCell(13)))); columnNo = 14; if (null != row.getCell(14) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(14))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(14)))) sd.setYear2011(Float.valueOf(df.formatCellValue(row.getCell(14)))); columnNo = 15; if (null != row.getCell(15) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(15))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(15)))) sd.setYear2012(Float.valueOf(df.formatCellValue(row.getCell(15)))); columnNo = 16; if (null != row.getCell(16) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(16))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(16)))) sd.setYear2013(Float.valueOf(df.formatCellValue(row.getCell(16)))); columnNo = 17; if (null != row.getCell(17) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(17))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(17)))) sd.setYear2014(Float.valueOf(df.formatCellValue(row.getCell(17)))); columnNo = 18; if (null != row.getCell(18) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(18))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(18)))) sd.setYear2015(Float.valueOf(df.formatCellValue(row.getCell(18)))); columnNo = 19; if (null != row.getCell(19) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(19))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(19)))) sd.setYear2016(Float.valueOf(df.formatCellValue(row.getCell(19)))); columnNo = 20; if (null != row.getCell(20) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(20))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(20)))) sd.setYear2017(Float.valueOf(df.formatCellValue(row.getCell(20)))); columnNo = 21; if (null != row.getCell(21) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(21))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(21)))) sd.setYear2018(Float.valueOf(df.formatCellValue(row.getCell(21)))); columnNo = 22; if (null != row.getCell(22) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(22))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(22)))) sd.setYear2019(Float.valueOf(df.formatCellValue(row.getCell(22)))); columnNo = 23; if (null != row.getCell(23) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(23))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(23)))) sd.setYear2020(Float.valueOf(df.formatCellValue(row.getCell(23)))); columnNo = 24; if (null != row.getCell(24) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(24))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(24)))) sd.setYear2021(Float.valueOf(df.formatCellValue(row.getCell(24)))); columnNo = 25; if (null != row.getCell(25) && !hypen.equalsIgnoreCase(df.formatCellValue(row.getCell(25))) && !BLANK.equalsIgnoreCase(df.formatCellValue(row.getCell(25)))) sd.setYear2022(Float.valueOf(df.formatCellValue(row.getCell(25)))); // columnNo=4;sd.setYear2001((null==row.getCell(4) || hypen.equalsIgnoreCase(row.getCell(4).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(4).getNumericCellValue()).floatValue()); // columnNo=5;sd.setYear2002((null==row.getCell(5) || hypen.equalsIgnoreCase(row.getCell(5).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(5).getNumericCellValue()).floatValue()); // columnNo=6;sd.setYear2003((null==row.getCell(6) || hypen.equalsIgnoreCase(row.getCell(6).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(6).getNumericCellValue()).floatValue()); // columnNo=7;sd.setYear2004((null==row.getCell(7) || hypen.equalsIgnoreCase(row.getCell(7).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(7).getNumericCellValue()).floatValue()); // columnNo=8;sd.setYear2005((null==row.getCell(8) || hypen.equalsIgnoreCase(row.getCell(8).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(8).getNumericCellValue()).floatValue()); // columnNo=9;sd.setYear2006((null==row.getCell(9) || hypen.equalsIgnoreCase(row.getCell(9).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(9).getNumericCellValue()).floatValue()); // columnNo=10;sd.setYear2007((null==row.getCell(10) || hypen.equalsIgnoreCase(row.getCell(10).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(10).getNumericCellValue()).floatValue()); // columnNo=11;sd.setYear2008((null==row.getCell(11) || hypen.equalsIgnoreCase(row.getCell(11).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(11).getNumericCellValue()).floatValue()); // columnNo=12;sd.setYear2009((null==row.getCell(12) || hypen.equalsIgnoreCase(row.getCell(12).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(12).getNumericCellValue()).floatValue()); // columnNo=13;sd.setYear2010((null==row.getCell(13) || hypen.equalsIgnoreCase(row.getCell(13).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(13).getNumericCellValue()).floatValue()); // columnNo=14;sd.setYear2011((null==row.getCell(14) || hypen.equalsIgnoreCase(row.getCell(14).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(14).getNumericCellValue()).floatValue()); // columnNo=15;sd.setYear2012((null==row.getCell(15) || hypen.equalsIgnoreCase(row.getCell(15).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(15).getNumericCellValue()).floatValue()); // columnNo=16;sd.setYear2013((null==row.getCell(16) || hypen.equalsIgnoreCase(row.getCell(16).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(16).getNumericCellValue()).floatValue()); // columnNo=17;sd.setYear2014((null==row.getCell(17) || hypen.equalsIgnoreCase(row.getCell(17).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(17).getNumericCellValue()).floatValue()); // columnNo=18;sd.setYear2015((null==row.getCell(18) || hypen.equalsIgnoreCase(row.getCell(18).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(18).getNumericCellValue()).floatValue()); // // columnNo=19;sd.setYear2016((null==row.getCell(19) || hypen.equalsIgnoreCase(row.getCell(19).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(19).getNumericCellValue()).floatValue()); // columnNo=20;sd.setYear2017((null==row.getCell(20) || hypen.equalsIgnoreCase(row.getCell(20).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(20).getNumericCellValue()).floatValue()); // columnNo=21;sd.setYear2018((null==row.getCell(21) || hypen.equalsIgnoreCase(row.getCell(21).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(21).getNumericCellValue()).floatValue()); // columnNo=22;sd.setYear2019((null==row.getCell(22) || hypen.equalsIgnoreCase(row.getCell(22).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(22).getNumericCellValue()).floatValue()); // columnNo=23;sd.setYear2020((null==row.getCell(23) || hypen.equalsIgnoreCase(row.getCell(23).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(23).getNumericCellValue()).floatValue()); // columnNo=24;sd.setYear2021((null==row.getCell(24) || hypen.equalsIgnoreCase(row.getCell(24).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(24).getNumericCellValue()).floatValue()); // columnNo=25;sd.setYear2022((null==row.getCell(25) || hypen.equalsIgnoreCase(row.getCell(25).getStringCellValue()))?0:BigDecimal.valueOf(row.getCell(25).getNumericCellValue()).floatValue()); supplyDemandList.add(sd); } catch (Exception e) { logger.error("Exception in ReadExcelFile - populateSupplyDemandData():" + e); totalRecords++; String columnName = getHeaderValues(sheet, columnNo); if (columnName.contains(".0")) columnName = columnName.substring(0, columnName.length() - 2); recordsList.append((row.getRowNum() + 1) + COMMA); if (totalRecords == (12 * linebreak)) { recordsList.append(SPACE);// Adding space for rendering in front end; linebreak++; } columnNamesSet.add(columnName); } } if (totalRecords > 0) { createTabData(tab, sheet.getSheetName().toUpperCase(), totalRecords, recordsList, columnNamesSet); logger.info("SupplyDemand totalRecords:" + totalRecords + "recordsList:" + recordsList); } logger.info("Total objects set for SupplyDemand:" + supplyDemandList.size()); return supplyDemandList; }