private static ContentType newCorePropertiesPart() { try { return new ContentType(ContentTypes.CORE_PROPERTIES_PART); } catch (InvalidFormatException e) { // Should never happen throw new OpenXML4JRuntimeException( "Package.init() : this exception should never happen, " + "if you read this message please send a mail to the developers team. : " + e.getMessage(), e ); } }
/** * Add an unmarshaller. * * @param contentType * The content type to bind to the specified unmarshaller. * @param unmarshaller * The unmarshaller to register with the specified content type. */ public void addUnmarshaller(String contentType, PartUnmarshaller unmarshaller) { try { partUnmarshallers.put(new ContentType(contentType), unmarshaller); } catch (InvalidFormatException e) { logger.log(POILogger.WARN, "The specified content type is not valid: '" + e.getMessage() + "'. The unmarshaller will not be added !"); } }
/** * Add a marshaller. * * @param contentType * The content type to bind to the specified marshaller. * @param marshaller * The marshaller to register with the specified content type. */ public void addMarshaller(String contentType, PartMarshaller marshaller) { try { partMarshallers.put(new ContentType(contentType), marshaller); } catch (InvalidFormatException e) { logger.log(POILogger.WARN, "The specified content type is not valid: '" + e.getMessage() + "'. The marshaller will not be added !"); } }
throw new InvalidOperationException(e.getMessage()); throw new InvalidOperationException(e.getMessage());
public FileDataValidator() { // maybe you need some code in here, maybe not } public void build(String[] lineData){ this.lineData = lineData; removeLeadingAndTrailingQuotes(); try { validateName(); validateAge(); validateTown(); } catch(InvalidFormatException e) { throw new com.myco.myapp.errors.InvalidDataException(e.getMessage()); } }
public FileDataValidator(String[] lineData){ this.lineData = lineData; removeLeadingAndTrailingQuotes(); try { validateName(); validateAge(); validateTown(); } catch(InvalidFormatException e) { throw new com.myco.myapp.errors.InvalidDataException(e.getMessage()); } }
+ partName.getName() + "'. Some parts may remain in the package. - " + e.getMessage()); return;
public FileDataValidator() { // maybe you need some code in here, maybe not } public void build(Person person, String[] lineData){ this.lineData = lineData; removeLeadingAndTrailingQuotes(); setNameFromData(person); setAgeFromData(person); setTownFromData(person); } public boolean validate(Person person) { try { validateName(person); validateAge(person); validateTown(person); return true; } catch(InvalidFormatException e) { throw new com.myco.myapp.errors.InvalidDataException(e.getMessage()); } }
/** * 导入Excel数据流,并封装成对象 * * @param inputStream * @param sheetClass * @return List<Object> */ public static List<Object> importExcel(InputStream inputStream, Class<?> sheetClass) { try { Workbook workbook = WorkbookFactory.create(inputStream); List<Object> dataList = importExcel(workbook, sheetClass); return dataList; } catch (IOException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } catch (InvalidFormatException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
/** * Add a marshaller. * * @param contentType * The content type to bind to the specified marshaller. * @param marshaller * The marshaller to register with the specified content type. */ public void addMarshaller(String contentType, PartMarshaller marshaller) { try { partMarshallers.put(new ContentType(contentType), marshaller); } catch (InvalidFormatException e) { logger.log(POILogger.WARN, "The specified content type is not valid: '" + e.getMessage() + "'. The marshaller will not be added !"); } }
private static ContentType newCorePropertiesPart() { try { return new ContentType(ContentTypes.CORE_PROPERTIES_PART); } catch (InvalidFormatException e) { // Should never happen throw new OpenXML4JRuntimeException( "Package.init() : this exception should never happen, " + "if you read this message please send a mail to the developers team. : " + e.getMessage(), e ); } }
/** * 导入Excel文件,并封装成对象 * * @param excelFile * @param sheetClass * @return List<Object> */ public static List<Object> importExcel(File excelFile, Class<?> sheetClass) { try { Workbook workbook = WorkbookFactory.create(excelFile); List<Object> dataList = importExcel(workbook, sheetClass); return dataList; } catch (IOException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } catch (InvalidFormatException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
/** * Add a marshaller. * * @param contentType * The content type to bind to the specified marshaller. * @param marshaller * The marshaller to register with the specified content type. */ public void addMarshaller(String contentType, PartMarshaller marshaller) { try { partMarshallers.put(new ContentType(contentType), marshaller); } catch (InvalidFormatException e) { logger.log(POILogger.WARN, "The specified content type is not valid: '" + e.getMessage() + "'. The marshaller will not be added !"); } }
/** * Add an unmarshaller. * * @param contentType * The content type to bind to the specified unmarshaller. * @param unmarshaller * The unmarshaller to register with the specified content type. */ public void addUnmarshaller(String contentType, PartUnmarshaller unmarshaller) { try { partUnmarshallers.put(new ContentType(contentType), unmarshaller); } catch (InvalidFormatException e) { logger.log(POILogger.WARN, "The specified content type is not valid: '" + e.getMessage() + "'. The unmarshaller will not be added !"); } }
/** * Add an unmarshaller. * * @param contentType * The content type to bind to the specified unmarshaller. * @param unmarshaller * The unmarshaller to register with the specified content type. */ public void addUnmarshaller(String contentType, PartUnmarshaller unmarshaller) { try { partUnmarshallers.put(new ContentType(contentType), unmarshaller); } catch (InvalidFormatException e) { logger.log(POILogger.WARN, "The specified content type is not valid: '" + e.getMessage() + "'. The unmarshaller will not be added !"); } }
private void evaluateFormula(Workbook workbook, Row row, int cellIndex) { Cell cell = row.getCell(cellIndex); try { final FormulaEvaluator evaluator = new WorkbookAction<FormulaEvaluator>(workbook) { @Override protected FormulaEvaluator doWithHSSFWorkbook(HSSFWorkbook workbook) { return new HSSFFormulaEvaluator(workbook); } @Override protected FormulaEvaluator doWithXSSFWorkbook(XSSFWorkbook workbook) { return new XSSFFormulaEvaluator(workbook); } }.execute(); if (cell != null) { evaluator.evaluateFormulaCell(cell); } else { LOGGER.warn("Cannot aggregate rowIndex={} cellIndex={} this cell does not exists"); } } catch (InvalidFormatException e) { LOGGER.error("Invalid format exception: cannot handle rowIndex={} cellIndex={} exception={}", row.getRowNum(), cellIndex, e.getMessage()); } }
public static Workbook getWorkbook(String url, Integer[] sheetNums, boolean needAll) { InputStream is = null; List<Integer> sheetList = Arrays.asList(sheetNums); try { is = POICacheManager.getFile(url); Workbook wb = WorkbookFactory.create(is); // 删除其他的sheet if (!needAll) { for (int i = wb.getNumberOfSheets() - 1; i >= 0; i--) { if (!sheetList.contains(i)) { wb.removeSheetAt(i); } } } return wb; } catch (InvalidFormatException e) { LOGGER.error(e.getMessage(), e); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } finally { try { is.close(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } return null; }
public static Workbook getWorkbook(String url, Integer[] sheetNums, boolean needAll) { InputStream is = null; List<Integer> sheetList = Arrays.asList(sheetNums); try { is = POICacheManager.getFile(url); Workbook wb = WorkbookFactory.create(is); // 删除其他的sheet if (!needAll) { for (int i = wb.getNumberOfSheets() - 1; i >= 0; i--) { if (!sheetList.contains(i)) { wb.removeSheetAt(i); } } } return wb; } catch (InvalidFormatException e) { LOGGER.error(e.getMessage(), e); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } finally { try { is.close(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } return null; }
public static Workbook getWorkbook(String url, Integer[] sheetNums, boolean needAll) { InputStream is = null; List<Integer> sheetList = Arrays.asList(sheetNums); try { is = POICacheManager.getFile(url); Workbook wb = WorkbookFactory.create(is); // 删除其他的sheet if (!needAll) { for (int i = wb.getNumberOfSheets() - 1; i >= 0; i--) { if (!sheetList.contains(i)) { wb.removeSheetAt(i); } } } return wb; } catch (InvalidFormatException e) { LOGGER.error(e.getMessage(), e); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } finally { try { is.close(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } return null; }
/** * Initialize the package instance. */ private void init() { this.partMarshallers = new Hashtable<ContentType, PartMarshaller>(5); this.partUnmarshallers = new Hashtable<ContentType, PartUnmarshaller>(2); try { // Add 'default' unmarshaller this.partUnmarshallers.put(new ContentType( ContentTypes.CORE_PROPERTIES_PART), new PackagePropertiesUnmarshaller()); // Add default marshaller this.defaultPartMarshaller = new DefaultMarshaller(); // TODO Delocalize specialized marshallers this.partMarshallers.put(new ContentType( ContentTypes.CORE_PROPERTIES_PART), new ZipPackagePropertiesMarshaller()); } catch (InvalidFormatException e) { // Should never happen throw new OpenXML4JRuntimeException( "Package.init() : this exception should never happen, " + "if you read this message please send a mail to the developers team. : " + e.getMessage() ); } }