tag r1761165 as 3.15

git-svn-id: https://svn.apache.org/repos/asf/poi/tags/REL_3_15_FINAL@1761166 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David North 2016-09-17 09:33:29 +00:00
commit 453c7e8082
4667 changed files with 1298 additions and 701059 deletions

View File

@ -1092,7 +1092,7 @@ under the License.
</copy>
</target>
<target name="compile-integration" depends="compile-scratchpad, compile-main, compile-ooxml">
<target name="compile-integration" depends="compile-scratchpad, compile-main, compile-ooxml, compile-examples">
<javac target="${jdk.version.class}"
source="${jdk.version.source}"
destdir="${integration.output.test.dir}"

View File

@ -160,8 +160,8 @@ public class SVTableCellRenderer extends JLabel
SVTableUtils.getAWTColor(s.getRightBorderColor(), SVTableUtils.black),
SVTableUtils.getAWTColor(s.getBottomBorderColor(), SVTableUtils.black),
SVTableUtils.getAWTColor(s.getLeftBorderColor(), SVTableUtils.black),
s.getBorderTop(), s.getBorderRight(),
s.getBorderBottom(), s.getBorderLeft(),
s.getBorderTopEnum(), s.getBorderRightEnum(),
s.getBorderBottomEnum(), s.getBorderLeftEnum(),
hasFocus);
setBorder(cellBorder);
isBorderSet=true;

View File

