}
try {
- FileInputStream fis = new FileInputStream(excelFileName);
- try {
- workbook = WorkbookFactory.create(fis);
- } finally {
- fis.close();
+ try (FileInputStream fis = new FileInputStream(excelFileName)) {
+ workbook = WorkbookFactory.create(fis);
}
} catch(Exception e) {
throw new BuildException("Cannot load file " + excelFileName
/**
* Used to add a UDF to the evaluator.
- * @param name
- * @param clazzName
- * @throws ClassNotFoundException
- * @throws InstantiationException
- * @throws IllegalAccessException
+ * @param name The name of the function to add
+ * @param clazzName The class which implements this function
+ * @throws ClassNotFoundException if the class cannot be found
+ * @throws InstantiationException if the class cannot be constructed
+ * @throws IllegalAccessException if the constructor or the class is not accessible
*/
public void addFunction(String name, String clazzName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Class<?> clazzInst = Class.forName(clazzName);
* Updates the internal HashMap of functions with instance and alias passed
* in.
*
- * @param name
- * @param func
+ * @param name the name of the function to replace
+ * @param func the function to use
*/
protected void addFunction(String name, FreeRefFunction func) {
xlsMacroList.put(name, func);
/**
* returns a UDFFinder that contains all of the functions added.
*
- * @return
+ * @return An instance of {@link UDFFinder} which can be used to
+ * lookup functions
*/
protected UDFFinder getFunctions() {
* Returns a formula evaluator that is loaded with the functions that
* have been supplied.
*
- * @param fileName
- * @return
+ * @param fileName Specifies if XSSF or HSSF should be used for
+ * the evaluator
+ * @return A {@link FormulaEvaluator} constructed accordingly
*/
protected FormulaEvaluator getEvaluator(String fileName) {
FormulaEvaluator evaluator;
import java.util.Date;
import java.util.List;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.examples.formula.CalculateMortgageFunction;
import org.apache.poi.ss.excelant.BuildFileTest;
import org.apache.poi.ss.formula.udf.UDFFinder;
public void testLoadNotExistingFile() {
try {
- assertNotNull(new ExcelAntWorkbookUtilTestHelper(
- "notexistingFile" ));
+ new ExcelAntWorkbookUtilTestHelper("notexistingFile");
fail("Should catch exception here");
} catch (BuildException e) {
assertTrue(e.getMessage().contains("notexistingFile"));
}
}
- public void testWorkbookConstructor() throws InvalidFormatException, IOException {
+ public void testWorkbookConstructor() throws IOException {
File workbookFile = new File(mortgageCalculatorFileName);
FileInputStream fis = new FileInputStream(workbookFile);
Workbook workbook = WorkbookFactory.create(fis);
double value = fixture.getCellAsDouble(cell);
- assertNotNull(value);
assertEquals(0.0, value);
}
double value = fixture.getCellAsDouble(cell);
- assertNotNull(value);
assertEquals(DateUtil.getExcelDate(cellValue, false), value);
}