Add Workbook.setCellFormulaValidation to control whether formulas are validated during Cell.setCellFormula or not
This commit is contained in:
parent
f10fa7ac69
commit
dbb6f07f29
@ -2269,6 +2269,27 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
|||||||
return recalc != null && recalc.getEngineId() != 0;
|
return recalc != null && recalc.getEngineId() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a call to {@link HSSFCell#setCellFormula(String)} will validate the formula or not.
|
||||||
|
*
|
||||||
|
* @param value true if the application will validate the formula is correct
|
||||||
|
* @since 3.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCellFormulaValidation(final boolean value) {
|
||||||
|
// currently {@link HSSFCell#setCellFormula(String)} does no validation anyway, ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a call to {@link HSSFCell#setCellFormula(String)} will validate the formula or not.
|
||||||
|
*
|
||||||
|
* @since 3.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean getCellFormulaValidation() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes an external referenced file to another file.
|
* Changes an external referenced file to another file.
|
||||||
* A formula in Excel which references a cell in another file is saved in two parts:
|
* A formula in Excel which references a cell in another file is saved in two parts:
|
||||||
|
@ -686,4 +686,19 @@ public interface Workbook extends Closeable, Iterable<Sheet> {
|
|||||||
* @throws IOException if the object can't be embedded
|
* @throws IOException if the object can't be embedded
|
||||||
*/
|
*/
|
||||||
int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException;
|
int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a call to {@link Cell#setCellFormula(String)} will validate the formula or not.
|
||||||
|
*
|
||||||
|
* @param value true if the application will validate the formula is correct
|
||||||
|
* @since 3.17
|
||||||
|
*/
|
||||||
|
void setCellFormulaValidation(boolean value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a call to {@link Cell#setCellFormula(String)} will validate the formula or not.
|
||||||
|
*
|
||||||
|
* @since 3.17
|
||||||
|
*/
|
||||||
|
boolean getCellFormulaValidation();
|
||||||
}
|
}
|
||||||
|
@ -1363,6 +1363,27 @@ public class SXSSFWorkbook implements Workbook {
|
|||||||
public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException {
|
public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException {
|
||||||
return _wb.addOlePackage(oleData, label, fileName, command);
|
return _wb.addOlePackage(oleData, label, fileName, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a call to {@link SXSSFCell#setCellFormula(String)} will validate the formula or not.
|
||||||
|
*
|
||||||
|
* @param value true if the application will validate the formula is correct
|
||||||
|
* @since 3.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCellFormulaValidation(final boolean value) {
|
||||||
|
// currently {@link SXSSFCell#setCellFormula(String)} does no validation anyway, ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a call to {@link SXSSFCell#setCellFormula(String)} will validate the formula or not.
|
||||||
|
*
|
||||||
|
* @since 3.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean getCellFormulaValidation() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//end of interface implementation
|
//end of interface implementation
|
||||||
}
|
}
|
||||||
|
@ -561,9 +561,11 @@ public final class XSSFCell implements Cell {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
|
if(wb.getCellFormulaValidation()) {
|
||||||
//validate through the FormulaParser
|
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
|
||||||
FormulaParser.parse(formula, fpb, formulaType, wb.getSheetIndex(getSheet()), getRowIndex());
|
//validate through the FormulaParser
|
||||||
|
FormulaParser.parse(formula, fpb, formulaType, wb.getSheetIndex(getSheet()), getRowIndex());
|
||||||
|
}
|
||||||
|
|
||||||
CTCellFormula f = CTCellFormula.Factory.newInstance();
|
CTCellFormula f = CTCellFormula.Factory.newInstance();
|
||||||
f.setStringValue(formula);
|
f.setStringValue(formula);
|
||||||
|
@ -208,6 +208,11 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
|||||||
*/
|
*/
|
||||||
private MissingCellPolicy _missingCellPolicy = MissingCellPolicy.RETURN_NULL_AND_BLANK;
|
private MissingCellPolicy _missingCellPolicy = MissingCellPolicy.RETURN_NULL_AND_BLANK;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a call to {@link XSSFCell#setCellFormula(String)} will validate the formula or not.
|
||||||
|
*/
|
||||||
|
private boolean cellFormulaValidation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array of pictures for this workbook
|
* array of pictures for this workbook
|
||||||
*/
|
*/
|
||||||
@ -2470,4 +2475,25 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
|||||||
|
|
||||||
return oleId;
|
return oleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a call to {@link XSSFCell#setCellFormula(String)} will validate the formula or not.
|
||||||
|
*
|
||||||
|
* @param value true if the application will validate the formula is correct
|
||||||
|
* @since 3.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCellFormulaValidation(final boolean value) {
|
||||||
|
this.cellFormulaValidation = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a call to {@link XSSFCell#setCellFormula(String)} will validate the formula or not.
|
||||||
|
*
|
||||||
|
* @since 3.17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean getCellFormulaValidation() {
|
||||||
|
return this.cellFormulaValidation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user