@ -367,23 +367,23 @@ public class ExcelComparator {
String borderName;
switch (borderSide) {
case 't': default:
b1 = style1.getBorderTop() == BorderStyle.THIN;
b2 = style2.getBorderTop() == BorderStyle.THIN;
b1 = style1.getBorderTopEnum() == BorderStyle.THIN;
b2 = style2.getBorderTopEnum() == BorderStyle.THIN;
borderName = "TOP";
break;
case 'b':
b1 = style1.getBorderBottom() == BorderStyle.THIN;
b2 = style2.getBorderBottom() == BorderStyle.THIN;
b1 = style1.getBorderBottomEnum() == BorderStyle.THIN;
b2 = style2.getBorderBottomEnum() == BorderStyle.THIN;
borderName = "BOTTOM";
break;
case 'l':
b1 = style1.getBorderLeft() == BorderStyle.THIN;
b2 = style2.getBorderLeft() == BorderStyle.THIN;
b1 = style1.getBorderLeftEnum() == BorderStyle.THIN;
b2 = style2.getBorderLeftEnum() == BorderStyle.THIN;
borderName = "LEFT";
break;
case 'r':
b1 = style1.getBorderRight() == BorderStyle.THIN;
b2 = style2.getBorderRight() == BorderStyle.THIN;
b1 = style1.getBorderRightEnum() == BorderStyle.THIN;
b2 = style2.getBorderRightEnum() == BorderStyle.THIN;
borderName = "RIGHT";
break;
}

View File

@ -298,10 +298,10 @@ public class ToHtml {
}
private void borderStyles(CellStyle style) {
styleOut("border-left", style.getBorderLeft(), BORDER);
styleOut("border-right", style.getBorderRight(), BORDER);
styleOut("border-top", style.getBorderTop(), BORDER);
styleOut("border-bottom", style.getBorderBottom(), BORDER);
styleOut("border-left", style.getBorderLeftEnum(), BORDER);
styleOut("border-right", style.getBorderRightEnum(), BORDER);
styleOut("border-top", style.getBorderTopEnum(), BORDER);
styleOut("border-bottom", style.getBorderBottomEnum(), BORDER);
}
private void fontStyle(CellStyle style) {

View File

@ -240,6 +240,7 @@ public class TestAllFiles {
EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_OnlyOneCorePropertiesPartFAIL.docx");
EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_UnauthorizedXMLLangAttributeFAIL.docx");
EXPECTED_FAILURES.add("openxml4j/OPCCompliance_DerivedPartNameFAIL.docx");
EXPECTED_FAILURES.add("openxml4j/invalid.xlsx");
EXPECTED_FAILURES.add("spreadsheet/54764-2.xlsx"); // see TestXSSFBugs.bug54764()
EXPECTED_FAILURES.add("spreadsheet/54764.xlsx"); // see TestXSSFBugs.bug54764()
EXPECTED_FAILURES.add("spreadsheet/Simple.xlsb");
@ -297,7 +298,10 @@ public class TestAllFiles {
List<Object[]> files = new ArrayList<Object[]>();
for(String file : scanner.getIncludedFiles()) {
file = file.replace('\\', '/'); // ... failures/handlers lookup doesn't work on windows otherwise
if (IGNORED.contains(file)) continue;
if (IGNORED.contains(file)) {
System.out.println("Ignoring " + file);
continue;
}
FileHandler handler = HANDLERS.get(getExtension(file));
files.add(new Object[] { file, handler });

View File

@ -30,6 +30,7 @@ import javax.xml.transform.TransformerException;
import org.apache.poi.POIXMLException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
@ -134,6 +135,9 @@ public class XSSFFileHandler extends SpreadsheetHandler {
EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/Simple.xlsb");
// TODO: good to ignore?
EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/sample-beta.xlsx");
// corrupt/invalid
EXPECTED_ADDITIONAL_FAILURES.add("openxml4j/invalid.xlsx");
}
@SuppressWarnings("resource")

View File

@ -16,6 +16,8 @@
==================================================================== */
package org.apache.poi.common.usermodel;
import org.apache.poi.util.Removal;
/**
* Represents a hyperlink.
*/
@ -25,6 +27,7 @@ public interface Hyperlink {
*
* @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#URL} instead.
*/
@Removal(version="3.17")
public static final int LINK_URL = 1; // HyperlinkType.URL.getCode()
/**
@ -32,6 +35,7 @@ public interface Hyperlink {
*
* @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#DOCUMENT} instead.
*/
@Removal(version="3.17")
public static final int LINK_DOCUMENT = 2; // HyperlinkType.DOCUMENT.getCode()
/**
@ -39,6 +43,7 @@ public interface Hyperlink {
*
* @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#EMAIL} instead.
*/
@Removal(version="3.17")
public static final int LINK_EMAIL = 3; // HyperlinkType.EMAIL.getCode()
/**
@ -46,6 +51,7 @@ public interface Hyperlink {
*
* @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#FILE} instead.
*/
@Removal(version="3.17")
public static final int LINK_FILE = 4; // HyperlinkType.FILE.getCode()
@ -83,6 +89,7 @@ public interface Hyperlink {
* @return the type of this hyperlink
* @see HyperlinkType#forInt(int)
* @deprecated POI 3.15 beta 3. Use {@link #getTypeEnum()}
* getType will return a HyperlinkType enum in the future.
*/
public int getType();

View File

@ -17,8 +17,6 @@
package org.apache.poi.hssf.model;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.util.Internal;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.FormulaParseException;
@ -26,6 +24,9 @@ import org.apache.poi.ss.formula.FormulaParser;
import org.apache.poi.ss.formula.FormulaParsingWorkbook;
import org.apache.poi.ss.formula.FormulaRenderer;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
/**
* HSSF wrapper for the {@link FormulaParser} and {@link FormulaRenderer}
@ -61,6 +62,7 @@ public final class HSSFFormulaParser {
*
* @deprecated POI 3.15 beta 3. Use {@link #parse(String, HSSFWorkbook, FormulaType)} instead.
*/
@Removal(version="3.17")
public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType) throws FormulaParseException {
return parse(formula, workbook, FormulaType.forInt(formulaType));
}
@ -87,6 +89,7 @@ public final class HSSFFormulaParser {
* @throws FormulaParseException if the formula has incorrect syntax or is otherwise invalid
* @deprecated POI 3.15 beta 3. Use {@link #parse(String, HSSFWorkbook, FormulaType, int)} instead.
*/
@Removal(version="3.17")
public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType, int sheetIndex) throws FormulaParseException {
return parse(formula, workbook, FormulaType.forInt(formulaType), sheetIndex);
}

View File

@ -42,28 +42,83 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
return borderFormatting;
}
/**
* @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderBottom() {
public short getBorderBottom() {
return (short)borderFormatting.getBorderBottom();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderBottomEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderBottom());
}
/**
* @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderDiagonal() {
public short getBorderDiagonal() {
return (short)borderFormatting.getBorderDiagonal();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderDiagonalEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderDiagonal());
}
/**
* @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderLeft() {
public short getBorderLeft() {
return (short)borderFormatting.getBorderLeft();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderLeftEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderLeft());
}
/**
* @deprecated POI 3.15. Use {@link #getBorderRightEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderRight() {
public short getBorderRight() {
return (short)borderFormatting.getBorderRight();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderRightEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderRight());
}
/**
* @deprecated POI 3.15. Use {@link #getBorderTopEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderTop() {
public short getBorderTop() {
return (short)borderFormatting.getBorderTop();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderTopEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderTop());
}

View File

@ -446,6 +446,7 @@ public class HSSFCell implements Cell {
*
* Will return {@link CellType} in a future version of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
* @deprecated 3.15. Will be return a {@link CellType} enum in the future.
*/
@Override
public int getCellType()
@ -459,7 +460,6 @@ public class HSSFCell implements Cell {
* @deprecated POI 3.15 beta 3
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Override
public CellType getCellTypeEnum()
{
@ -1154,6 +1154,7 @@ public class HSSFCell implements Cell {
* @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING},
* {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending
* on the cached value of the formula
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCachedFormulaResultType() {
@ -1169,7 +1170,6 @@ public class HSSFCell implements Cell {
* @deprecated POI 3.15 beta 3
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Override
public CellType getCachedFormulaResultTypeEnum() {
if (_cellType != CellType.FORMULA) {

View File

@ -32,6 +32,7 @@ import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.util.Removal;
/**
* High level representation of the style of a cell in a sheet of a workbook.
@ -254,6 +255,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #ALIGN_CENTER_SELECTION
* @deprecated POI 3.15 beta 3. Use {@link #setAlignment(HorizontalAlignment)} instead.
*/
@Removal(version="3.17")
@Override
public void setAlignment(short align)
{
@ -329,6 +331,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see VerticalAlignment
* @deprecated POI 3.15 beta 3. Use {@link #setVerticalAlignment(VerticalAlignment)} instead.
*/
@Removal(version="3.17")
@Override
public void setVerticalAlignment(short align)
{
@ -459,6 +462,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderLeft(BorderStyle)} instead.
*/
@Removal(version="3.17")
@Override
public void setBorderLeft(short border)
{
@ -469,6 +473,7 @@ public final class HSSFCellStyle implements CellStyle {
/**
* set the type of border to use for the left border of the cell
* @param border type
* @since POI 3.15
*/
@Override
public void setBorderLeft(BorderStyle border)
@ -479,9 +484,20 @@ public final class HSSFCellStyle implements CellStyle {
/**
* get the type of border to use for the left border of the cell
* @return border type
* @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderLeftEnum()}.
*/
@Override
public BorderStyle getBorderLeft()
public short getBorderLeft()
{
return _format.getBorderLeft();
}
/**
* get the type of border to use for the left border of the cell
* @return border type
* @since POI 3.15
*/
@Override
public BorderStyle getBorderLeftEnum()
{
return BorderStyle.valueOf(_format.getBorderLeft());
}
@ -505,6 +521,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderRight(BorderStyle)} instead.
*/
@Removal(version="3.17")
@Override
public void setBorderRight(short border)
{
@ -515,6 +532,7 @@ public final class HSSFCellStyle implements CellStyle {
/**
* set the type of border to use for the right border of the cell
* @param border type
* @since POI 3.15
*/
@Override
public void setBorderRight(BorderStyle border)
@ -525,9 +543,20 @@ public final class HSSFCellStyle implements CellStyle {
/**
* get the type of border to use for the right border of the cell
* @return border type
* @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderRightEnum()}.
*/
@Override
public BorderStyle getBorderRight()
public short getBorderRight()
{
return _format.getBorderRight();
}
/**
* get the type of border to use for the right border of the cell
* @return border type
* @since POI 3.15
*/
@Override
public BorderStyle getBorderRightEnum()
{
return BorderStyle.valueOf(_format.getBorderRight());
}
@ -551,6 +580,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderTop(BorderStyle)} instead.
*/
@Removal(version="3.17")
@Override
public void setBorderTop(short border)
{
@ -561,6 +591,7 @@ public final class HSSFCellStyle implements CellStyle {
/**
* set the type of border to use for the top border of the cell
* @param border type
* @since POI 3.15
*/
@Override
public void setBorderTop(BorderStyle border)
@ -571,9 +602,20 @@ public final class HSSFCellStyle implements CellStyle {
/**
* get the type of border to use for the top border of the cell
* @return border type
* @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderTopEnum()}.
*/
@Override
public BorderStyle getBorderTop()
public short getBorderTop()
{
return _format.getBorderTop();
}
/**
* get the type of border to use for the top border of the cell
* @return border type
* @since 3.15
*/
@Override
public BorderStyle getBorderTopEnum()
{
return BorderStyle.valueOf(_format.getBorderTop());
}
@ -597,6 +639,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderBottom(BorderStyle)} instead.
*/
@Removal(version="3.17")
@Override
public void setBorderBottom(short border)
{
@ -607,6 +650,7 @@ public final class HSSFCellStyle implements CellStyle {
/**
* set the type of border to use for the bottom border of the cell
* @param border type
* @since 3.15 beta 2
*/
@Override
public void setBorderBottom(BorderStyle border)
@ -617,9 +661,20 @@ public final class HSSFCellStyle implements CellStyle {
/**
* get the type of border to use for the bottom border of the cell
* @return border type
* @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderBottomEnum()}.
*/
@Override
public BorderStyle getBorderBottom()
public short getBorderBottom()
{
return _format.getBorderBottom();
}
/**
* get the type of border to use for the bottom border of the cell
* @return border type
* @since 3.15
*/
@Override
public BorderStyle getBorderBottomEnum()
{
return BorderStyle.valueOf(_format.getBorderBottom());
}
@ -733,6 +788,7 @@ public final class HSSFCellStyle implements CellStyle {
* @param fp fill pattern (set to 1 to fill w/foreground color)
* @deprecated POI 3.15 beta 3. Use {@link #setFillPattern(FillPatternType)} instead.
*/
@Removal(version="3.17")
@Override
public void setFillPattern(short fp)
{

View File

@ -21,6 +21,7 @@ import org.apache.poi.ddf.EscherClientAnchorRecord;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.util.Removal;
/**
* A client anchor is attached to an excel worksheet. It anchors against a
@ -250,6 +251,7 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
/**
* Gets the anchor type
* Changed from returning an int to an enum in POI 3.14 beta 1.
* @return the anchor type
*/
@Override
@ -260,11 +262,22 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
/**
* Sets the anchor type
* @param anchorType the anchor type to set
* @since POI 3.14
*/
@Override
public void setAnchorType(AnchorType anchorType) {
_escherClientAnchor.setFlag(anchorType.value);
}
/**
* Sets the anchor type
* @param anchorType the anchor type to set
* @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead.
*/
@Removal(version="3.17")
@Override
public void setAnchorType(int anchorType) {
_escherClientAnchor.setFlag((short) anchorType);
}
private void checkRange(int value, int minRange, int maxRange, String varName) {
if (value < minRange || value > maxRange)

View File

@ -21,6 +21,7 @@ import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.hssf.record.common.ExtendedColor;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
public class HSSFCreationHelper implements CreationHelper {
private final HSSFWorkbook workbook;
@ -50,6 +51,7 @@ public class HSSFCreationHelper implements CreationHelper {
* @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead.
*/
@Deprecated
@Removal(version="3.17")
@Override
public HSSFHyperlink createHyperlink(int type) {
return new HSSFHyperlink(type);

View File

@ -55,6 +55,7 @@ final class HSSFEvaluationCell implements EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCellType() {
@ -65,7 +66,6 @@ final class HSSFEvaluationCell implements EvaluationCell {
* @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Override
public CellType getCellTypeEnum() {
return _cell.getCellTypeEnum();
@ -99,6 +99,7 @@ final class HSSFEvaluationCell implements EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type of cached formula result
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCachedFormulaResultType() {
@ -109,7 +110,6 @@ final class HSSFEvaluationCell implements EvaluationCell {
* @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Override
public CellType getCachedFormulaResultTypeEnum() {
return _cell.getCachedFormulaResultTypeEnum();

View File

@ -30,11 +30,10 @@ import org.apache.poi.ss.formula.eval.StringValueEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.Internal;
/**
* Evaluates formula cells.<p/>
@ -81,6 +80,11 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator {
public static HSSFFormulaEvaluator create(HSSFWorkbook workbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) {
return new HSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder);
}
@Override
protected RichTextString createRichTextString(String str) {
return new HSSFRichTextString(str);
}
/**
@ -136,87 +140,10 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator {
public void notifySetFormula(Cell cell) {
_bookEvaluator.notifyUpdateCell(new HSSFEvaluationCell((HSSFCell)cell));
}
/**
* If cell contains formula, it evaluates the formula, and saves the result of the formula. The
* cell remains as a formula cell. If the cell does not contain formula, rather than throwing an
* exception, this method returns {@link CellType#_NONE} and leaves the cell unchanged.
*
* Note that the type of the <em>formula result</em> is returned, so you know what kind of
* cached formula result is also stored with the formula.
* <pre>
* CellType evaluatedCellType = evaluator.evaluateFormulaCell(cell);
* </pre>
* Be aware that your cell will hold both the formula, and the result. If you want the cell
* replaced with the result of the formula, use {@link #evaluateInCell(org.apache.poi.ss.usermodel.Cell)}
* @param cell The cell to evaluate
* @return {@link CellType#_NONE} for non-formula cells, or the type of the <em>formula result</em>
* @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal
@Override
public CellType evaluateFormulaCellEnum(Cell cell) {
if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
return CellType._NONE;
}
CellValue cv = evaluateFormulaCellValue(cell);
// cell remains a formula cell, but the cached value is changed
setCellValue(cell, cv);
return cv.getCellType();
}
/**
* If cell contains formula, it evaluates the formula, and
* puts the formula result back into the cell, in place
* of the old formula.
* Else if cell does not contain formula, this method leaves
* the cell unchanged.
* Note that the same instance of HSSFCell is returned to
* allow chained calls like:
* <pre>
* int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
* </pre>
* Be aware that your cell value will be changed to hold the
* result of the formula. If you simply want the formula
* value computed for you, use {@link #evaluateFormulaCellEnum(Cell)}}
*/
@Override
public HSSFCell evaluateInCell(Cell cell) {
if (cell == null) {
return null;
}
HSSFCell result = (HSSFCell) cell;
if (cell.getCellTypeEnum() == CellType.FORMULA) {
CellValue cv = evaluateFormulaCellValue(cell);
setCellValue(cell, cv);
setCellType(cell, cv); // cell will no longer be a formula cell
}
return result;
}
private static void setCellValue(Cell cell, CellValue cv) {
CellType cellType = cv.getCellType();
switch (cellType) {
case BOOLEAN:
cell.setCellValue(cv.getBooleanValue());
break;
case ERROR:
cell.setCellErrorValue(cv.getErrorValue());
break;
case NUMERIC:
cell.setCellValue(cv.getNumberValue());
break;
case STRING:
cell.setCellValue(new HSSFRichTextString(cv.getStringValue()));
break;
case BLANK:
// never happens - blanks eventually get translated to zero
case FORMULA:
// this will never happen, we have already evaluated the formula
default:
throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
}
return (HSSFCell) super.evaluateInCell(cell);
}
/**

View File

@ -273,6 +273,8 @@ public class HSSFHyperlink implements Hyperlink {
*
* @return the type of this hyperlink
* @see HyperlinkType#forInt
* @deprecated POI 3.15. Use {@link #getTypeEnum()} instead.
* getType will return a HyperlinkType enum in the future.
*/
@Override
public int getType() {

View File

@ -94,6 +94,8 @@ public class FileBackedDataSource extends DataSource {
if (writable) {
dst = channel.map(FileChannel.MapMode.READ_WRITE, position, length);
worked = 0;
// remember the buffer for cleanup if necessary
buffersToClean.add(dst);
} else {
// Read
channel.position(position);
@ -109,9 +111,6 @@ public class FileBackedDataSource extends DataSource {
// Ready it for reading
dst.position(0);
// remember the buffer for cleanup if necessary
buffersToClean.add(dst);
// All done
return dst;
}

View File

@ -83,6 +83,7 @@ public interface SlideShow<
* @param format The format of the picture.
*
* @return the picture data reference.
* @since 3.15 beta 1
*/
PictureData addPicture(InputStream is, PictureType format) throws IOException;
@ -93,6 +94,7 @@ public interface SlideShow<
* @param format The format of the picture.
*
* @return the picture data reference
* @since 3.15 beta 1
*/
PictureData addPicture(File pict, PictureType format) throws IOException;
@ -101,6 +103,7 @@ public interface SlideShow<
*
* @param pictureData The picture data to find in the SlideShow
* @return {@code null} if picture data is not found in this slideshow
* @since 3.15 beta 3
*/
PictureData findPictureData(byte[] pictureData);

View File

@ -35,7 +35,6 @@ import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.util.DateFormatConverter;
import org.apache.poi.util.Internal;
/**
* Format a value according to the standard Excel behavior. This "standard" is
@ -44,28 +43,35 @@ import org.apache.poi.util.Internal;
* <p/>
* An Excel format has up to four parts, separated by semicolons. Each part
* specifies what to do with particular kinds of values, depending on the number
* of parts given: <dl> <dt>One part (example: <tt>[Green]#.##</tt>) <dd>If the
* value is a number, display according to this one part (example: green text,
* with up to two decimal points). If the value is text, display it as is.
* <dt>Two parts (example: <tt>[Green]#.##;[Red]#.##</tt>) <dd>If the value is a
* positive number or zero, display according to the first part (example: green
* of parts given:
* <dl>
* <dt>One part (example: <tt>[Green]#.##</tt>)</dt>
* <dd>If the value is a number, display according to this one part (example: green text,
* with up to two decimal points). If the value is text, display it as is.</dd>
*
* <dt>Two parts (example: <tt>[Green]#.##;[Red]#.##</tt>)</dt>
* <dd>If the value is a positive number or zero, display according to the first part (example: green
* text, with up to two decimal points); if it is a negative number, display
* according to the second part (example: red text, with up to two decimal
* points). If the value is text, display it as is. <dt>Three parts (example:
* <tt>[Green]#.##;[Black]#.##;[Red]#.##</tt>) <dd>If the value is a positive
* points). If the value is text, display it as is.</dd>
*
* <dt>Three parts (example: <tt>[Green]#.##;[Black]#.##;[Red]#.##</tt>)</dt>
* <dd>If the value is a positive
* number, display according to the first part (example: green text, with up to
* two decimal points); if it is zero, display according to the second part
* (example: black text, with up to two decimal points); if it is a negative
* number, display according to the third part (example: red text, with up to
* two decimal points). If the value is text, display it as is. <dt>Four parts
* (example: <tt>[Green]#.##;[Black]#.##;[Red]#.##;[@]</tt>) <dd>If the value is
* a positive number, display according to the first part (example: green text,
* two decimal points). If the value is text, display it as is.</dd>
*
* <dt>Four parts (example: <tt>[Green]#.##;[Black]#.##;[Red]#.##;[@]</tt>)</dt>
* <dd>If the value is a positive number, display according to the first part (example: green text,
* with up to two decimal points); if it is zero, display according to the
* second part (example: black text, with up to two decimal points); if it is a
* negative number, display according to the third part (example: red text, with
* up to two decimal points). If the value is text, display according to the
* fourth part (example: text in the cell's usual color, with the text value
* surround by brackets). </dl>
* surround by brackets).</dd>
* </dl>
* <p/>
* A given format part may specify a given Locale, by including something
* like <tt>[$$-409]</tt> or <tt>[$&pound;-809]</tt> or <tt>[$-40C]</tt>. These
@ -421,6 +427,7 @@ public class CellFormat {
* @param cell The cell.
*
* @return The ultimate type of this cell.
* @deprecated POI 3.15. This will return a CellType enum in the future
*/
public static int ultimateType(Cell cell) {
return ultimateTypeEnum(cell).getCode();
@ -439,7 +446,6 @@ public class CellFormat {
* @deprecated POI 3.15 beta 3
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
public static CellType ultimateTypeEnum(Cell cell) {
CellType type = cell.getCellTypeEnum();
if (type == CellType.FORMULA)

View File

@ -23,6 +23,7 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@ -108,6 +109,37 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook
throw new IllegalStateException("Bad cell type (" + cell.getCellTypeEnum() + ")");
}
}
/**
* If cell contains formula, it evaluates the formula, and
* puts the formula result back into the cell, in place
* of the old formula.
* Else if cell does not contain formula, this method leaves
* the cell unchanged.
* Note that the same instance of HSSFCell is returned to
* allow chained calls like:
* <pre>
* int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
* </pre>
* Be aware that your cell value will be changed to hold the
* result of the formula. If you simply want the formula
* value computed for you, use {@link #evaluateFormulaCellEnum(Cell)}}
* @param cell
* @return the {@code cell} that was passed in, allowing for chained calls
*/
@Override
public Cell evaluateInCell(Cell cell) {
if (cell == null) {
return null;
}
Cell result = cell;
if (cell.getCellTypeEnum() == CellType.FORMULA) {
CellValue cv = evaluateFormulaCellValue(cell);
setCellValue(cell, cv);
setCellType(cell, cv); // cell will no longer be a formula cell
}
return result;
}
protected abstract CellValue evaluateFormulaCellValue(Cell cell);
@ -125,14 +157,47 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook
* replaced with the result of the formula, use {@link #evaluateInCell(org.apache.poi.ss.usermodel.Cell)}
* @param cell The cell to evaluate
* @return -1 for non-formula cells, or the type of the <em>formula result</em>
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int evaluateFormulaCell(Cell cell) {
return evaluateFormulaCellEnum(cell).getCode();
}
/**
* If cell contains formula, it evaluates the formula,
* and saves the result of the formula. The cell
* remains as a formula cell.
* Else if cell does not contain formula, this method leaves
* the cell unchanged.
* Note that the type of the formula result is returned,
* so you know what kind of value is also stored with
* the formula.
* <pre>
* CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
* </pre>
* Be aware that your cell will hold both the formula,
* and the result. If you want the cell replaced with
* the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)} }
* @param cell The cell to evaluate
* @return The type of the formula result (the cell's type remains as CellType.FORMULA however)
* If cell is not a formula cell, returns {@link CellType#_NONE} rather than throwing an exception.
* @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Override
public CellType evaluateFormulaCellEnum(Cell cell) {
if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
return CellType._NONE;
}
CellValue cv = evaluateFormulaCellValue(cell);
// cell remains a formula cell, but the cached value is changed
setCellValue(cell, cv);
return cv.getCellTypeEnum();
}
protected static void setCellType(Cell cell, CellValue cv) {
CellType cellType = cv.getCellType();
CellType cellType = cv.getCellTypeEnum();
switch (cellType) {
case BOOLEAN:
case ERROR:
@ -150,6 +215,33 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook
throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
}
}
protected abstract RichTextString createRichTextString(String str);
protected void setCellValue(Cell cell, CellValue cv) {
CellType cellType = cv.getCellTypeEnum();
switch (cellType) {
case BOOLEAN:
cell.setCellValue(cv.getBooleanValue());
break;
case ERROR:
cell.setCellErrorValue(cv.getErrorValue());
break;
case NUMERIC:
cell.setCellValue(cv.getNumberValue());
break;
case STRING:
cell.setCellValue(createRichTextString(cv.getStringValue()));
break;
case BLANK:
// never happens - blanks eventually get translated to zero
case FORMULA:
// this will never happen, we have already evaluated the formula
default:
throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
}
}
/**
* Loops over all cells in all sheets of the supplied

View File

@ -42,6 +42,7 @@ public interface EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
int getCellType();
/**
@ -61,6 +62,7 @@ public interface EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type of cached formula result
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
int getCachedFormulaResultType();
/**

View File

@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.RangePtg;
import org.apache.poi.ss.formula.ptg.UnionPtg;
import org.apache.poi.ss.formula.ptg.ValueOperatorPtg;
import org.apache.poi.util.Removal;
/**
* This class performs 'operand class' transformation. Non-base tokens are classified into three
@ -59,7 +60,10 @@ final class OperandClassTransformer {
private final FormulaType _formulaType;
/** @deprecated POI 3.15 beta 3. */
/**
* @deprecated POI 3.15 beta 3. Use {@code OperandClassTransformer(FormulaType)} instead.
*/
@Removal(version="3.17")
public OperandClassTransformer(int formulaType) {
this(FormulaType.forInt(formulaType));
}

View File

@ -108,6 +108,7 @@ final class ForkedEvaluationCell implements EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCellType() {
@ -118,7 +119,6 @@ final class ForkedEvaluationCell implements EvaluationCell {
* @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Override
public CellType getCellTypeEnum() {
return _cellType;
@ -160,6 +160,7 @@ final class ForkedEvaluationCell implements EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type of cached formula result
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCachedFormulaResultType() {
@ -170,7 +171,6 @@ final class ForkedEvaluationCell implements EvaluationCell {
* @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Override
public CellType getCachedFormulaResultTypeEnum() {
return _masterCell.getCachedFormulaResultTypeEnum();

View File

@ -17,7 +17,10 @@
package org.apache.poi.ss.formula.functions;
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.ValueEval;
/**
@ -46,8 +49,18 @@ public final class DGet implements IDStarAlgorithm {
public ValueEval getResult() {
if(result == null) {
return ErrorEval.VALUE_INVALID;
} else {
return result;
}
} else if(result instanceof BlankEval) {
return ErrorEval.VALUE_INVALID;
} else
try {
if(OperandResolver.coerceValueToString(OperandResolver.getSingleValue(result, 0, 0)).equals("")) {
return ErrorEval.VALUE_INVALID;
}
else {
return result;
}
} catch (EvaluationException e) {
return e.getErrorEval();
}
}
}

View File

@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.functions;
import org.apache.poi.ss.formula.TwoDEval;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NotImplementedException;
import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.RefEval;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.StringValueEval;
import org.apache.poi.ss.formula.eval.ValueEval;
@ -62,11 +62,17 @@ public final class DStarRunner implements Function3Arg {
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex,
ValueEval database, ValueEval filterColumn, ValueEval conditionDatabase) {
// Input processing and error checks.
if(!(database instanceof TwoDEval) || !(conditionDatabase instanceof TwoDEval)) {
if(!(database instanceof AreaEval) || !(conditionDatabase instanceof AreaEval)) {
return ErrorEval.VALUE_INVALID;
}
TwoDEval db = (TwoDEval)database;
TwoDEval cdb = (TwoDEval)conditionDatabase;
AreaEval db = (AreaEval)database;
AreaEval cdb = (AreaEval)conditionDatabase;
try {
filterColumn = OperandResolver.getSingleValue(filterColumn, srcRowIndex, srcColumnIndex);
} catch (EvaluationException e) {
return e.getErrorEval();
}
int fc;
try {
@ -100,15 +106,11 @@ public final class DStarRunner implements Function3Arg {
}
// Filter each entry.
if(matches) {
try {
ValueEval currentValueEval = solveReference(db.getValue(row, fc));
// Pass the match to the algorithm and conditionally abort the search.
boolean shouldContinue = algorithm.processMatch(currentValueEval);
if(! shouldContinue) {
break;
}
} catch (EvaluationException e) {
return e.getErrorEval();
ValueEval currentValueEval = resolveReference(db, row, fc);
// Pass the match to the algorithm and conditionally abort the search.
boolean shouldContinue = algorithm.processMatch(currentValueEval);
if(! shouldContinue) {
break;
}
}
}
@ -126,56 +128,16 @@ public final class DStarRunner implements Function3Arg {
}
/**
* Resolve reference(-chains) until we have a normal value.
*
*
* @param field a ValueEval which can be a RefEval.
* @return a ValueEval which is guaranteed not to be a RefEval
* @throws EvaluationException If a multi-sheet reference was found along the way.
*/
private static ValueEval solveReference(ValueEval field) throws EvaluationException {
if (field instanceof RefEval) {
RefEval refEval = (RefEval)field;
if (refEval.getNumberOfSheets() > 1) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
return solveReference(refEval.getInnerValueEval(refEval.getFirstSheetIndex()));
}
else {
return field;
}
}
/**
* Returns the first column index that matches the given name. The name can either be
* a string or an integer, when it's an integer, then the respective column
* (1 based index) is returned.
* @param nameValueEval
* @param db
* @return the first column index that matches the given name (or int)
* @param nameValueEval Must not be a RefEval or AreaEval. Thus make sure resolveReference() is called on the value first!
* @param db Database
* @return Corresponding column number.
* @throws EvaluationException
*/
@SuppressWarnings("unused")
private static int getColumnForTag(ValueEval nameValueEval, TwoDEval db)
private static int getColumnForName(ValueEval nameValueEval, AreaEval db)
throws EvaluationException {
int resultColumn = -1;
// Numbers as column indicator are allowed, check that.
if(nameValueEval instanceof NumericValueEval) {
double doubleResultColumn = ((NumericValueEval)nameValueEval).getNumberValue();
resultColumn = (int)doubleResultColumn;
// Floating comparisions are usually not possible, but should work for 0.0.
if(doubleResultColumn - resultColumn != 0.0)
throw new EvaluationException(ErrorEval.VALUE_INVALID);
resultColumn -= 1; // Numbers are 1-based not 0-based.
} else {
resultColumn = getColumnForName(nameValueEval, db);
}
return resultColumn;
}
private static int getColumnForName(ValueEval nameValueEval, TwoDEval db)
throws EvaluationException {
String name = getStringFromValueEval(nameValueEval);
String name = OperandResolver.coerceValueToString(nameValueEval);
return getColumnForString(db, name);
}
@ -187,16 +149,19 @@ public final class DStarRunner implements Function3Arg {
* @return Corresponding column number.
* @throws EvaluationException If it's not possible to turn all headings into strings.
*/
private static int getColumnForString(TwoDEval db,String name)
private static int getColumnForString(AreaEval db,String name)
throws EvaluationException {
int resultColumn = -1;
final int width = db.getWidth();
for(int column = 0; column < width; ++column) {
ValueEval columnNameValueEval = db.getValue(0, column);
if(solveReference(columnNameValueEval) instanceof BlankEval) {
ValueEval columnNameValueEval = resolveReference(db, 0, column);
if(columnNameValueEval instanceof BlankEval) {
continue;
}
String columnName = getStringFromValueEval(columnNameValueEval);
if(columnNameValueEval instanceof ErrorEval) {
continue;
}
String columnName = OperandResolver.coerceValueToString(columnNameValueEval);
if(name.equals(columnName)) {
resultColumn = column;
break;
@ -215,7 +180,7 @@ public final class DStarRunner implements Function3Arg {
* @throws EvaluationException If references could not be resolved or comparison
* operators and operands didn't match.
*/
private static boolean fullfillsConditions(TwoDEval db, int row, TwoDEval cdb)
private static boolean fullfillsConditions(AreaEval db, int row, AreaEval cdb)
throws EvaluationException {
// Only one row must match to accept the input, so rows are ORed.
// Each row is made up of cells where each cell is a condition,
@ -229,20 +194,15 @@ public final class DStarRunner implements Function3Arg {
// special column that accepts formulas.
boolean columnCondition = true;
ValueEval condition = null;
try {
// The condition to apply.
condition = solveReference(cdb.getValue(conditionRow, column));
} catch (java.lang.RuntimeException e) {
// It might be a special formula, then it is ok if it fails.
columnCondition = false;
}
// The condition to apply.
condition = resolveReference(cdb, conditionRow, column);
// If the condition is empty it matches.
if(condition instanceof BlankEval)
continue;
// The column in the DB to apply the condition to.
ValueEval targetHeader = solveReference(cdb.getValue(0, column));
targetHeader = solveReference(targetHeader);
ValueEval targetHeader = resolveReference(cdb, 0, column);
if(!(targetHeader instanceof StringValueEval)) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
@ -254,14 +214,14 @@ public final class DStarRunner implements Function3Arg {
if(columnCondition == true) { // normal column condition
// Should not throw, checked above.
ValueEval value = db.getValue(
row, getColumnForName(targetHeader, db));
ValueEval value = resolveReference(db, row, getColumnForName(targetHeader, db));
if(!testNormalCondition(value, condition)) {
matches = false;
break;
}
} else { // It's a special formula condition.
if(getStringFromValueEval(condition).isEmpty()) {
// TODO: Check whether the condition cell contains a formula and return #VALUE! if it doesn't.
if(OperandResolver.coerceValueToString(condition).isEmpty()) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
throw new NotImplementedException(
@ -328,7 +288,7 @@ public final class DStarRunner implements Function3Arg {
if(itsANumber) {
return testNumericCondition(value, operator.equal, stringOrNumber);
} else { // It's a string.
String valueString = value instanceof BlankEval ? "" : getStringFromValueEval(value);
String valueString = value instanceof BlankEval ? "" : OperandResolver.coerceValueToString(value);
return stringOrNumber.equals(valueString);
}
} else { // It's a text starts-with condition.
@ -336,7 +296,7 @@ public final class DStarRunner implements Function3Arg {
return value instanceof StringEval;
}
else {
String valueString = value instanceof BlankEval ? "" : getStringFromValueEval(value);
String valueString = value instanceof BlankEval ? "" : OperandResolver.coerceValueToString(value);
return valueString.startsWith(conditionString);
}
}
@ -424,20 +384,20 @@ public final class DStarRunner implements Function3Arg {
return null;
}
}
/**
* Takes a ValueEval and tries to retrieve a String value from it.
* It tries to resolve references if there are any.
* Resolve a ValueEval that's in an AreaEval.
*
* @param value ValueEval to retrieve the string from.
* @return String corresponding to the given ValueEval.
* @throws EvaluationException If it's not possible to retrieve a String value.
* @param db AreaEval from which the cell to resolve is retrieved.
* @param dbRow Relative row in the AreaEval.
* @param dbCol Relative column in the AreaEval.
* @return A ValueEval that is a NumberEval, StringEval, BoolEval, BlankEval or ErrorEval.
*/
private static String getStringFromValueEval(ValueEval value)
throws EvaluationException {
value = solveReference(value);
if(!(value instanceof StringValueEval))
throw new EvaluationException(ErrorEval.VALUE_INVALID);
return ((StringValueEval)value).getStringValue();
private static ValueEval resolveReference(AreaEval db, int dbRow, int dbCol) {
try {
return OperandResolver.getSingleValue(db.getValue(dbRow, dbCol), db.getFirstRow()+dbRow, db.getFirstColumn()+dbCol);
} catch (EvaluationException e) {
return e.getErrorEval();
}
}
}

View File

@ -19,6 +19,8 @@
package org.apache.poi.ss.usermodel;
import org.apache.poi.util.Removal;
/**
* High level representation for Border Formatting component
* of Conditional Formatting settings
@ -27,84 +29,128 @@ public interface BorderFormatting {
/** No border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#NONE}
*/
@Removal(version="3.17")
short BORDER_NONE = 0x0;
/** Thin border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THIN}
*/
@Removal(version="3.17")
short BORDER_THIN = 0x1;
/** Medium border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM}
*/
@Removal(version="3.17")
short BORDER_MEDIUM = 0x2;
/** dash border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASHED}
*/
@Removal(version="3.17")
short BORDER_DASHED = 0x3;
/** dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOTTED}
*/
@Removal(version="3.17")
short BORDER_DOTTED = 0x4;
/** Thick border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THICK}
*/
@Removal(version="3.17")
short BORDER_THICK = 0x5;
/** double-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOUBLE}
*/
@Removal(version="3.17")
short BORDER_DOUBLE = 0x6;
/** hair-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#HAIR}
*/
@Removal(version="3.17")
short BORDER_HAIR = 0x7;
/** Medium dashed border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASHED}
*/
@Removal(version="3.17")
short BORDER_MEDIUM_DASHED = 0x8;
/** dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT}
*/
@Removal(version="3.17")
short BORDER_DASH_DOT = 0x9;
/** medium dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT}
*/
@Removal(version="3.17")
short BORDER_MEDIUM_DASH_DOT = 0xA;
/** dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT_DOT}
*/
@Removal(version="3.17")
short BORDER_DASH_DOT_DOT = 0xB;
/** medium dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT_DOT}
*/
@Removal(version="3.17")
short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
/** slanted dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#SLANTED_DASH_DOT}
*/
@Removal(version="3.17")
short BORDER_SLANTED_DASH_DOT = 0xD;
BorderStyle getBorderBottom();
/**
* @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderBottom();
/** @since POI 3.15 */
BorderStyle getBorderBottomEnum();
BorderStyle getBorderDiagonal();
/**
* @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderDiagonal();
/** @since POI 3.15 */
BorderStyle getBorderDiagonalEnum();
BorderStyle getBorderLeft();
/**
* @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderLeft();
/** @since POI 3.15 */
BorderStyle getBorderLeftEnum();
BorderStyle getBorderRight();
/**
* @deprecated POI 3.15. Use {@link #getBorderRightEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderRight();
/** @since POI 3.15 */
BorderStyle getBorderRightEnum();
BorderStyle getBorderTop();
/**
* @deprecated POI 3.15. Use {@link #getBorderTopEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderTop();
/** @since POI 3.15 */
BorderStyle getBorderTopEnum();
short getBottomBorderColor();
Color getBottomBorderColorColor();

View File

@ -167,6 +167,7 @@ public interface Cell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return the cell type
* @deprecated POI 3.15. Will return a {@link CellType} enum in the future.
*/
int getCellType();
@ -178,7 +179,6 @@ public interface Cell {
* @deprecated POI 3.15 beta 3
* Will be renamed to <code>getCellType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Removal(version="4.2")
CellType getCellTypeEnum();
@ -191,6 +191,7 @@ public interface Cell {
* @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING},
* {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending
* on the cached value of the formula
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
int getCachedFormulaResultType();
@ -203,7 +204,6 @@ public interface Cell {
* @deprecated POI 3.15 beta 3
* Will be renamed to <code>getCachedFormulaResultType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
CellType getCachedFormulaResultTypeEnum();
/**

View File

@ -17,270 +17,316 @@
package org.apache.poi.ss.usermodel;
import org.apache.poi.util.Removal;
public interface CellStyle {
/**
* general (normal) horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#GENERAL} instead.
*/
@Removal(version="3.17")
static final short ALIGN_GENERAL = 0x0; //HorizontalAlignment.GENERAL.getCode();
/**
* left-justified horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#LEFT} instead.
*/
@Removal(version="3.17")
static final short ALIGN_LEFT = 0x1; //HorizontalAlignment.LEFT.getCode();
/**
* center horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#CENTER} instead.
*/
@Removal(version="3.17")
static final short ALIGN_CENTER = 0x2; //HorizontalAlignment.CENTER.getCode();
/**
* right-justified horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#RIGHT} instead.
*/
@Removal(version="3.17")
static final short ALIGN_RIGHT = 0x3; //HorizontalAlignment.RIGHT.getCode();
/**
* fill? horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#FILL} instead.
*/
@Removal(version="3.17")
static final short ALIGN_FILL = 0x4; //HorizontalAlignment.FILL.getCode();
/**
* justified horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#JUSTIFY} instead.
*/
@Removal(version="3.17")
static final short ALIGN_JUSTIFY = 0x5; //HorizontalAlignment.JUSTIFY.getCode();
/**
* center-selection? horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#CENTER_SELECTION} instead.
*/
@Removal(version="3.17")
static final short ALIGN_CENTER_SELECTION = 0x6; //HorizontalAlignment.CENTER_SELECTION.getCode();
/**
* top-aligned vertical alignment
* @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#TOP} instead.
*/
@Removal(version="3.17")
static final short VERTICAL_TOP = 0x0; //VerticalAlignment.TOP.getCode();
/**
* center-aligned vertical alignment
* @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#CENTER} instead.
*/
@Removal(version="3.17")
static final short VERTICAL_CENTER = 0x1; //VerticalAlignment.CENTER.getCode();
/**
* bottom-aligned vertical alignment
* @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#BOTTOM} instead.
*/
@Removal(version="3.17")
static final short VERTICAL_BOTTOM = 0x2; //VerticalAlignment.BOTTOM.getCode();
/**
* vertically justified vertical alignment
* @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#JUSTIFY} instead.
*/
@Removal(version="3.17")
static final short VERTICAL_JUSTIFY = 0x3; //VerticalAlignment.JUSTIFY.getCode();
/**
* No border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#NONE} instead.
*/
@Removal(version="3.17")
static final short BORDER_NONE = 0x0; //BorderStyle.NONE.getCode();
/**
* Thin border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THIN} instead.
*/
@Removal(version="3.17")
static final short BORDER_THIN = 0x1; //BorderStyle.THIN.getCode();
/**
* Medium border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM} instead.
*/
@Removal(version="3.17")
static final short BORDER_MEDIUM = 0x2; //BorderStyle.MEDIUM.getCode();
/**
* dash border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASHED} instead.
*/
@Removal(version="3.17")
static final short BORDER_DASHED = 0x3; //BorderStyle.DASHED.getCode();
/**
* dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOTTED} instead.
*/
@Removal(version="3.17")
static final short BORDER_DOTTED = 0x4; //BorderStyle.DOTTED.getCode();
/**
* Thick border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THICK} instead.
*/
@Removal(version="3.17")
static final short BORDER_THICK = 0x5; //BorderStyle.THICK.getCode();
/**
* double-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOUBLE} instead.
*/
@Removal(version="3.17")
static final short BORDER_DOUBLE = 0x6; //BorderStyle.DOUBLE.getCode();
/**
* hair-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#HAIR} instead.
*/
@Removal(version="3.17")
static final short BORDER_HAIR = 0x7; //BorderStyle.HAIR.getCode();
/**
* Medium dashed border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASHED} instead.
*/
@Removal(version="3.17")
static final short BORDER_MEDIUM_DASHED = 0x8; //BorderStyle.MEDIUM_DASHED.getCode();
/**
* dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_DASH_DOT = 0x9; //BorderStyle.DASH_DOT.getCode();
/**
* medium dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_MEDIUM_DASH_DOT = 0xA; //BorderStyle.MEDIUM_DASH_DOT.getCode();
/**
* dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_DASH_DOT_DOT = 0xB; //BorderStyle.DASH_DOT_DOT.getCode();
/**
* medium dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_MEDIUM_DASH_DOT_DOT = 0xC; //BorderStyle.MEDIUM_DASH_DOT_DOT.getCode();
/**
* slanted dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#SLANTED_DASH_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_SLANTED_DASH_DOT = 0xD; //BorderStyle.SLANTED_DASH_DOT.getCode();
/**
* Fill Pattern: No background
* @deprecated 3.15 beta 3. Use {@link FillPatternType#NO_FILL} instead.
*/
@Removal(version="3.17")
static final short NO_FILL = 0; //FillPatternType.NO_FILL.getCode();
/**
* Fill Pattern: Solidly filled
* @deprecated 3.15 beta 3. Use {@link FillPatternType#SOLID_FOREGROUND} instead.
*/
@Removal(version="3.17")
static final short SOLID_FOREGROUND = 1; //FillPatternType.SOLID_FOREGROUND.getCode();
/**
* Fill Pattern: Small fine dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#FINE_DOTS} instead.
*/
@Removal(version="3.17")
static final short FINE_DOTS = 2; //FillPatternType.FINE_DOTS.getCode();
/**
* Fill Pattern: Wide dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#ALT_BARS} instead.
*/
@Removal(version="3.17")
static final short ALT_BARS = 3; //FillPatternType.ALT_BARS.getCode();
/**
* Fill Pattern: Sparse dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#SPARSE_DOTS} instead.
*/
@Removal(version="3.17")
static final short SPARSE_DOTS = 4; //FillPatternType.SPARSE_DOTS.getCode();
/**
* Fill Pattern: Thick horizontal bands
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_HORZ_BANDS} instead.
*/
@Removal(version="3.17")
static final short THICK_HORZ_BANDS = 5; //FillPatternType.THICK_HORZ_BANDS.getCode();
/**
* Fill Pattern: Thick vertical bands
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_VERT_BANDS} instead.
*/
@Removal(version="3.17")
static final short THICK_VERT_BANDS = 6; //FillPatternType.THICK_VERT_BANDS.getCode();
/**
* Fill Pattern: Thick backward facing diagonals
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_BACKWARD_DIAG} instead.
*/
@Removal(version="3.17")
static final short THICK_BACKWARD_DIAG = 7; //FillPatternType.THICK_BACKWARD_DIAG.getCode();
/**
* Fill Pattern: Thick forward facing diagonals
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_FORWARD_DIAG} instead.
*/
@Removal(version="3.17")
static final short THICK_FORWARD_DIAG = 8; //FillPatternType.THICK_FORWARD_DIAG.getCode();
/**
* Fill Pattern: Large spots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#BIG_SPOTS} instead.
*/
@Removal(version="3.17")
static final short BIG_SPOTS = 9; //FillPatternType.BIG_SPOTS.getCode();
/**
* Fill Pattern: Brick-like layout
* @deprecated 3.15 beta 3. Use {@link FillPatternType#BRICKS} instead.
*/
@Removal(version="3.17")
static final short BRICKS = 10; //FillPatternType.BRICKS.getCode();
/**
* Fill Pattern: Thin horizontal bands
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_HORZ_BANDS} instead.
*/
@Removal(version="3.17")
static final short THIN_HORZ_BANDS = 11; //FillPatternType.THIN_HORZ_BANDS.getCode();
/**
* Fill Pattern: Thin vertical bands
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_VERT_BANDS} instead.
*/
@Removal(version="3.17")
static final short THIN_VERT_BANDS = 12; //FillPatternType.THIN_VERT_BANDS.getCode();
/**
* Fill Pattern: Thin backward diagonal
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_BACKWARD_DIAG} instead.
*/
@Removal(version="3.17")
static final short THIN_BACKWARD_DIAG = 13; //FillPatternType.THIN_BACKWARD_DIAG.getCode();
/**
* Fill Pattern: Thin forward diagonal
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_FORWARD_DIAG} instead.
*/
@Removal(version="3.17")
static final short THIN_FORWARD_DIAG = 14; //FillPatternType.THIN_FORWARD_DIAG.getCode();
/**
* Fill Pattern: Squares
* @deprecated 3.15 beta 3. Use {@link FillPatternType#SQUARES} instead.
*/
@Removal(version="3.17")
static final short SQUARES = 15; //FillPatternType.SQUARES.getCode();
/**
* Fill Pattern: Diamonds
* @deprecated 3.15 beta 3. Use {@link FillPatternType#DIAMONDS} instead.
*/
@Removal(version="3.17")
static final short DIAMONDS = 16; //FillPatternType.DIAMONDS.getCode();
/**
* Fill Pattern: Less Dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#LESS_DOTS} instead.
*/
@Removal(version="3.17")
static final short LESS_DOTS = 17; //FillPatternType.LESS_DOTS.getCode();
/**
* Fill Pattern: Least Dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#LEAST_DOTS} instead.
*/
@Removal(version="3.17")
static final short LEAST_DOTS = 18; //FillPatternType.LEAST_DOTS.getCode();
/**
@ -495,19 +541,29 @@ public interface CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link #setBorderLeft(BorderStyle)} instead
*/
@Removal(version="3.17")
void setBorderLeft(short border);
/**
* set the type of border to use for the left border of the cell
* @param border type
* @since POI 3.15
*/
void setBorderLeft(BorderStyle border);
/**
* get the type of border to use for the left border of the cell
* @return border type
* @deprecated POI 3.15. Use {@link #getBorderLeftEnum()} instead.
* This will return a BorderStyle enum in the future.
*/
BorderStyle getBorderLeft();
short getBorderLeft();
/**
* get the type of border to use for the left border of the cell
* @return border type
* @since POI 3.15
*/
BorderStyle getBorderLeftEnum();
/**
* set the type of border to use for the right border of the cell
@ -528,19 +584,29 @@ public interface CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link #setBorderRight(BorderStyle)} instead
*/
@Removal(version="3.17")
void setBorderRight(short border);
/**
* set the type of border to use for the right border of the cell
* @param border type
* @since POI 3.15
*/
void setBorderRight(BorderStyle border);
/**
* get the type of border to use for the right border of the cell
* @return border type
* @deprecated POI 3.15. Use {@link #getBorderRightEnum()} instead.
* This will return a BorderStyle enum in the future.
*/
BorderStyle getBorderRight();
short getBorderRight();
/**
* get the type of border to use for the right border of the cell
* @return border type
* @since POI 3.15
*/
BorderStyle getBorderRightEnum();
/**
* set the type of border to use for the top border of the cell
@ -561,19 +627,29 @@ public interface CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link #setBorderTop(BorderStyle)} instead
*/
@Removal(version="3.17")
void setBorderTop(short border);
/**
* set the type of border to use for the top border of the cell
* @param border type
* @since POI 3.15
*/
void setBorderTop(BorderStyle border);
/**
* get the type of border to use for the top border of the cell
* @return border type
* @deprecated POI 3.15. Use {@link #getBorderTopEnum()} instead.
* This will return a BorderStyle enum in the future.
*/
BorderStyle getBorderTop();
short getBorderTop();
/**
* get the type of border to use for the top border of the cell
* @return border type
* @since POI 3.15
*/
BorderStyle getBorderTopEnum();
/**
* set the type of border to use for the bottom border of the cell
@ -594,19 +670,29 @@ public interface CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link #setBorderBottom(BorderStyle)} instead.
*/
@Removal(version="3.17")
void setBorderBottom(short border);
/**
* set the type of border to use for the bottom border of the cell
* @param border type
* @since POI 3.15
*/
void setBorderBottom(BorderStyle border);
/**
* get the type of border to use for the bottom border of the cell
* @return border type
* @deprecated POI 3.15. Use {@link #getBorderBottomEnum()} instead.
* This will return a BorderStyle enum in the future.
*/
BorderStyle getBorderBottom();
short getBorderBottom();
/**
* get the type of border to use for the bottom border of the cell
* @return border type
* @since POI 3.15
*/
BorderStyle getBorderBottomEnum();
/**
* set the color to use for the left border

View File

@ -78,10 +78,22 @@ public final class CellValue {
}
/**
* @return Returns the cellType.
* @since POI 3.15
*/
public CellType getCellType() {
public CellType getCellTypeEnum() {
return _cellType;
}
/**
* @return Returns the cellType.
* @deprecated POI 3.15. Use {@link #getCellTypeEnum()} instead.
* In the future, the signature of this method will be changed to return a
* {@link CellType}.
*/
@Deprecated
public int getCellType() {
return _cellType.getCode();
}
/**
* @return Returns the errorValue.
*/

View File

@ -17,6 +17,7 @@
package org.apache.poi.ss.usermodel;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
/**
* A client anchor is attached to an excel worksheet. It anchors against a
@ -35,6 +36,7 @@ public interface ClientAnchor {
* </p>
* @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#MOVE_AND_RESIZE} instead.
*/
@Removal(version="3.17")
public static final AnchorType MOVE_AND_RESIZE = AnchorType.MOVE_AND_RESIZE;
/**
@ -50,6 +52,7 @@ public interface ClientAnchor {
* </p>
* @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#MOVE_DONT_RESIZE} instead.
*/
@Removal(version="3.17")
public static final AnchorType MOVE_DONT_RESIZE = AnchorType.MOVE_DONT_RESIZE;
/**
@ -66,6 +69,7 @@ public interface ClientAnchor {
* </p>
* @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#DONT_MOVE_AND_RESIZE} instead.
*/
@Removal(version="3.17")
public static final AnchorType DONT_MOVE_AND_RESIZE = AnchorType.DONT_MOVE_AND_RESIZE;
/**
@ -288,11 +292,20 @@ public interface ClientAnchor {
/**
* Sets the anchor type
* @param anchorType the anchor type to set
* @since POI 3.14
*/
public void setAnchorType( AnchorType anchorType );
/**
* Sets the anchor type
* @param anchorType the anchor type to set
* @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead.
*/
@Removal(version="3.17")
public void setAnchorType( int anchorType );
/**
* Gets the anchor type
* Changed from returning an int to an enum in POI 3.14 beta 1.
* @return the anchor type
*/
public AnchorType getAnchorType();

View File

@ -17,18 +17,18 @@
package org.apache.poi.ss.usermodel;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.util.Removal;
/**
* An object that handles instantiating concrete
* classes of the various instances one needs for
* HSSF and XSSF.
* Works around a major shortcoming in Java, where we
* can't have static methods on interfaces or abstract
* Works around a limitation in Java where we
* cannot have static methods on interfaces or abstract
* classes.
* This allows you to get the appropriate class for
* a given interface, without you having to worry
* about if you're dealing with HSSF or XSSF, despite
* Java being quite rubbish.
* about if you're dealing with HSSF or XSSF.
*/
public interface CreationHelper {
/**
@ -46,6 +46,7 @@ public interface CreationHelper {
* Creates a new Hyperlink, of the given type
* @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead.
*/
@Removal(version="3.17")
@Deprecated
Hyperlink createHyperlink(int type);

View File

@ -38,8 +38,8 @@ public enum DataConsolidateFunction {
VAR(10, "Var"),
VARP(11, "Varp");
private int value;
private String name;
private final int value;
private final String name;
DataConsolidateFunction(int value, String name) {
this.value = value;

View File

@ -166,19 +166,19 @@ public enum FormulaError {
return false;
}
public static FormulaError forInt(byte type){
public static FormulaError forInt(byte type) throws IllegalArgumentException {
FormulaError err = bmap.get(type);
if(err == null) throw new IllegalArgumentException("Unknown error type: " + type);
return err;
}
public static FormulaError forInt(int type){
public static FormulaError forInt(int type) throws IllegalArgumentException {
FormulaError err = imap.get(type);
if(err == null) err = bmap.get((byte)type);
if(err == null) throw new IllegalArgumentException("Unknown error type: " + type);
return err;
}
public static FormulaError forString(String code){
public static FormulaError forString(String code) throws IllegalArgumentException {
FormulaError err = smap.get(code);
if(err == null) throw new IllegalArgumentException("Unknown error code: " + code);
return err;

View File

@ -101,6 +101,7 @@ public interface FormulaEvaluator {
* or one of {@link CellType#NUMERIC}, {@link CellType#STRING},
* {@link CellType#BOOLEAN}, {@link CellType#ERROR}
* Note: the cell's type remains as CellType.FORMULA however.
* @deprecated 3.15. Will return a {@link CellType} enum in the future
*/
int evaluateFormulaCell(Cell cell);

View File

@ -19,6 +19,8 @@ package org.apache.poi.ss.usermodel;
import java.util.Iterator;
import org.apache.poi.util.Removal;
/**
* High level representation of a row of a spreadsheet.
*/
@ -240,8 +242,10 @@ public interface Row extends Iterable<Cell> {
CREATE_NULL_AS_BLANK(3);
/**
* @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - the id has no function and will be removed
* @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - the id has no function and will be removed.
* The {@code id} is only kept only for backwards compatibility with applications that hard-coded the number
*/
@Removal(version="3.17")
@Deprecated
public final int id;
private MissingCellPolicy(int id) {
@ -254,6 +258,7 @@ public interface Row extends Iterable<Cell> {
*
* @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum
**/
@Removal(version="3.17")
@Deprecated
public static final MissingCellPolicy RETURN_NULL_AND_BLANK = MissingCellPolicy.RETURN_NULL_AND_BLANK;
/**
@ -261,6 +266,7 @@ public interface Row extends Iterable<Cell> {
*
* @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum
**/
@Removal(version="3.17")
@Deprecated
public static final MissingCellPolicy RETURN_BLANK_AS_NULL = MissingCellPolicy.RETURN_BLANK_AS_NULL;
/**
@ -268,6 +274,7 @@ public interface Row extends Iterable<Cell> {
*
* @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum
**/
@Removal(version="3.17")
@Deprecated
public static final MissingCellPolicy CREATE_NULL_AS_BLANK = MissingCellPolicy.CREATE_NULL_AS_BLANK;

View File

@ -42,7 +42,7 @@ public class DataSources {
return new AbstractCellRangeDataSource<Number>(sheet, cellRangeAddress) {
public Number getPointAt(int index) {
CellValue cellValue = getCellValueAt(index);
if (cellValue != null && cellValue.getCellType() == CellType.NUMERIC) {
if (cellValue != null && cellValue.getCellTypeEnum() == CellType.NUMERIC) {
return Double.valueOf(cellValue.getNumberValue());
} else {
return null;
@ -59,7 +59,7 @@ public class DataSources {
return new AbstractCellRangeDataSource<String>(sheet, cellRangeAddress) {
public String getPointAt(int index) {
CellValue cellValue = getCellValueAt(index);
if (cellValue != null && cellValue.getCellType() == CellType.STRING) {
if (cellValue != null && cellValue.getCellTypeEnum() == CellType.STRING) {
return cellValue.getStringValue();
} else {
return null;

View File

@ -405,10 +405,10 @@ public final class CellUtil {
Map<String, Object> properties = new HashMap<String, Object>();
put(properties, ALIGNMENT, style.getAlignmentEnum());
put(properties, VERTICAL_ALIGNMENT, style.getVerticalAlignmentEnum());
put(properties, BORDER_BOTTOM, style.getBorderBottom());
put(properties, BORDER_LEFT, style.getBorderLeft());
put(properties, BORDER_RIGHT, style.getBorderRight());
put(properties, BORDER_TOP, style.getBorderTop());
put(properties, BORDER_BOTTOM, style.getBorderBottomEnum());
put(properties, BORDER_LEFT, style.getBorderLeftEnum());
put(properties, BORDER_RIGHT, style.getBorderRightEnum());
put(properties, BORDER_TOP, style.getBorderTopEnum());
put(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor());
put(properties, DATA_FORMAT, style.getDataFormat());
put(properties, FILL_PATTERN, style.getFillPatternEnum());

View File

@ -248,9 +248,10 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* @throws InvalidFormatException
* If the specified file doesn't exist, and a parsing error
* occur.
* @throws InvalidOperationException
*/
public static OPCPackage open(String path, PackageAccess access)
throws InvalidFormatException {
throws InvalidFormatException, InvalidOperationException {
if (path == null || "".equals(path.trim())) {
throw new IllegalArgumentException("'path' must be given");
}
@ -261,8 +262,20 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
}
OPCPackage pack = new ZipPackage(path, access);
boolean success = false;
if (pack.partList == null && access != PackageAccess.WRITE) {
pack.getParts();
try {
pack.getParts();
success = true;
} finally {
if (! success) {
try {
pack.close();
} catch (final IOException e) {
throw new InvalidOperationException("Could not close OPCPackage while cleaning up", e);
}
}
}
}
pack.originalPackagePath = new File(path).getAbsolutePath();
return pack;

View File

@ -19,6 +19,7 @@ package org.apache.poi.openxml4j.opc;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -52,7 +53,10 @@ import org.apache.poi.util.TempFile;
* Physical zip package.
*/
public final class ZipPackage extends OPCPackage {
private static POILogger logger = POILogFactory.getLogger(ZipPackage.class);
private static final String MIMETYPE = "mimetype";
private static final String SETTINGS_XML = "settings.xml";
private static final POILogger logger = POILogFactory.getLogger(ZipPackage.class);
/**
* Zip archive, as either a file on disk,
@ -85,12 +89,22 @@ public final class ZipPackage extends OPCPackage {
* @throws IllegalArgumentException
* If the specified input stream not an instance of
* ZipInputStream.
* @throws IOException
* if input stream cannot be opened, read, or closed
*/
ZipPackage(InputStream in, PackageAccess access) throws IOException {
super(access);
@SuppressWarnings("resource")
ThresholdInputStream zis = ZipHelper.openZipStream(in);
this.zipArchive = new ZipInputStreamZipEntrySource(zis);
try {
this.zipArchive = new ZipInputStreamZipEntrySource(zis);
} catch (final IOException e) {
try {
zis.close();
} catch (final IOException e2) {
throw new IOException("Failed to close zip input stream while cleaning up. " + e.getMessage(), e2);
}
throw new IOException("Failed to read zip entry source", e);
}
}
/**
@ -100,8 +114,9 @@ public final class ZipPackage extends OPCPackage {
* The path of the file to open or create.
* @param access
* The package access mode.
* @throws InvalidOperationException
*/
ZipPackage(String path, PackageAccess access) {
ZipPackage(String path, PackageAccess access) throws InvalidOperationException {
this(new File(path), access);
}
@ -112,9 +127,9 @@ public final class ZipPackage extends OPCPackage {
* The file to open or create.
* @param access
* The package access mode.
* @throws InvalidOperationException
*/
@SuppressWarnings("resource")
ZipPackage(File file, PackageAccess access) {
ZipPackage(File file, PackageAccess access) throws InvalidOperationException {
super(access);
ZipEntrySource ze;
@ -127,36 +142,72 @@ public final class ZipPackage extends OPCPackage {
throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e);
}
logger.log(POILogger.ERROR, "Error in zip file "+file+" - falling back to stream processing (i.e. ignoring zip central directory)");
// some zips can't be opened via ZipFile in JDK6, as the central directory
// contains either non-latin entries or the compression type can't be handled
// the workaround is to iterate over the stream and not the directory
FileInputStream fis = null;
ThresholdInputStream zis = null;
try {
fis = new FileInputStream(file);
zis = ZipHelper.openZipStream(fis);
ze = new ZipInputStreamZipEntrySource(zis);
} catch (IOException e2) {
if (zis != null) {
try {
zis.close();
} catch (IOException e3) {
throw new InvalidOperationException("Can't open the specified file: '" + file + "'"+
" and couldn't close the file input stream", e);
}
} else if (fis != null) {
try {
fis.close();
} catch (IOException e3) {
throw new InvalidOperationException("Can't open the specified file: '" + file + "'"+
" and couldn't close the file input stream", e);
}
}
throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e);
}
ze = openZipEntrySourceStream(file);
}
this.zipArchive = ze;
}
private static ZipEntrySource openZipEntrySourceStream(File file) throws InvalidOperationException {
final FileInputStream fis;
// Acquire a resource that is needed to read the next level of openZipEntrySourceStream
try {
// open the file input stream
fis = new FileInputStream(file);
} catch (final FileNotFoundException e) {
// If the source cannot be acquired, abort (no resources to free at this level)
throw new InvalidOperationException("Can't open the specified file input stream from file: '" + file + "'", e);
}
// If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource
try {
// read from the file input stream
return openZipEntrySourceStream(fis);
} catch (final Exception e) {
try {
// abort: close the file input stream
fis.close();
} catch (final IOException e2) {
throw new InvalidOperationException("Could not close the specified file input stream from file: '" + file + "'", e2);
}
throw new InvalidOperationException("Failed to read the file input stream from file: '" + file + "'", e);
}
}
private static ZipEntrySource openZipEntrySourceStream(FileInputStream fis) throws InvalidOperationException {
final ThresholdInputStream zis;
// Acquire a resource that is needed to read the next level of openZipEntrySourceStream
try {
// open the zip input stream
zis = ZipHelper.openZipStream(fis);
} catch (final IOException e) {
// If the source cannot be acquired, abort (no resources to free at this level)
throw new InvalidOperationException("Could not open the file input stream", e);
}
// If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource
try {
// read from the zip input stream
return openZipEntrySourceStream(zis);
} catch (final Exception e) {
try {
// abort: close the zip input stream
zis.close();
} catch (final IOException e2) {
throw new InvalidOperationException("Failed to read the zip entry source stream and could not close the zip input stream", e2);
}
throw new InvalidOperationException("Failed to read the zip entry source stream", e);
}
}
private static ZipEntrySource openZipEntrySourceStream(ThresholdInputStream zis) throws InvalidOperationException {
// Acquire the final level resource. If this is acquired successfully, the zip package was read successfully from the input stream
try {
// open the zip entry source stream
return new ZipInputStreamZipEntrySource(zis);
} catch (IOException e) {
throw new InvalidOperationException("Could not open the specified zip entry source stream", e);
}
}
/**
* Constructor. Opens a Zip based Open XML document from
@ -206,7 +257,7 @@ public final class ZipPackage extends OPCPackage {
this.contentTypeManager = new ZipContentTypeManager(
getZipArchive().getInputStream(entry), this);
} catch (IOException e) {
throw new InvalidFormatException(e.getMessage());
throw new InvalidFormatException(e.getMessage(), e);
}
break;
}
@ -220,11 +271,12 @@ public final class ZipPackage extends OPCPackage {
boolean hasSettingsXML = false;
entries = this.zipArchive.getEntries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.getName().equals("mimetype")) {
final ZipEntry entry = entries.nextElement();
final String name = entry.getName();
if (MIMETYPE.equals(name)) {
hasMimetype = true;
}
if (entry.getName().equals("settings.xml")) {
if (SETTINGS_XML.equals(name)) {
hasSettingsXML = true;
}
numEntries++;
@ -259,10 +311,10 @@ public final class ZipPackage extends OPCPackage {
String contentType = contentTypeManager.getContentType(partName);
if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
try {
partList.put(partName, new ZipPackagePart(this, entry,
partName, contentType));
PackagePart part = new ZipPackagePart(this, entry, partName, contentType);
partList.put(partName, part);
} catch (InvalidOperationException e) {
throw new InvalidFormatException(e.getMessage());
throw new InvalidFormatException(e.getMessage(), e);
}
}
}
@ -274,17 +326,16 @@ public final class ZipPackage extends OPCPackage {
PackagePartName partName = buildPartName(entry);
if(partName == null) continue;
String contentType = contentTypeManager
.getContentType(partName);
String contentType = contentTypeManager.getContentType(partName);
if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
// Already handled
}
else if (contentType != null) {
try {
partList.put(partName, new ZipPackagePart(this, entry,
partName, contentType));
PackagePart part = new ZipPackagePart(this, entry, partName, contentType);
partList.put(partName, part);
} catch (InvalidOperationException e) {
throw new InvalidFormatException(e.getMessage());
throw new InvalidFormatException(e.getMessage(), e);
}
} else {
throw new InvalidFormatException(
@ -392,20 +443,22 @@ public final class ZipPackage extends OPCPackage {
// Save the final package to a temporary file
try {
save(tempFile);
// Close the current zip file, so we can
// overwrite it on all platforms
this.zipArchive.close();
// Copy the new file over the old one
FileHelper.copyFile(tempFile, targetFile);
} finally {
// Either the save operation succeed or not, we delete the
// temporary file
if (!tempFile.delete()) {
logger
.log(POILogger.WARN,"The temporary file: '"
+ targetFile.getAbsolutePath()
+ "' cannot be deleted ! Make sure that no other application use it.");
try {
// Close the current zip file, so we can
// overwrite it on all platforms
this.zipArchive.close();
// Copy the new file over the old one
FileHelper.copyFile(tempFile, targetFile);
} finally {
// Either the save operation succeed or not, we delete the
// temporary file
if (!tempFile.delete()) {
logger
.log(POILogger.WARN,"The temporary file: '"
+ targetFile.getAbsolutePath()
+ "' cannot be deleted ! Make sure that no other application use it.");
}
}
}
} else {

View File

@ -19,6 +19,7 @@ package org.apache.poi.openxml4j.opc.internal;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
@ -239,10 +240,15 @@ public final class ZipHelper {
* @param file
* The file to open.
* @return The zip archive freshly open.
* @throws IOException if the zip file cannot be opened or closed to read the header signature
* @throws NotOfficeXmlFileException if stream does not start with zip header signature
*/
public static ZipFile openZipFile(File file) throws IOException {
public static ZipFile openZipFile(File file) throws IOException, NotOfficeXmlFileException {
if (!file.exists()) {
return null;
throw new FileNotFoundException("File does not exist");
}
if (file.isDirectory()) {
throw new IOException("File is a directory");
}
// Peek at the first few bytes to sanity check

View File

@ -45,4 +45,9 @@ public interface ZipEntrySource {
* resources may be freed
*/
public void close() throws IOException;
/**
* Has close been called already?
*/
public boolean isClosed();
}

View File

@ -39,6 +39,9 @@ public class ZipFileZipEntrySource implements ZipEntrySource {
}
zipArchive = null;
}
public boolean isClosed() {
return (zipArchive == null);
}
public Enumeration<? extends ZipEntry> getEntries() {
if (zipArchive == null)

View File

@ -76,6 +76,9 @@ public class ZipInputStreamZipEntrySource implements ZipEntrySource {
// Free the memory
zipEntries = null;
}
public boolean isClosed() {
return (zipEntries == null);
}
/**
* Why oh why oh why are Iterator and Enumeration

View File

@ -134,15 +134,15 @@ public class ZipSecureFile extends ZipFile {
return MAX_TEXT_SIZE;
}
public ZipSecureFile(File file, int mode) throws IOException {
public ZipSecureFile(File file, int mode) throws ZipException, IOException {
super(file, mode);
}
public ZipSecureFile(File file) throws IOException {
public ZipSecureFile(File file) throws ZipException, IOException {
super(file);
}
public ZipSecureFile(String name) throws IOException {
public ZipSecureFile(String name) throws ZipException, IOException {
super(name);
}

View File

@ -471,6 +471,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
* @param format The format of the picture
*
* @return the picture data
* @since 3.15 beta 2
*/
@Override
public XSLFPictureData addPicture(InputStream is, PictureType format) throws IOException
@ -486,6 +487,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
* @param format The format of the picture.
*
* @return the picture data
* @since 3.15 beta 2
*/
@Override
public XSLFPictureData addPicture(File pict, PictureType format) throws IOException
@ -507,6 +509,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
*
* @param pictureData The picture data to find in the SlideShow
* @return {@code null} if picture data is not found in this slideshow
* @since 3.15 beta 2
*/
@Override
public XSLFPictureData findPictureData(byte[] pictureData) {

View File

@ -69,6 +69,10 @@ public class XSLFHyperlink implements Hyperlink<XSLFShape,XSLFTextParagraph> {
_link.setTooltip(label);
}
/* (non-Javadoc)
* @deprecated POI 3.15. Use {@link #getTypeEnum()} instead.
* Will return a HyperlinkType enum in the future
*/
@Override
public int getType() {
return getTypeEnum().getCode();

View File

@ -43,6 +43,7 @@ import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.NotImplemented;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.Removal;
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
@ -61,6 +62,8 @@ public class SXSSFCell implements Cell {
* @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Removal(version="3.17")
@Deprecated
public SXSSFCell(SXSSFRow row, int cellType)
{
this(row, CellType.forInt((cellType)));

View File

@ -26,6 +26,7 @@ import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.Removal;
import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
@ -72,6 +73,7 @@ public class SXSSFCreationHelper implements CreationHelper {
* @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead.
*/
@Deprecated
@Removal(version="3.17")
@Override
public Hyperlink createHyperlink(int type) {
return helper.createHyperlink(type);

View File

@ -72,24 +72,9 @@ public final class SXSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
return new SXSSFEvaluationCell((SXSSFCell)cell);
}
/**
* If cell contains formula, it evaluates the formula, and
* puts the formula result back into the cell, in place
* of the old formula.
* Else if cell does not contain formula, this method leaves
* the cell unchanged.
* Note that the same instance of SXSSFCell is returned to
* allow chained calls like:
* <pre>
* int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
* </pre>
* Be aware that your cell value will be changed to hold the
* result of the formula. If you simply want the formula
* value computed for you, use {@link #evaluateFormulaCellEnum(org.apache.poi.ss.usermodel.Cell)} }
*/
@Override
public SXSSFCell evaluateInCell(Cell cell) {
doEvaluateInCell(cell);
return (SXSSFCell)cell;
return (SXSSFCell) super.evaluateInCell(cell);
}
/**

View File

@ -28,7 +28,7 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.util.Internal;
import org.apache.poi.ss.usermodel.RichTextString;
/**
* Internal POI use only - parent of XSSF and SXSSF formula evaluators
@ -37,6 +37,10 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator {
protected BaseXSSFFormulaEvaluator(WorkbookEvaluator bookEvaluator) {
super(bookEvaluator);
}
@Override
protected RichTextString createRichTextString(String str) {
return new XSSFRichTextString(str);
}
public void notifySetFormula(Cell cell) {
_bookEvaluator.notifyUpdateCell(new XSSFEvaluationCell((XSSFCell)cell));
@ -48,78 +52,6 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator {
_bookEvaluator.notifyUpdateCell(new XSSFEvaluationCell((XSSFCell)cell));
}
/**
* If cell contains formula, it evaluates the formula,
* and saves the result of the formula. The cell
* remains as a formula cell.
* Else if cell does not contain formula, this method leaves
* the cell unchanged.
* Note that the type of the formula result is returned,
* so you know what kind of value is also stored with
* the formula.
* <pre>
* CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
* </pre>
* Be aware that your cell will hold both the formula,
* and the result. If you want the cell replaced with
* the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)} }
* @param cell The cell to evaluate
* @return The type of the formula result (the cell's type remains as CellType.FORMULA however)
* If cell is not a formula cell, returns {@link CellType#_NONE} rather than throwing an exception.
* @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
public CellType evaluateFormulaCellEnum(Cell cell) {
if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
return CellType._NONE;
}
CellValue cv = evaluateFormulaCellValue(cell);
// cell remains a formula cell, but the cached value is changed
setCellValue(cell, cv);
return cv.getCellType();
}
/**
* If cell contains formula, it evaluates the formula, and
* puts the formula result back into the cell, in place
* of the old formula.
* Else if cell does not contain formula, this method leaves
* the cell unchanged.
*/
protected void doEvaluateInCell(Cell cell) {
if (cell == null) return;
if (cell.getCellTypeEnum() == CellType.FORMULA) {
CellValue cv = evaluateFormulaCellValue(cell);
setCellType(cell, cv); // cell will no longer be a formula cell
setCellValue(cell, cv);
}
}
private static void setCellValue(Cell cell, CellValue cv) {
CellType cellType = cv.getCellType();
switch (cellType) {
case BOOLEAN:
cell.setCellValue(cv.getBooleanValue());
break;
case ERROR:
cell.setCellErrorValue(cv.getErrorValue());
break;
case NUMERIC:
cell.setCellValue(cv.getNumberValue());
break;
case STRING:
cell.setCellValue(new XSSFRichTextString(cv.getStringValue()));
break;
case BLANK:
// never happens - blanks eventually get translated to zero
case FORMULA:
// this will never happen, we have already evaluated the formula
default:
throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
}
}
/**
* Turns a XSSFCell / SXSSFCell into a XSSFEvaluationCell
*/

View File

@ -35,32 +35,87 @@ public class XSSFBorderFormatting implements BorderFormatting {
_border = border;
}
/**
* @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderBottom() {
public short getBorderBottom() {
return getBorderBottomEnum().getCode();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderBottomEnum() {
STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
/**
* @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderDiagonal() {
public short getBorderDiagonal() {
return getBorderDiagonalEnum().getCode();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderDiagonalEnum() {
STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
/**
* @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderLeft() {
public short getBorderLeft() {
return getBorderLeftEnum().getCode();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderLeftEnum() {
STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
/**
* @deprecated POI 3.15. Use {@link #getBorderRightEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderRight() {
public short getBorderRight() {
return getBorderRightEnum().getCode();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderRightEnum() {
STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
/**
* @deprecated POI 3.15. Use {@link #getBorderTopEnum()}.
* This method will return an BorderStyle enum in the future.
*/
@Override
public BorderStyle getBorderTop() {
public short getBorderTop() {
return getBorderTopEnum().getCode();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderTopEnum() {
STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}

View File

@ -668,6 +668,7 @@ public final class XSSFCell implements Cell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return the cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCellType() {
@ -699,6 +700,7 @@ public final class XSSFCell implements Cell {
* @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING},
* {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending
* on the cached value of the formula
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCachedFormulaResultType() {
@ -714,7 +716,6 @@ public final class XSSFCell implements Cell {
* @deprecated POI 3.15 beta 3
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Override
public CellType getCachedFormulaResultTypeEnum() {
if (! isFormulaCell()) {
@ -826,7 +827,7 @@ public final class XSSFCell implements Cell {
* @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} isn't {@link CellType#ERROR}
* @see FormulaError
*/
public String getErrorCellString() {
public String getErrorCellString() throws IllegalStateException {
CellType cellType = getBaseCellType(true);
if(cellType != CellType.ERROR) throw typeMismatch(CellType.ERROR, cellType, false);
@ -844,13 +845,16 @@ public final class XSSFCell implements Cell {
* @see FormulaError
*/
@Override
public byte getErrorCellValue() {
public byte getErrorCellValue() throws IllegalStateException {
String code = getErrorCellString();
if (code == null) {
return 0;
}
return FormulaError.forString(code).getCode();
try {
return FormulaError.forString(code).getCode();
} catch (final IllegalArgumentException e) {
throw new IllegalStateException("Unexpected error code", e);
}
}
/**

View File

@ -28,6 +28,7 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.ThemesTable;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellAlignment;
@ -251,11 +252,13 @@ public class XSSFCellStyle implements CellStyle {
/**
* Get the type of border to use for the bottom border of the cell
* Will be removed when {@link #getBorderBottom()} returns a BorderStyle enum
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @since POI 3.15
*/
@Override
public BorderStyle getBorderBottom() {
public BorderStyle getBorderBottomEnum() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
@ -266,24 +269,26 @@ public class XSSFCellStyle implements CellStyle {
}
return BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
/**
* Get the type of border to use for the bottom border of the cell
* This will return a BorderStyle enum in the future.
*
* @return border type as Java enum
* @deprecated 3.15 beta 2. Use {@link #getBorderBottom}
* @return border type code
* @deprecated 3.15 beta 2. Use {@link #getBorderBottomEnum()}
*/
public BorderStyle getBorderBottomEnum() {
return getBorderBottom();
public short getBorderBottom() {
return getBorderBottomEnum().getCode();
}
/**
* Get the type of border to use for the left border of the cell
* Will be removed when {@link #getBorderLeft()} returns a BorderStyle enum
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @since POI 3.15
*/
@Override
public BorderStyle getBorderLeft() {
public BorderStyle getBorderLeftEnum() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
@ -297,21 +302,24 @@ public class XSSFCellStyle implements CellStyle {
/**
* Get the type of border to use for the left border of the cell
* This will return a BorderStyle enum in the future.
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @deprecated 3.15 beta 2. Use {@link #getBorderLeft}
* @return border type code
* @deprecated 3.15 beta 2. Use {@link #getBorderLeftEnum()}
*/
public BorderStyle getBorderLeftEnum() {
return getBorderLeft();
public short getBorderLeft() {
return getBorderLeftEnum().getCode();
}
/**
* Get the type of border to use for the right border of the cell
* Will be removed when {@link #getBorderRight()} returns a BorderStyle enum
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @since POI 3.15
*/
@Override
public BorderStyle getBorderRight() {
public BorderStyle getBorderRightEnum() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
@ -322,24 +330,26 @@ public class XSSFCellStyle implements CellStyle {
}
return BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
/**
* Get the type of border to use for the right border of the cell
* This will return a BorderStyle enum in the future.
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @deprecated 3.15 beta 2. Use {@link #getBorderRight}
* @deprecated 3.15 beta 2. Use {@link #getBorderRightEnum()} instead
*/
public BorderStyle getBorderRightEnum() {
return getBorderRight();
public short getBorderRight() {
return getBorderRightEnum().getCode();
}
/**
* Get the type of border to use for the top border of the cell
* Will be removed when {@link #getBorderTop()} returns a BorderStyle enum
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @since POI 3.15
*/
@Override
public BorderStyle getBorderTop() {
public BorderStyle getBorderTopEnum() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
@ -350,15 +360,15 @@ public class XSSFCellStyle implements CellStyle {
}
return BorderStyle.valueOf((short) (ptrn.intValue() - 1));
}
/**
* Get the type of border to use for the top border of the cell
* This will return a BorderStyle enum in the future.
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
* @deprecated 3.15 beta 2. Use {@link #getBorderTop}
* @deprecated 3.15 beta 2. Use {@link #getBorderTopEnum()} instead.
*/
public BorderStyle getBorderTopEnum() {
return getBorderTop();
public short getBorderTop() {
return getBorderTopEnum().getCode();
}
/**
@ -775,6 +785,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_CENTER_SELECTION
* @deprecated POI 3.15 beta 3. Use {@link #setAlignment(HorizontalAlignment)} instead.
*/
@Removal(version="3.17")
@Override
public void setAlignment(short align) {
setAlignment(HorizontalAlignment.forInt(align));
@ -796,6 +807,7 @@ public class XSSFCellStyle implements CellStyle {
* @param border the type of border to use
* @deprecated 3.15 beta 2. Use {@link #setBorderBottom(BorderStyle)}
*/
@Removal(version="3.17")
@Override
public void setBorderBottom(short border) {
setBorderBottom(BorderStyle.valueOf(border));
@ -806,6 +818,7 @@ public class XSSFCellStyle implements CellStyle {
*
* @param border - type of border to use
* @see org.apache.poi.ss.usermodel.BorderStyle
* @since POI 3.15
*/
@Override
public void setBorderBottom(BorderStyle border) {
@ -825,6 +838,7 @@ public class XSSFCellStyle implements CellStyle {
* @param border the type of border to use
* @deprecated 3.15 beta 2. Use {@link #setBorderLeft(BorderStyle)}
*/
@Removal(version="3.17")
@Override
public void setBorderLeft(short border) {
setBorderLeft(BorderStyle.valueOf(border));
@ -834,6 +848,7 @@ public class XSSFCellStyle implements CellStyle {
* Set the type of border to use for the left border of the cell
*
* @param border the type of border to use
* @since POI 3.15
*/
@Override
public void setBorderLeft(BorderStyle border) {
@ -854,6 +869,7 @@ public class XSSFCellStyle implements CellStyle {
* @param border the type of border to use
* @deprecated 3.15 beta 2. Use {@link #setBorderRight(BorderStyle)}
*/
@Removal(version="3.17")
@Override
public void setBorderRight(short border) {
setBorderRight(BorderStyle.valueOf(border));
@ -863,6 +879,7 @@ public class XSSFCellStyle implements CellStyle {
* Set the type of border to use for the right border of the cell
*
* @param border the type of border to use
* @since POI 3.15
*/
@Override
public void setBorderRight(BorderStyle border) {
@ -883,6 +900,7 @@ public class XSSFCellStyle implements CellStyle {
* @param border the type of border to use
* @deprecated 3.15 beta 2. Use {@link #setBorderTop(BorderStyle)}
*/
@Removal(version="3.17")
@Override
public void setBorderTop(short border) {
setBorderTop(BorderStyle.valueOf(border));
@ -892,6 +910,7 @@ public class XSSFCellStyle implements CellStyle {
* Set the type of border to use for the top border of the cell
*
* @param border the type of border to use
* @since POI 3.15
*/
@Override
public void setBorderTop(BorderStyle border) {
@ -1121,7 +1140,9 @@ public class XSSFCellStyle implements CellStyle {
* @see #setFillBackgroundColor(short)
* @see #setFillForegroundColor(short)
* @param fp fill pattern (set to {@link org.apache.poi.ss.usermodel.CellStyle#SOLID_FOREGROUND} to fill w/foreground color)
* @deprecated POI 3.15. Use {@link #setFillPattern(FillPatternType)} instead.
*/
@Removal(version="3.17")
@Override
public void setFillPattern(short fp) {
setFillPattern(FillPatternType.forInt(fp));
@ -1335,6 +1356,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.VerticalAlignment
* @deprecated POI 3.15 beta 3. Use {@link #setVerticalAlignment(VerticalAlignment)} instead.
*/
@Removal(version="3.17")
@Override
public void setVerticalAlignment(short align) {
setVerticalAlignment(VerticalAlignment.forInt(align));

View File

@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
/**
@ -218,15 +219,28 @@ public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
/**
* Sets the anchor type
* @param anchorType the anchor type to set
* @since POI 3.14
*/
@Override
public void setAnchorType( AnchorType anchorType )
{
this.anchorType = anchorType;
}
/**
* Sets the anchor type
* @param anchorType the anchor type to set
* @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead
*/
@Removal(version="3.17")
@Override
public void setAnchorType( int anchorType )
{
this.anchorType = AnchorType.byId(anchorType);
}
/**
* Gets the anchor type
* Changed from returning an int to an enum in POI 3.14 beta 1.
* @return the anchor type
*/
@Override

View File

@ -20,6 +20,7 @@ import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
public class XSSFCreationHelper implements CreationHelper {
private final XSSFWorkbook workbook;
@ -61,6 +62,7 @@ public class XSSFCreationHelper implements CreationHelper {
* @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead.
*/
@Deprecated
@Removal(version="3.17")
@Override
public XSSFHyperlink createHyperlink(int type) {
return new XSSFHyperlink(type);

View File

@ -58,6 +58,7 @@ final class XSSFEvaluationCell implements EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCellType() {
@ -68,7 +69,6 @@ final class XSSFEvaluationCell implements EvaluationCell {
* @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Override
public CellType getCellTypeEnum() {
return _cell.getCellTypeEnum();

View File

@ -23,6 +23,8 @@ import org.apache.poi.ss.formula.IStabilityClassifier;
import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
/**
* Evaluates formula cells.<p/>
@ -55,27 +57,6 @@ public final class XSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
return new XSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder);
}
/**
* If cell contains formula, it evaluates the formula, and
* puts the formula result back into the cell, in place
* of the old formula.
* Else if cell does not contain formula, this method leaves
* the cell unchanged.
* Note that the same instance of XSSFCell is returned to
* allow chained calls like:
* <pre>
* int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
* </pre>
* Be aware that your cell value will be changed to hold the
* result of the formula. If you simply want the formula
* value computed for you, use {@link #evaluateFormulaCellEnum(org.apache.poi.ss.usermodel.Cell)} }
* @param cell
*/
public XSSFCell evaluateInCell(Cell cell) {
doEvaluateInCell(cell);
return (XSSFCell)cell;
}
/**
* Loops over all cells in all sheets of the supplied
* workbook.
@ -90,6 +71,12 @@ public final class XSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
public static void evaluateAllFormulaCells(XSSFWorkbook wb) {
BaseFormulaEvaluator.evaluateAllFormulaCells(wb);
}
@Override
public XSSFCell evaluateInCell(Cell cell) {
return (XSSFCell) super.evaluateInCell(cell);
}
/**
* Loops over all cells in all sheets of the supplied
* workbook.

View File

@ -168,6 +168,7 @@ public class XSSFHyperlink implements Hyperlink {
* @return the type of this hyperlink
* @see HyperlinkType#forInt
* @deprecated POI 3.15 beta 3. Use {@link #getTypeEnum()} instead.
* getType will return a HyperlinkType enum in the future.
*/
@Override
public int getType() {

View File

@ -30,6 +30,7 @@ import javax.xml.namespace.QName;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataConsolidateFunction;
@ -213,24 +214,43 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
}
protected AreaReference getPivotArea() {
AreaReference pivotArea = new AreaReference(getPivotCacheDefinition().
getCTPivotCacheDefinition().getCacheSource().getWorksheetSource().getRef());
AreaReference pivotArea = new AreaReference(
getPivotCacheDefinition()
.getCTPivotCacheDefinition()
.getCacheSource()
.getWorksheetSource()
.getRef(),
SpreadsheetVersion.EXCEL2007);
return pivotArea;
}
/**
* Verify column index (relative to first column in pivot area) is within the
* pivot area
*
* @param columnIndex
* @throws IndexOutOfBoundsException
*/
private void checkColumnIndex(int columnIndex) throws IndexOutOfBoundsException {
AreaReference pivotArea = getPivotArea();
int size = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol() + 1;
if (columnIndex < 0 || columnIndex >= size) {
throw new IndexOutOfBoundsException("Column Index: " + columnIndex + ", Size: " + size);
}
}
/**
* Add a row label using data from the given column.
* @param columnIndex the index of the column to be used as row label.
* @param columnIndex the index of the source column to be used as row label.
* {@code columnIndex} is 0-based indexed and relative to the first column in the source.
*/
@Beta
public void addRowLabel(int columnIndex) {
checkColumnIndex(columnIndex);
AreaReference pivotArea = getPivotArea();
int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
if(columnIndex > lastColIndex) {
throw new IndexOutOfBoundsException();
}
final int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
CTPivotField pivotField = CTPivotField.Factory.newInstance();
@ -238,7 +258,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
pivotField.setAxis(STAxis.AXIS_ROW);
pivotField.setShowAll(false);
for(int i = 0; i <= lastRowIndex; i++) {
for (int i = 0; i <= lastRowIndex; i++) {
items.addNewItem().setT(STItemType.DEFAULT);
}
items.setCount(items.sizeOfItemArray());
@ -270,7 +290,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
/**
* Add a column label using data from the given column and specified function
* @param columnIndex the index of the column to be used as column label.
* @param columnIndex the index of the source column to be used as column label.
* {@code columnIndex} is 0-based indexed and relative to the first column in the source.
* @param function the function to be used on the data
* The following functions exists:
* Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
@ -278,12 +299,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
*/
@Beta
public void addColumnLabel(DataConsolidateFunction function, int columnIndex, String valueFieldName) {
AreaReference pivotArea = getPivotArea();
int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
if(columnIndex > lastColIndex && columnIndex < 0) {
throw new IndexOutOfBoundsException();
}
checkColumnIndex(columnIndex);
addDataColumn(columnIndex, true);
addDataField(function, columnIndex, valueFieldName);
@ -303,7 +319,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
/**
* Add a column label using data from the given column and specified function
* @param columnIndex the index of the column to be used as column label.
* @param columnIndex the index of the source column to be used as column label
* {@code columnIndex} is 0-based indexed and relative to the first column in the source..
* @param function the function to be used on the data
* The following functions exists:
* Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
@ -323,12 +340,10 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
*/
@Beta
private void addDataField(DataConsolidateFunction function, int columnIndex, String valueFieldName) {
checkColumnIndex(columnIndex);
AreaReference pivotArea = getPivotArea();
int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
if(columnIndex > lastColIndex && columnIndex < 0) {
throw new IndexOutOfBoundsException();
}
CTDataFields dataFields;
if(pivotTableDefinition.getDataFields() != null) {
dataFields = pivotTableDefinition.getDataFields();
@ -352,11 +367,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
*/
@Beta
public void addDataColumn(int columnIndex, boolean isDataField) {
AreaReference pivotArea = getPivotArea();
int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
if(columnIndex > lastColIndex && columnIndex < 0) {
throw new IndexOutOfBoundsException();
}
checkColumnIndex(columnIndex);
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
CTPivotField pivotField = CTPivotField.Factory.newInstance();
@ -371,13 +383,11 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
*/
@Beta
public void addReportFilter(int columnIndex) {
checkColumnIndex(columnIndex);
AreaReference pivotArea = getPivotArea();
int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
if(columnIndex > lastColIndex && columnIndex < 0) {
throw new IndexOutOfBoundsException();
}
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
CTPivotField pivotField = CTPivotField.Factory.newInstance();

View File

@ -4165,9 +4165,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* @return The pivot table
*/
@Beta
public XSSFPivotTable createPivotTable(AreaReference source, CellReference position, Sheet sourceSheet){
if(source.getFirstCell().getSheetName() != null && !source.getFirstCell().getSheetName().equals(sourceSheet.getSheetName())) {
public XSSFPivotTable createPivotTable(AreaReference source, CellReference position, Sheet sourceSheet) {
final String sourceSheetName = source.getFirstCell().getSheetName();
if(sourceSheetName != null && !sourceSheetName.equalsIgnoreCase(sourceSheet.getSheetName())) {
throw new IllegalArgumentException("The area is referenced in another sheet than the "
+ "defined source sheet " + sourceSheet.getSheetName() + ".");
}
@ -4193,8 +4193,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/
@Beta
public XSSFPivotTable createPivotTable(AreaReference source, CellReference position){
if(source.getFirstCell().getSheetName() != null && !source.getFirstCell().getSheetName().equals(this.getSheetName())) {
return createPivotTable(source, position, getWorkbook().getSheet(source.getFirstCell().getSheetName()));
final String sourceSheetName = source.getFirstCell().getSheetName();
if(sourceSheetName != null && !sourceSheetName.equalsIgnoreCase(this.getSheetName())) {
final XSSFSheet sourceSheet = getWorkbook().getSheet(sourceSheetName);
return createPivotTable(source, position, sourceSheet);
}
return createPivotTable(source, position, this);
}

View File

@ -682,9 +682,12 @@ public class TestExtractorFactory {
// Text
try {
ExtractorFactory.createExtractor(OPCPackage.open(txt.toString()));
fail();
fail("TestExtractorFactory.testPackage() failed on " + txt.toString());
} catch(UnsupportedFileFormatException e) {
// Good
} catch (Exception e) {
System.out.println("TestExtractorFactory.testPackage() failed on " + txt.toString());
throw e;
}
}
@ -942,6 +945,7 @@ public class TestExtractorFactory {
"openxml4j/OPCCompliance_CoreProperties_OnlyOneCorePropertiesPartFAIL.docx",
"openxml4j/OPCCompliance_CoreProperties_UnauthorizedXMLLangAttributeFAIL.docx",
"openxml4j/OPCCompliance_DerivedPartNameFAIL.docx",
"openxml4j/invalid.xlsx",
"spreadsheet/54764-2.xlsx", // see TestXSSFBugs.bug54764()
"spreadsheet/54764.xlsx", // see TestXSSFBugs.bug54764()
"spreadsheet/Simple.xlsb",

View File

@ -943,4 +943,22 @@ public final class TestPackage {
ZipSecureFile.setMaxTextSize(before);
}
}
// bug 60128
@Test
public void testCorruptFile() throws IOException {
OPCPackage pkg = null;
File file = OpenXML4JTestDataSamples.getSampleFile("invalid.xlsx");
try {
pkg = OPCPackage.open(file, PackageAccess.READ);
} catch (Exception e) {
System.out.println(e.getClass().getName());
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
if (pkg != null) {
pkg.close();
}
}
}
}

View File

@ -33,11 +33,14 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POITextExtractor;
import org.apache.poi.POIXMLException;
import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
import org.apache.poi.openxml4j.exceptions.ODFNotOfficeXmlFileException;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.ss.usermodel.Workbook;
@ -181,6 +184,7 @@ public class TestZipPackage {
public void testClosingStreamOnException() throws IOException {
InputStream is = OpenXML4JTestDataSamples.openSampleStream("dcterms_bug_56479.zip");
File tmp = File.createTempFile("poi-test-truncated-zip", "");
// create a corrupted zip file by truncating a valid zip file to the first 100 bytes
OutputStream os = new FileOutputStream(tmp);
for (int i = 0; i < 100; i++) {
os.write(is.read());
@ -189,11 +193,63 @@ public class TestZipPackage {
os.close();
is.close();
// feed the corrupted zip file to OPCPackage
try {
OPCPackage.open(tmp, PackageAccess.READ);
} catch (Exception e) {
// expected: the zip file is invalid
// this test does not care if open() throws an exception or not.
}
// If the stream is not closed on exception, it will keep a file descriptor to tmp,
// and requests to the OS to delete the file will fail.
assertTrue("Can't delete tmp file", tmp.delete());
}
/**
* If ZipPackage is passed an invalid file, a call to close
* (eg from the OPCPackage open method) should tidy up the
* stream / file the broken file is being read from.
* See bug #60128 for more
*/
@Test
public void testTidyStreamOnInvalidFile() throws Exception {
// Spreadsheet has a good mix of alternate file types
POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
File[] notValidF = new File[] {
files.getFile("SampleSS.ods"), files.getFile("SampleSS.txt")
};
InputStream[] notValidS = new InputStream[] {
files.openResourceAsStream("SampleSS.ods"), files.openResourceAsStream("SampleSS.txt")
};
for (File notValid : notValidF) {
ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ);
assertNotNull(pkg.getZipArchive());
assertFalse(pkg.getZipArchive().isClosed());
try {
pkg.getParts();
fail("Shouldn't work");
} catch (ODFNotOfficeXmlFileException e) {
} catch (NotOfficeXmlFileException ne) {}
pkg.close();
assertNotNull(pkg.getZipArchive());
assertTrue(pkg.getZipArchive().isClosed());
}
for (InputStream notValid : notValidS) {
ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ);
assertNotNull(pkg.getZipArchive());
assertFalse(pkg.getZipArchive().isClosed());
try {
pkg.getParts();
fail("Shouldn't work");
} catch (ODFNotOfficeXmlFileException e) {
} catch (NotOfficeXmlFileException ne) {}
pkg.close();
assertNotNull(pkg.getZipArchive());
assertTrue(pkg.getZipArchive().isClosed());
}
}
}

View File

@ -149,10 +149,12 @@ public class TestSecureTempZip {
static class AesZipFileZipEntrySource implements ZipEntrySource {
final ZipFile zipFile;
final Cipher ci;
boolean closed;
AesZipFileZipEntrySource(ZipFile zipFile, Cipher ci) {
this.zipFile = zipFile;
this.ci = ci;
this.closed = false;
}
/**
@ -172,6 +174,12 @@ public class TestSecureTempZip {
@Override
public void close() throws IOException {
zipFile.close();
closed = true;
}
@Override
public boolean isClosed() {
return closed;
}
}
}

View File

@ -110,7 +110,7 @@ public class TestStructuredReferences {
private static void confirm(FormulaEvaluator fe, Cell cell, double expectedResult) {
fe.clearAllCachedResultValues();
CellValue cv = fe.evaluate(cell);
if (cv.getCellType() != CellType.NUMERIC) {
if (cv.getCellTypeEnum() != CellType.NUMERIC) {
fail("expected numeric cell type but got " + cv.formatAsString());
}
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
@ -119,7 +119,7 @@ public class TestStructuredReferences {
private static void confirm(FormulaEvaluator fe, Cell cell, String expectedResult) {
fe.clearAllCachedResultValues();
CellValue cv = fe.evaluate(cell);
if (cv.getCellType() != CellType.STRING) {
if (cv.getCellTypeEnum() != CellType.STRING) {
fail("expected String cell type but got " + cv.formatAsString());
}
assertEquals(expectedResult, cv.getStringValue());

View File

@ -96,7 +96,7 @@ public final class TestProper {
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
if (cv.getCellType() != CellType.STRING) {
if (cv.getCellTypeEnum() != CellType.STRING) {
throw new AssertionFailedError("Wrong result type: " + cv.formatAsString());
}
String actualValue = cv.getStringValue();

View File

@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@ -35,6 +36,8 @@ import java.util.Arrays;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.ss.usermodel.BaseTestXWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
@ -536,4 +539,40 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
swb.dispose();
swb.close();
}
/**
* To avoid accident changes to the template, you should be able
* to create a SXSSFWorkbook from a read-only XSSF one, then
* change + save that (only). See bug #60010
* TODO Fix this to work!
*/
@Test
@Ignore
public void createFromReadOnlyWorkbook() throws Exception {
File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ);
XSSFWorkbook xssf = new XSSFWorkbook(pkg);
SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2);
String sheetName = "Test SXSSF";
Sheet s = wb.createSheet(sheetName);
for (int i=0; i<10; i++) {
Row r = s.createRow(i);
r.createCell(0).setCellValue(true);
r.createCell(1).setCellValue(2.4);
r.createCell(2).setCellValue("Test Row " + i);
}
assertEquals(10, s.getLastRowNum());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
wb.write(bos);
wb.dispose();
wb.close();
xssf = new XSSFWorkbook(new ByteArrayInputStream(bos.toByteArray()));
s = xssf.getSheet(sheetName);
assertEquals(10, s.getLastRowNum());
assertEquals(true, s.getRow(0).getCell(0).getBooleanCellValue());
assertEquals("Test Row 9", s.getRow(9).getCell(2).getStringCellValue());
}
}

View File

@ -59,7 +59,7 @@ import org.junit.runners.Suite;
TestXSSFSheetComments.class,
TestColumnHelper.class,
TestHeaderFooterHelper.class,
TestXSSFPivotTable.class,
//TestXSSFPivotTable.class, //converted to junit4
TestForkedEvaluator.class
})
public final class AllXSSFUsermodelTests {

View File

@ -205,14 +205,14 @@ public final class TestFormulaEvaluatorOnXSSF {
final CellType expectedCellType = expValue.getCellTypeEnum();
switch (expectedCellType) {
case BLANK:
assertEquals(msg, CellType.BLANK, actValue.getCellType());
assertEquals(msg, CellType.BLANK, actValue.getCellTypeEnum());
break;
case BOOLEAN:
assertEquals(msg, CellType.BOOLEAN, actValue.getCellType());
assertEquals(msg, CellType.BOOLEAN, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue());
break;
case ERROR:
assertEquals(msg, CellType.ERROR, actValue.getCellType());
assertEquals(msg, CellType.ERROR, actValue.getCellTypeEnum());
// if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values
// assertEquals(msg, expValue.getErrorCellValue(), actValue.getErrorValue());
// }
@ -220,14 +220,14 @@ public final class TestFormulaEvaluatorOnXSSF {
case FORMULA: // will never be used, since we will call method after formula evaluation
fail("Cannot expect formula as result of formula evaluation: " + msg);
case NUMERIC:
assertEquals(msg, CellType.NUMERIC, actValue.getCellType());
assertEquals(msg, CellType.NUMERIC, actValue.getCellTypeEnum());
TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
// double delta = Math.abs(expValue.getNumericCellValue()-actValue.getNumberValue());
// double pctExpValue = Math.abs(0.00001*expValue.getNumericCellValue());
// assertTrue(msg, delta <= pctExpValue);
break;
case STRING:
assertEquals(msg, CellType.STRING, actValue.getCellType());
assertEquals(msg, CellType.STRING, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue());
break;
default:

View File

@ -188,14 +188,14 @@ public final class TestMultiSheetFormulaEvaluatorOnXSSF {
final CellType expectedCellType = expValue.getCellTypeEnum();
switch (expectedCellType) {
case BLANK:
assertEquals(msg, CellType.BLANK, actValue.getCellType());
assertEquals(msg, CellType.BLANK, actValue.getCellTypeEnum());
break;
case BOOLEAN:
assertEquals(msg, CellType.BOOLEAN, actValue.getCellType());
assertEquals(msg, CellType.BOOLEAN, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue());
break;
case ERROR:
assertEquals(msg, CellType.ERROR, actValue.getCellType());
assertEquals(msg, CellType.ERROR, actValue.getCellTypeEnum());
// if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values
// assertEquals(msg, expected.getErrorCellValue(), actual.getErrorValue());
// }
@ -203,14 +203,14 @@ public final class TestMultiSheetFormulaEvaluatorOnXSSF {
case FORMULA: // will never be used, since we will call method after formula evaluation
fail("Cannot expect formula as result of formula evaluation: " + msg);
case NUMERIC:
assertEquals(msg, CellType.NUMERIC, actValue.getCellType());
assertEquals(msg, CellType.NUMERIC, actValue.getCellTypeEnum());
TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
// double delta = Math.abs(expected.getNumericCellValue()-actual.getNumberValue());
// double pctExpected = Math.abs(0.00001*expected.getNumericCellValue());
// assertTrue(msg, delta <= pctExpected);
break;
case STRING:
assertEquals(msg, CellType.STRING, actValue.getCellType());
assertEquals(msg, CellType.STRING, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue());
break;
default:

View File

@ -304,7 +304,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
if(c.getCellTypeEnum() == CellType.FORMULA) {
CellValue cv = eval.evaluate(c);
if(cv.getCellType() == CellType.NUMERIC) {
if(cv.getCellTypeEnum() == CellType.NUMERIC) {
// assert that the calculated value agrees with
// the cached formula result calculated by Excel
String formula = c.getCellFormula();
@ -2187,7 +2187,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals("E4+E5", cell.getCellFormula());
CellValue value = evaluator.evaluate(cell);
assertEquals(CellType.ERROR, value.getCellType());
assertEquals(CellType.ERROR, value.getCellTypeEnum());
assertEquals(-60, value.getErrorValue());
assertEquals("~CIRCULAR~REF~", FormulaError.forInt(value.getErrorValue()).getString());
assertEquals("CIRCULAR_REF", FormulaError.forInt(value.getErrorValue()).toString());

View File

@ -104,11 +104,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderBottom() {
//default values
assertEquals(BorderStyle.NONE, cellStyle.getBorderBottom());
assertEquals(BorderStyle.NONE, cellStyle.getBorderBottomEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderBottom(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom());
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottomEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@ -122,7 +122,7 @@ public class TestXSSFCellStyle {
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderBottom(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom());
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottomEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
@ -139,11 +139,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderRight() {
//default values
assertEquals(BorderStyle.NONE, cellStyle.getBorderRight());
assertEquals(BorderStyle.NONE, cellStyle.getBorderRightEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderRight(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight());
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRightEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@ -157,7 +157,7 @@ public class TestXSSFCellStyle {
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderRight(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight());
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRightEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
@ -174,11 +174,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderLeft() {
//default values
assertEquals(BorderStyle.NONE, cellStyle.getBorderLeft());
assertEquals(BorderStyle.NONE, cellStyle.getBorderLeftEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderLeft(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft());
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeftEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@ -192,7 +192,7 @@ public class TestXSSFCellStyle {
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderLeft(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft());
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeftEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
@ -209,11 +209,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderTop() {
//default values
assertEquals(BorderStyle.NONE, cellStyle.getBorderTop());
assertEquals(BorderStyle.NONE, cellStyle.getBorderTopEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderTop(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop());
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTopEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@ -227,7 +227,7 @@ public class TestXSSFCellStyle {
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderTop(BorderStyle.MEDIUM);
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop());
assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTopEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
@ -243,7 +243,7 @@ public class TestXSSFCellStyle {
private void testGetSetBorderXMLBean(BorderStyle border, STBorderStyle.Enum expected) {
cellStyle.setBorderTop(border);
assertEquals(border, cellStyle.getBorderTop());
assertEquals(border, cellStyle.getBorderTopEnum());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
@ -256,7 +256,7 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderNone() {
cellStyle.setBorderTop(BorderStyle.NONE);
assertEquals(BorderStyle.NONE, cellStyle.getBorderTop());
assertEquals(BorderStyle.NONE, cellStyle.getBorderTopEnum());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
@ -562,10 +562,10 @@ public class TestXSSFCellStyle {
assertEquals(style2.getRightBorderColor(), style1.getRightBorderColor());
assertEquals(style2.getBottomBorderColor(), style1.getBottomBorderColor());
assertEquals(style2.getBorderBottom(), style1.getBorderBottom());
assertEquals(style2.getBorderLeft(), style1.getBorderLeft());
assertEquals(style2.getBorderRight(), style1.getBorderRight());
assertEquals(style2.getBorderTop(), style1.getBorderTop());
assertEquals(style2.getBorderBottomEnum(), style1.getBorderBottomEnum());
assertEquals(style2.getBorderLeftEnum(), style1.getBorderLeftEnum());
assertEquals(style2.getBorderRightEnum(), style1.getBorderRightEnum());
assertEquals(style2.getBorderTopEnum(), style1.getBorderTopEnum());
wb2.close();
}
@ -999,7 +999,7 @@ public class TestXSSFCellStyle {
Workbook copy = XSSFTestDataSamples.writeOutAndReadBack(target);
// previously this failed because the border-element was not copied over
copy.getCellStyleAt((short)1).getBorderBottom();
copy.getCellStyleAt((short)1).getBorderBottomEnum();
copy.close();

View File

@ -682,4 +682,15 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
value = evaluator.evaluate(cell);
assertEquals(1, value.getNumberValue(), 0.001);
}
@Test
public void evaluateInCellReturnsSameDataType() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
wb.createSheet().createRow(0).createCell(0);
XSSFFormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
XSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
XSSFCell same = evaluator.evaluateInCell(cell);
assertSame(cell, same);
wb.close();
}
}

View File

@ -16,30 +16,39 @@
==================================================================== */
package org.apache.poi.xssf.usermodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataConsolidateFunction;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageField;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageFields;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotTableDefinition;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataConsolidateFunction;
import junit.framework.TestCase;
public class TestXSSFPivotTable extends TestCase {
public class TestXSSFPivotTable {
private static final XSSFITestDataProvider _testDataProvider = XSSFITestDataProvider.instance;
private XSSFWorkbook wb;
private XSSFPivotTable pivotTable;
private XSSFPivotTable offsetPivotTable;
private Cell offsetOuterCell;
@Override
@Before
public void setUp(){
Workbook wb = new XSSFWorkbook();
XSSFSheet sheet = (XSSFSheet) wb.createSheet();
wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
Row row1 = sheet.createRow(0);
// Create a cell and put a value in it.
@ -72,10 +81,10 @@ public class TestXSSFPivotTable extends TestCase {
Cell cell12 = row1.createCell(3);
cell12.setCellValue(12.12);
AreaReference source = new AreaReference("A1:C2");
AreaReference source = new AreaReference("A1:C2", _testDataProvider.getSpreadsheetVersion());
pivotTable = sheet.createPivotTable(source, new CellReference("H5"));
XSSFSheet offsetSheet = (XSSFSheet) wb.createSheet();
XSSFSheet offsetSheet = wb.createSheet();
Row tableRow_1 = offsetSheet.createRow(1);
offsetOuterCell = tableRow_1.createCell(1);
@ -114,11 +123,19 @@ public class TestXSSFPivotTable extends TestCase {
AreaReference offsetSource = new AreaReference(new CellReference("C2"), new CellReference("E4"));
offsetPivotTable = offsetSheet.createPivotTable(offsetSource, new CellReference("C6"));
}
@After
public void tearDown() throws IOException {
XSSFWorkbook wb2 = _testDataProvider.writeOutAndReadBack(wb);
wb.close();
wb2.close();
}
/**
* Verify that when creating a row label it's created on the correct row
* and the count is increased by one.
*/
@Test
public void testAddRowLabelToPivotTable() {
int columnIndex = 0;
@ -141,6 +158,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's not possible to create a row label outside of the referenced area.
*/
@Test
public void testAddRowLabelOutOfRangeThrowsException() {
int columnIndex = 5;
@ -155,6 +173,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that when creating one column label, no col fields are being created.
*/
@Test
public void testAddOneColumnLabelToPivotTableDoesNotCreateColField() {
int columnIndex = 0;
@ -167,6 +186,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's possible to create three column labels with different DataConsolidateFunction
*/
@Test
public void testAddThreeDifferentColumnLabelsToPivotTable() {
int columnOne = 0;
int columnTwo = 1;
@ -184,6 +204,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's possible to create three column labels with the same DataConsolidateFunction
*/
@Test
public void testAddThreeSametColumnLabelsToPivotTable() {
int columnOne = 0;
int columnTwo = 1;
@ -200,6 +221,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that when creating two column labels, a col field is being created and X is set to -2.
*/
@Test
public void testAddTwoColumnLabelsToPivotTable() {
int columnOne = 0;
int columnTwo = 1;
@ -214,6 +236,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that a data field is created when creating a data column
*/
@Test
public void testColumnLabelCreatesDataField() {
int columnIndex = 0;
@ -229,6 +252,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's possible to set a custom name when creating a data column
*/
@Test
public void testColumnLabelSetCustomName() {
int columnIndex = 0;
@ -245,6 +269,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's not possible to create a column label outside of the referenced area.
*/
@Test
public void testAddColumnLabelOutOfRangeThrowsException() {
int columnIndex = 5;
@ -260,6 +285,7 @@ public class TestXSSFPivotTable extends TestCase {
* Verify when creating a data column set to a data field, the data field with the corresponding
* column index will be set to true.
*/
@Test
public void testAddDataColumn() {
int columnIndex = 0;
boolean isDataField = true;
@ -272,6 +298,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's not possible to create a data column outside of the referenced area.
*/
@Test
public void testAddDataColumnOutOfRangeThrowsException() {
int columnIndex = 5;
boolean isDataField = true;
@ -301,6 +328,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's not possible to create a new filter outside of the referenced area.
*/
@Test
public void testAddReportFilterOutOfRangeThrowsException() {
int columnIndex = 5;
try {
@ -315,10 +343,28 @@ public class TestXSSFPivotTable extends TestCase {
* Verify that the Pivot Table operates only within the referenced area, even when the
* first column of the referenced area is not index 0.
*/
@Test
public void testAddDataColumnWithOffsetData() {
offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
assertEquals(CellType.NUMERIC, offsetOuterCell.getCellTypeEnum());
offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 0);
}
@Test
public void testPivotTableSheetNamesAreCaseInsensitive() {
wb.setSheetName(0, "original");
wb.setSheetName(1, "offset");
XSSFSheet original = wb.getSheet("OriginaL");
XSSFSheet offset = wb.getSheet("OffseT");
// assume sheets are accessible via case-insensitive name
assertNotNull(original);
assertNotNull(offset);
AreaReference source = new AreaReference("ORIGinal!A1:C2", _testDataProvider.getSpreadsheetVersion());
// create a pivot table on the same sheet, case insensitive
original.createPivotTable(source, new CellReference("W1"));
// create a pivot table on a different sheet, case insensitive
offset.createPivotTable(source, new CellReference("W1"));
}
}

View File

@ -804,6 +804,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
* @param format The format of the picture.
*
* @return the picture data.
* @since 3.15 beta 2
*/
@Override
public HSLFPictureData addPicture(InputStream is, PictureType format) throws IOException {
@ -822,6 +823,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
* The format of the picture.
*
* @return the picture data.
* @since 3.15 beta 2
*/
@Override
public HSLFPictureData addPicture(File pict, PictureType format) throws IOException {
@ -844,6 +846,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
*
* @param pictureData The picture data to find in the SlideShow
* @return {@code null} if picture data is not found in this slideshow
* @since 3.15 beta 3
*/
@Override
public HSLFPictureData findPictureData(byte[] pictureData) {

View File

@ -193,10 +193,10 @@ public class ExcelToFoConverter extends AbstractExcelConverter
protected boolean isEmptyStyle( CellStyle cellStyle ) {
return cellStyle == null || (
cellStyle.getFillPattern() == 0
&& cellStyle.getBorderTop() == BorderStyle.NONE
&& cellStyle.getBorderRight() == BorderStyle.NONE
&& cellStyle.getBorderBottom() == BorderStyle.NONE
&& cellStyle.getBorderLeft() == BorderStyle.NONE
&& cellStyle.getBorderTopEnum() == BorderStyle.NONE
&& cellStyle.getBorderRightEnum() == BorderStyle.NONE
&& cellStyle.getBorderBottomEnum() == BorderStyle.NONE
&& cellStyle.getBorderLeftEnum() == BorderStyle.NONE
);
}
@ -361,13 +361,13 @@ public class ExcelToFoConverter extends AbstractExcelConverter
}
processCellStyleBorder( workbook, cellTarget, "top",
cellStyle.getBorderTop(), cellStyle.getTopBorderColor() );
cellStyle.getBorderTopEnum(), cellStyle.getTopBorderColor() );
processCellStyleBorder( workbook, cellTarget, "right",
cellStyle.getBorderRight(), cellStyle.getRightBorderColor() );
cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor() );
processCellStyleBorder( workbook, cellTarget, "bottom",
cellStyle.getBorderBottom(), cellStyle.getBottomBorderColor() );
cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor() );
processCellStyleBorder( workbook, cellTarget, "left",
cellStyle.getBorderLeft(), cellStyle.getLeftBorderColor() );
cellStyle.getBorderLeftEnum(), cellStyle.getLeftBorderColor() );
HSSFFont font = cellStyle.getFont( workbook );
processCellStyleFont( workbook, blockTarget, font );

View File

@ -175,13 +175,13 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
break;
}
buildStyle_border( workbook, style, "top", cellStyle.getBorderTop(),
buildStyle_border( workbook, style, "top", cellStyle.getBorderTopEnum(),
cellStyle.getTopBorderColor() );
buildStyle_border( workbook, style, "right",
cellStyle.getBorderRight(), cellStyle.getRightBorderColor() );
cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor() );
buildStyle_border( workbook, style, "bottom",
cellStyle.getBorderBottom(), cellStyle.getBottomBorderColor() );
buildStyle_border( workbook, style, "left", cellStyle.getBorderLeft(),
cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor() );
buildStyle_border( workbook, style, "left", cellStyle.getBorderLeftEnum(),
cellStyle.getLeftBorderColor() );
HSSFFont font = cellStyle.getFont( workbook );

View File

@ -99,7 +99,7 @@ public final class TestFormulaParserEval extends TestCase {
}
throw e;
}
assertEquals(CellType.NUMERIC, result.getCellType());
assertEquals(CellType.NUMERIC, result.getCellTypeEnum());
assertEquals(42.0, result.getNumberValue(), 0.0);
}
}

View File

@ -228,7 +228,7 @@ public final class TestSharedFormulaRecord extends TestCase {
private static void confirmCellEvaluation(HSSFWorkbook wb, HSSFCell cell, double expectedValue) {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue cv = fe.evaluate(cell);
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(expectedValue, cv.getNumberValue(), 0.0);
}

View File

@ -2567,7 +2567,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(0);
HSSFCellStyle rstyle = row.getRowStyle();
assertEquals(BorderStyle.DOUBLE, rstyle.getBorderBottom());
assertEquals(BorderStyle.DOUBLE, rstyle.getBorderBottomEnum());
wb.close();
}
@ -3051,7 +3051,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFBorderFormatting bord = rule.createBorderFormatting();
bord.setBorderDiagonal(BorderStyle.THICK);
assertEquals(BorderStyle.THICK, bord.getBorderDiagonal());
assertEquals(BorderStyle.THICK, bord.getBorderDiagonalEnum());
bord.setBackwardDiagonalOn(true);
assertTrue(bord.isBackwardDiagonalOn());
@ -3064,7 +3064,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Create the bottom border style so we know what a border is supposed to look like
bord.setBorderBottom(BorderStyle.THICK);
assertEquals(BorderStyle.THICK, bord.getBorderBottom());
assertEquals(BorderStyle.THICK, bord.getBorderBottomEnum());
bord.setBottomBorderColor(BLUE);
assertEquals(BLUE, bord.getBottomBorderColor());

View File

@ -348,40 +348,40 @@ public final class TestCellStyle extends TestCase {
HSSFCellStyle cs;
cs = s.getRow(0).getCell(0).getCellStyle();
assertEquals(BorderStyle.HAIR, cs.getBorderRight());
assertEquals(BorderStyle.HAIR, cs.getBorderRightEnum());
cs = s.getRow(1).getCell(1).getCellStyle();
assertEquals(BorderStyle.DOTTED, cs.getBorderRight());
assertEquals(BorderStyle.DOTTED, cs.getBorderRightEnum());
cs = s.getRow(2).getCell(2).getCellStyle();
assertEquals(BorderStyle.DASH_DOT_DOT, cs.getBorderRight());
assertEquals(BorderStyle.DASH_DOT_DOT, cs.getBorderRightEnum());
cs = s.getRow(3).getCell(3).getCellStyle();
assertEquals(BorderStyle.DASHED, cs.getBorderRight());
assertEquals(BorderStyle.DASHED, cs.getBorderRightEnum());
cs = s.getRow(4).getCell(4).getCellStyle();
assertEquals(BorderStyle.THIN, cs.getBorderRight());
assertEquals(BorderStyle.THIN, cs.getBorderRightEnum());
cs = s.getRow(5).getCell(5).getCellStyle();
assertEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, cs.getBorderRight());
assertEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, cs.getBorderRightEnum());
cs = s.getRow(6).getCell(6).getCellStyle();
assertEquals(BorderStyle.SLANTED_DASH_DOT, cs.getBorderRight());
assertEquals(BorderStyle.SLANTED_DASH_DOT, cs.getBorderRightEnum());
cs = s.getRow(7).getCell(7).getCellStyle();
assertEquals(BorderStyle.MEDIUM_DASH_DOT, cs.getBorderRight());
assertEquals(BorderStyle.MEDIUM_DASH_DOT, cs.getBorderRightEnum());
cs = s.getRow(8).getCell(8).getCellStyle();
assertEquals(BorderStyle.MEDIUM_DASHED, cs.getBorderRight());
assertEquals(BorderStyle.MEDIUM_DASHED, cs.getBorderRightEnum());
cs = s.getRow(9).getCell(9).getCellStyle();
assertEquals(BorderStyle.MEDIUM, cs.getBorderRight());
assertEquals(BorderStyle.MEDIUM, cs.getBorderRightEnum());
cs = s.getRow(10).getCell(10).getCellStyle();
assertEquals(BorderStyle.THICK, cs.getBorderRight());
assertEquals(BorderStyle.THICK, cs.getBorderRightEnum());
cs = s.getRow(11).getCell(11).getCellStyle();
assertEquals(BorderStyle.DOUBLE, cs.getBorderRight());
assertEquals(BorderStyle.DOUBLE, cs.getBorderRightEnum());
}
public void testShrinkToFit() {
@ -500,7 +500,7 @@ public final class TestCellStyle extends TestCase {
newCell.setCellValue("2testtext2");
CellStyle newStyle = newCell.getCellStyle();
assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottom());
assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottomEnum());
assertEquals(Font.COLOR_RED, ((HSSFCellStyle)newStyle).getFont(wb).getColor());
// OutputStream out = new FileOutputStream("/tmp/56959.xls");

View File

@ -55,7 +55,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
HSSFCell cell = sheet.getRow(8).getCell(0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue cv = fe.evaluate(cell);
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(3.72, cv.getNumberValue(), 0.0);
wb.close();
}
@ -127,7 +127,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
try {
value = hsf.evaluate(cellA1);
assertEquals(CellType.NUMERIC, value.getCellType());
assertEquals(CellType.NUMERIC, value.getCellTypeEnum());
assertEquals(5.33, value.getNumberValue(), 0.0);
} catch (RuntimeException e) {

View File

@ -308,8 +308,8 @@ public final class TestHSSFOptimiser extends TestCase {
// Check
assertEquals(23, wb.getNumCellStyles());
assertEquals(BorderStyle.THICK, r.getCell(0).getCellStyle().getBorderBottom());
assertEquals(BorderStyle.DASH_DOT, r.getCell(1).getCellStyle().getBorderBottom());
assertEquals(BorderStyle.THICK, r.getCell(2).getCellStyle().getBorderBottom());
assertEquals(BorderStyle.THICK, r.getCell(0).getCellStyle().getBorderBottomEnum());
assertEquals(BorderStyle.DASH_DOT, r.getCell(1).getCellStyle().getBorderBottomEnum());
assertEquals(BorderStyle.THICK, r.getCell(2).getCellStyle().getBorderBottomEnum());
}
}

View File

@ -151,10 +151,10 @@ public final class TestRowStyle extends TestCase {
assertNotNull("Row is not null", r);
cs = r.getRowStyle();
assertEquals("Bottom Border Style for row:", BorderStyle.THIN, cs.getBorderBottom());
assertEquals("Left Border Style for row:", BorderStyle.THIN, cs.getBorderLeft());
assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRight());
assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTop());
assertEquals("Bottom Border Style for row:", BorderStyle.THIN, cs.getBorderBottomEnum());
assertEquals("Left Border Style for row:", BorderStyle.THIN, cs.getBorderLeftEnum());
assertEquals("Right Border Style for row:", BorderStyle.THIN, cs.getBorderRightEnum());
assertEquals("Top Border Style for row:", BorderStyle.THIN, cs.getBorderTopEnum());
assertEquals("FillForegroundColor for row:", 0xA, cs.getFillForegroundColor());
assertEquals("FillPattern for row:", 0x1, cs.getFillPattern());

View File

@ -203,7 +203,7 @@ public class TestWorkbookEvaluator {
} catch (RuntimeException e) {
fail("Missing arg result not being handled correctly.");
}
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
// adding blank to 1.0 gives 1.0
assertEquals(1.0, cv.getNumberValue(), 0.0);
@ -211,7 +211,7 @@ public class TestWorkbookEvaluator {
cell.setCellFormula("\"abc\"&IF(1,,)");
fe.notifySetFormula(cell);
cv = fe.evaluate(cell);
assertEquals(CellType.STRING, cv.getCellType());
assertEquals(CellType.STRING, cv.getCellTypeEnum());
// adding blank to "abc" gives "abc"
assertEquals("abc", cv.getStringValue());
@ -219,7 +219,7 @@ public class TestWorkbookEvaluator {
cell.setCellFormula("\"abc\"&CHOOSE(2,5,,9)");
fe.notifySetFormula(cell);
cv = fe.evaluate(cell);
assertEquals(CellType.STRING, cv.getCellType());
assertEquals(CellType.STRING, cv.getCellTypeEnum());
// adding blank to "abc" gives "abc"
assertEquals("abc", cv.getStringValue());
}
@ -245,14 +245,14 @@ public class TestWorkbookEvaluator {
}
throw new RuntimeException(e);
}
assertEquals(CellType.ERROR, cv.getCellType());
assertEquals(CellType.ERROR, cv.getCellTypeEnum());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), cv.getErrorValue());
// verify circular refs are still detected properly
fe.clearAllCachedResultValues();
cell.setCellFormula("OFFSET(A1,0,0)");
cv = fe.evaluate(cell);
assertEquals(CellType.ERROR, cv.getCellType());
assertEquals(CellType.ERROR, cv.getCellTypeEnum());
assertEquals(ErrorEval.CIRCULAR_REF_ERROR.getErrorCode(), cv.getErrorValue());
} finally {
wb.close();
@ -396,7 +396,7 @@ public class TestWorkbookEvaluator {
assertEquals(CellType.FORMULA, D1.getCellTypeEnum());
assertEquals(expectedFormula, D1.getCellFormula());
assertEquals(CellType.NUMERIC, result.getCellType());
assertEquals(CellType.NUMERIC, result.getCellTypeEnum());
assertEquals(expectedResult, result.getNumberValue(), EPSILON);
testIFEqualsFormulaEvaluation_teardown(wb);

View File

@ -78,18 +78,18 @@ public class TestIfError extends TestCase {
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
assertEquals("Checks that the cell is numeric",
CellType.NUMERIC, evaluator.evaluate(cell1).getCellType());
CellType.NUMERIC, evaluator.evaluate(cell1).getCellTypeEnum());
assertEquals("Divides 210 by 35 and returns 6.0",
6.0, evaluator.evaluate(cell1).getNumberValue(), accuracy);
assertEquals("Checks that the cell is numeric",
CellType.STRING, evaluator.evaluate(cell2).getCellType());
CellType.STRING, evaluator.evaluate(cell2).getCellTypeEnum());
assertEquals("Rounds -10 to a nearest multiple of -3 (-9)",
"Error in calculation", evaluator.evaluate(cell2).getStringValue());
assertEquals("Check that C1 returns string",
CellType.STRING, evaluator.evaluate(cell3).getCellType());
CellType.STRING, evaluator.evaluate(cell3).getCellTypeEnum());
assertEquals("Check that C1 returns string \"error\"",
"error", evaluator.evaluate(cell3).getStringValue());
}

View File

@ -66,7 +66,7 @@ public abstract class BaseTestCircularReferences {
* Makes sure that the specified evaluated cell value represents a circular reference error.
*/
private static void confirmCycleErrorCode(CellValue cellValue) {
assertTrue(cellValue.getCellType() == CellType.ERROR);
assertTrue(cellValue.getCellTypeEnum() == CellType.ERROR);
assertEquals(ErrorEval.CIRCULAR_REF_ERROR.getErrorCode(), cellValue.getErrorValue());
}
@ -96,7 +96,7 @@ public abstract class BaseTestCircularReferences {
CellValue cellValue = evaluateWithCycles(wb, testCell);
assertTrue(cellValue.getCellType() == CellType.NUMERIC);
assertTrue(cellValue.getCellTypeEnum() == CellType.NUMERIC);
assertEquals(2, cellValue.getNumberValue(), 0);
wb.close();
}
@ -166,24 +166,24 @@ public abstract class BaseTestCircularReferences {
// Happy day flow - evaluate A1 first
cv = fe.evaluate(cellA1);
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(42.0, cv.getNumberValue(), 0.0);
cv = fe.evaluate(cellB1); // no circ-ref-error because A1 result is cached
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(46.0, cv.getNumberValue(), 0.0);
// Show the bug - evaluate another cell from the loop first
fe.clearAllCachedResultValues();
cv = fe.evaluate(cellB1);
// Identified bug 46898
assertNotEquals(cv.getCellType(), ErrorEval.CIRCULAR_REF_ERROR.getErrorCode());
assertEquals(CellType.NUMERIC, cv.getCellType());
assertNotEquals(cv.getCellTypeEnum(), ErrorEval.CIRCULAR_REF_ERROR.getErrorCode());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(46.0, cv.getNumberValue(), 0.0);
// start evaluation on another cell
fe.clearAllCachedResultValues();
cv = fe.evaluate(cellE1);
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(43.0, cv.getNumberValue(), 0.0);
wb.close();

View File

@ -58,7 +58,7 @@ public final class TestFormulaBugs {
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
CellValue cv = fe.evaluate(cell);
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(3.0, cv.getNumberValue(), 0.0);
wb.close();
@ -106,11 +106,11 @@ public final class TestFormulaBugs {
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
CellValue cv;
cv = fe.evaluate(cell);
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(1.0, cv.getNumberValue(), 0.0);
cv = fe.evaluate(row.getCell(1));
assertEquals(CellType.BOOLEAN, cv.getCellType());
assertEquals(CellType.BOOLEAN, cv.getCellTypeEnum());
assertEquals(true, cv.getBooleanValue());
wb.close();
@ -161,7 +161,7 @@ public final class TestFormulaBugs {
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
CellValue cv = fe.evaluate(cell);
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
wb.close();

View File

@ -190,24 +190,24 @@ public final class TestFormulasFromSpreadsheet {
final CellType cellType = expValue.getCellTypeEnum();
switch (cellType) {
case BLANK:
assertEquals(msg, CellType.BLANK, actValue.getCellType());
assertEquals(msg, CellType.BLANK, actValue.getCellTypeEnum());
break;
case BOOLEAN:
assertEquals(msg, CellType.BOOLEAN, actValue.getCellType());
assertEquals(msg, CellType.BOOLEAN, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue());
break;
case ERROR:
assertEquals(msg, CellType.ERROR, actValue.getCellType());
assertEquals(msg, CellType.ERROR, actValue.getCellTypeEnum());
assertEquals(msg, ErrorEval.getText(expValue.getErrorCellValue()), ErrorEval.getText(actValue.getErrorValue()));
break;
case FORMULA: // will never be used, since we will call method after formula evaluation
fail("Cannot expect formula as result of formula evaluation: " + msg);
case NUMERIC:
assertEquals(msg, CellType.NUMERIC, actValue.getCellType());
assertEquals(msg, CellType.NUMERIC, actValue.getCellTypeEnum());
TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
break;
case STRING:
assertEquals(msg, CellType.STRING, actValue.getCellType());
assertEquals(msg, CellType.STRING, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue());
break;
default:

View File

@ -110,24 +110,24 @@ public final class TestMultiSheetEval extends TestCase {
switch (cellType) {
case BLANK:
assertEquals(msg, CellType.BLANK, actual.getCellType());
assertEquals(msg, CellType.BLANK, actual.getCellTypeEnum());
break;
case BOOLEAN:
assertEquals(msg, CellType.BOOLEAN, actual.getCellType());
assertEquals(msg, CellType.BOOLEAN, actual.getCellTypeEnum());
assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue());
break;
case ERROR:
assertEquals(msg, CellType.ERROR, actual.getCellType());
assertEquals(msg, CellType.ERROR, actual.getCellTypeEnum());
assertEquals(msg, ErrorEval.getText(expected.getErrorCellValue()), ErrorEval.getText(actual.getErrorValue()));
break;
case FORMULA: // will never be used, since we will call method after formula evaluation
throw new AssertionFailedError("Cannot expect formula as result of formula evaluation: " + msg);
case NUMERIC:
assertEquals(msg, CellType.NUMERIC, actual.getCellType());
assertEquals(msg, CellType.NUMERIC, actual.getCellTypeEnum());
TestMathX.assertEquals(msg, expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
break;
case STRING:
assertEquals(msg, CellType.STRING, actual.getCellType());
assertEquals(msg, CellType.STRING, actual.getCellTypeEnum());
assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue());
break;
default:

View File

@ -78,7 +78,7 @@ public final class TestPercentEval extends TestCase {
// else some other unexpected error
throw e;
}
assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(0.5, cv.getNumberValue(), 0.0);
}
}

View File

@ -155,7 +155,7 @@ public abstract class BaseTestFunctionsFromSpreadsheet {
if (expectedCell.getCellTypeEnum() == CellType.ERROR) {
int expectedErrorCode = expectedCell.getErrorCellValue();
assertEquals(msg, CellType.ERROR, actualValue.getCellType());
assertEquals(msg, CellType.ERROR, actualValue.getCellTypeEnum());
assertEquals(msg, ErrorEval.getText(expectedErrorCode), actualValue.formatAsString());
assertEquals(msg, expectedErrorCode, actualValue.getErrorValue());
assertEquals(msg, ErrorEval.getText(expectedErrorCode), ErrorEval.getText(actualValue.getErrorValue()));
@ -163,11 +163,11 @@ public abstract class BaseTestFunctionsFromSpreadsheet {
}
// unexpected error
assertNotEquals(msg, CellType.ERROR, actualValue.getCellType());
assertNotEquals(msg, CellType.ERROR, actualValue.getCellTypeEnum());
assertNotEquals(msg, formatValue(expectedCell), ErrorEval.getText(actualValue.getErrorValue()));
// wrong type error
assertEquals(msg, expectedCell.getCellTypeEnum(), actualValue.getCellType());
assertEquals(msg, expectedCell.getCellTypeEnum(), actualValue.getCellTypeEnum());
final CellType expectedCellType = expectedCell.getCellTypeEnum();
switch (expectedCellType) {

View File

@ -73,7 +73,7 @@ public final class TestAddress extends TestCase {
cell.setCellFormula(formulaText);
fe.notifyUpdateCell(cell);
CellValue result = fe.evaluate(cell);
assertEquals(result.getCellType(), CellType.STRING);
assertEquals(result.getCellTypeEnum(), CellType.STRING);
assertEquals(expectedResult, result.getStringValue());
}
}

View File

@ -103,7 +103,7 @@ public final class TestCalendarFieldFunction extends TestCase {
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
if (cv.getCellType() != CellType.NUMERIC) {
if (cv.getCellTypeEnum() != CellType.NUMERIC) {
throw new AssertionFailedError("Wrong result type: " + cv.formatAsString());
}
double actualValue = cv.getNumberValue();

View File

@ -60,7 +60,7 @@ public final class TestClean extends TestCase {
cell.setCellFormula(formulaText);
fe.notifyUpdateCell(cell);
CellValue result = fe.evaluate(cell);
assertEquals(result.getCellType(), CellType.STRING);
assertEquals(result.getCellTypeEnum(), CellType.STRING);
assertEquals(expectedResult, result.getStringValue());
}
}

View File

@ -81,7 +81,7 @@ public final class TestDate extends TestCase {
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
if (cv.getCellType() != CellType.NUMERIC) {
if (cv.getCellTypeEnum() != CellType.NUMERIC) {
throw new AssertionFailedError("Wrong result type: " + cv.formatAsString());
}
double actualValue = cv.getNumberValue();

View File

@ -66,7 +66,7 @@ public final class TestFind {
cell.setCellFormula(formulaText);
fe.notifyUpdateCell(cell);
CellValue result = fe.evaluate(cell);
assertEquals(result.getCellType(), CellType.NUMERIC);
assertEquals(result.getCellTypeEnum(), CellType.NUMERIC);
assertEquals(expectedResult, result.getNumberValue(), 0.0);
}
@ -75,7 +75,7 @@ public final class TestFind {
cell.setCellFormula(formulaText);
fe.notifyUpdateCell(cell);
CellValue result = fe.evaluate(cell);
assertEquals(result.getCellType(), CellType.ERROR);
assertEquals(result.getCellTypeEnum(), CellType.ERROR);
assertEquals(expectedErrorCode.getCode(), result.getErrorValue());
}
}

View File

@ -117,7 +117,7 @@ public final class TestFixed {
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
assertEquals("Wrong result type: " + cv.formatAsString(), CellType.STRING, cv.getCellType());
assertEquals("Wrong result type: " + cv.formatAsString(), CellType.STRING, cv.getCellTypeEnum());
String actualValue = cv.getStringValue();
assertEquals(expectedResult, actualValue);
}
@ -127,7 +127,7 @@ public final class TestFixed {
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
assertTrue("Wrong result type: " + cv.formatAsString(),
cv.getCellType() == CellType.ERROR
cv.getCellTypeEnum() == CellType.ERROR
&& cv.getErrorValue() == FormulaError.VALUE.getCode());
}
}

View File

@ -185,7 +185,7 @@ public final class TestIndirect {
fe.clearAllCachedResultValues();
cell.setCellFormula(formula);
CellValue cv = fe.evaluate(cell);
if (cv.getCellType() != CellType.NUMERIC) {
if (cv.getCellTypeEnum() != CellType.NUMERIC) {
fail("expected numeric cell type but got " + cv.formatAsString());
}
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
@ -196,7 +196,7 @@ public final class TestIndirect {
fe.clearAllCachedResultValues();
cell.setCellFormula(formula);
CellValue cv = fe.evaluate(cell);
if (cv.getCellType() != CellType.ERROR) {
if (cv.getCellTypeEnum() != CellType.ERROR) {
fail("expected error cell type but got " + cv.formatAsString());
}
int expCode = expectedResult.getErrorCode();

View File

@ -128,7 +128,7 @@ public final class TestIrr extends TestCase {
private static void assertFormulaResult(CellValue cv, HSSFCell cell){
double actualValue = cv.getNumberValue();
double expectedValue = cell.getNumericCellValue(); // cached formula result calculated by Excel
assertEquals("Invalid formula result: " + cv.toString(), CellType.NUMERIC, cv.getCellType());
assertEquals("Invalid formula result: " + cv.toString(), CellType.NUMERIC, cv.getCellTypeEnum());
assertEquals(expectedValue, actualValue, 1E-4); // should agree within 0.01%
}
}

Some files were not shown because too many files have changed in this diff Show More