package org.apache.poi.hssf.usermodel.examples;
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFRow;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellType;
+
public class CellTypes {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
row.createCell(1).setCellValue(new Date());
row.createCell(2).setCellValue("a string");
row.createCell(3).setCellValue(true);
- row.createCell(4).setCellType(HSSFCell.CELL_TYPE_ERROR);
+ row.createCell(4).setCellType(CellType.ERROR);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
package org.apache.poi.hssf.usermodel.examples;
-import org.apache.poi.hssf.usermodel.*;
-
import java.io.FileOutputStream;
import java.io.IOException;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellType;
+
/**
* Test if hyperlink formula, with url that got more than 127 characters, works
*
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
- cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
+ cell.setCellType(CellType.FORMULA);
cell.setCellFormula("HYPERLINK(\"http://127.0.0.1:8080/toto/truc/index.html?test=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"test\")");
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.CellType;
import java.io.FileOutputStream;
import java.io.IOException;
r = s.createRow(2);
r.setHeight((short) 0x349);
c = r.createCell(2);
- c.setCellType(HSSFCell.CELL_TYPE_STRING);
+ c.setCellType(CellType.STRING);
c.setCellValue("Use \n with word wrap on to create a new line");
c.setCellStyle(cs);
s.setColumnWidth(2, (int) ((50 * 8) / ((double) 1 / 20)));
package org.apache.poi.hssf.usermodel.examples;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.hssf.usermodel.HSSFRow;
-import org.apache.poi.hssf.usermodel.HSSFCell;
-
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.ss.usermodel.CellType;
+
/**
* This example demonstrates opening a workbook, modifying it and writing
* the results back out.
HSSFCell cell = row.getCell(3);
if (cell == null)
cell = row.createCell(3);
- cell.setCellType(HSSFCell.CELL_TYPE_STRING);
+ cell.setCellType(CellType.STRING);
cell.setCellValue("a test");
// Write the output to a file
==================================================================== */
package org.apache.poi.hssf.view;
-import org.apache.poi.hssf.view.brush.PendingPaintings;
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Row;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.Toolkit;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
-import javax.swing.*;
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JViewport;
+import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
-import javax.swing.table.*;
+import javax.swing.table.JTableHeader;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableModel;
import javax.swing.text.JTextComponent;
-import java.awt.*;
-import java.awt.event.HierarchyEvent;
-import java.awt.event.HierarchyListener;
+
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.view.brush.PendingPaintings;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Row;
/**
* This class is a table that represents the values in a single worksheet.
HSSFCell cell = (HSSFCell) getValueAt(row, col);
String formula = "";
if (cell != null) {
- if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
+ if (cell.getCellType() == CellType.FORMULA) {
formula = cell.getCellFormula();
} else {
formula = cell.toString();
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
csvLine.add("");
}
else {
- if(cell.getCellType() != Cell.CELL_TYPE_FORMULA) {
+ if(cell.getCellType() != CellType.FORMULA) {
csvLine.add(this.formatter.formatCellValue(cell));
}
else {
long valueLongBits = readLong();
double result = Double.longBitsToDouble(valueLongBits);
if (Double.isNaN(result)) {
- // YK: Excel doesn't write NaN but instead converts the cell type into CELL_TYPE_ERROR.
+ // YK: Excel doesn't write NaN but instead converts the cell type into {@link CellType#ERROR}.
// HSSF prior to version 3.7 had a bug: it could write Double.NaN but could not read such a file back.
// This behavior was fixed in POI-3.7.
- //throw new RuntimeException("Did not expect to read NaN"); // (Because Excel typically doesn't write NaN
+ //throw new RuntimeException("Did not expect to read NaN"); // (Because Excel typically doesn't write NaN)
}
return result;
}
import org.apache.poi.hssf.record.FontRecord;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
/**
HSSFSheet s = workbook.getSheetAt(sheetNum);
for (Row row : s) {
for (Cell cell : row) {
- if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
+ if(cell.getCellType() == CellType.STRING) {
HSSFRichTextString rtr = (HSSFRichTextString)cell.getRichStringCellValue();
UnicodeString u = rtr.getRawUnicodeString();
/**
* Use this to create new cells within the row and return it.
* <p>
- * The cell that is returned is a CELL_TYPE_BLANK. The type can be changed
+ * The cell that is returned is a {@link CellType#BLANK}. The type can be changed
* either through calling <code>setCellValue</code> or <code>setCellType</code>.
*
* @param column - the column number this cell represents
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.HyperlinkRecord;
import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.NoteRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellRange;
import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.usermodel.Row;
CellRange<HSSFCell> result = getCellRange(range);
// clear all cells in the range
for (Cell c : result) {
- c.setCellType(Cell.CELL_TYPE_BLANK);
+ c.setCellType(CellType.BLANK);
}
return result;
}
/**
* Returns the ultimate cell type, following the results of formulas. If
- * the cell is a {@link Cell#CELL_TYPE_FORMULA}, this returns the result of
+ * the cell is a {@link CellType#FORMULA}, this returns the result of
* {@link Cell#getCachedFormulaResultType()}. Otherwise this returns the
* result of {@link Cell#getCellType()}.
*
package org.apache.poi.ss.formula;
+import org.apache.poi.ss.formula.FormulaCellCache.IEntryOperation;
+import org.apache.poi.ss.formula.FormulaUsedBlankCellSet.BookSheetKey;
+import org.apache.poi.ss.formula.PlainCellCache.Loc;
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.apache.poi.ss.formula.FormulaCellCache.IEntryOperation;
-import org.apache.poi.ss.formula.FormulaUsedBlankCellSet.BookSheetKey;
-import org.apache.poi.ss.formula.PlainCellCache.Loc;
-import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
/**
* Performance optimisation for {@link org.apache.poi.ss.usermodel.FormulaEvaluator}.
Loc loc = new Loc(bookIndex, sheetIndex, rowIndex, columnIndex);
PlainValueCellCacheEntry pcce = _plainCellCache.get(loc);
- if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
+ if (cell.getCellType() == CellType.FORMULA) {
if (fcce == null) {
fcce = new FormulaCellCacheEntry();
if (pcce == null) {
}
public void notifyDeleteCell(int bookIndex, int sheetIndex, EvaluationCell cell) {
- if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
+ if (cell.getCellType() == CellType.FORMULA) {
FormulaCellCacheEntry fcce = _formulaCellCache.remove(cell);
if (fcce == null) {
// formula cell has not been evaluated yet
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.ptg.FuncVarPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
-import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
/**
* Evaluator for cells within a specific Sheet
public boolean isSubTotal(int rowIndex, int columnIndex){
boolean subtotal = false;
EvaluationCell cell = getSheet().getCell(rowIndex, columnIndex);
- if(cell != null && cell.getCellType() == Cell.CELL_TYPE_FORMULA){
+ if(cell != null && cell.getCellType() == CellType.FORMULA){
EvaluationWorkbook wb = _bookEvaluator.getWorkbook();
for(Ptg ptg : wb.getFormulaTokens(cell)){
if(ptg instanceof FuncVarPtg){
package org.apache.poi.ss.formula.eval;
import org.apache.poi.ss.formula.SheetRange;
+import org.apache.poi.ss.usermodel.CellType;
/**
* RefEval is the super interface for Ref2D and Ref3DEval. Basically a RefEval
* impl should contain reference to the original ReferencePtg or Ref3DPtg as
* well as the final "value" resulting from the evaluation of the cell
- * reference. Thus if the Cell has type CELL_TYPE_NUMERIC, the contained
- * value object should be of type NumberEval; if cell type is CELL_TYPE_STRING,
+ * reference. Thus if the Cell has type {@link CellType#NUMERIC}, the contained
+ * value object should be of type NumberEval; if cell type is {@link CellType#STRING},
* contained value object should be of type StringEval
*/
public interface RefEval extends ValueEval, SheetRange {
*
* @throws IllegalArgumentException if the specified cell type is invalid
* @throws IllegalStateException if the current value cannot be converted to the new type
- * @see #CELL_TYPE_NUMERIC
- * @see #CELL_TYPE_STRING
- * @see #CELL_TYPE_FORMULA
- * @see #CELL_TYPE_BLANK
- * @see #CELL_TYPE_BOOLEAN
- * @see #CELL_TYPE_ERROR
+ * @see CellType#NUMERIC
+ * @see CellType#STRING
+ * @see CellType#FORMULA
+ * @see CellType#BLANK
+ * @see CellType#BOOLEAN
+ * @see CellType#ERROR
* @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead.
*/
void setCellType(int cellType);
* the result of the formula, use {@link #evaluateInCell(Cell)}
* @param cell The cell to evaluate
* @return The type of the formula result, i.e. -1 if the cell is not a formula,
- * or one of Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_STRING, Cell.CELL_TYPE_BOOLEAN, Cell.CELL_TYPE_ERROR
- * Note: the cell's type remains as Cell.CELL_TYPE_FORMULA however.
+ * or one of CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN, CellType.ERROR
+ * Note: the cell's type remains as CellType.FORMULA however.
*/
CellType evaluateFormulaCell(Cell cell);
return new AbstractCellRangeDataSource<Number>(sheet, cellRangeAddress) {
public Number getPointAt(int index) {
CellValue cellValue = getCellValueAt(index);
- if (cellValue != null && cellValue.getCellType() == Cell.CELL_TYPE_NUMERIC) {
+ if (cellValue != null && cellValue.getCellType() == CellType.NUMERIC) {
return Double.valueOf(cellValue.getNumberValue());
} else {
return null;
return new AbstractCellRangeDataSource<String>(sheet, cellRangeAddress) {
public String getPointAt(int index) {
CellValue cellValue = getCellValueAt(index);
- if (cellValue != null && cellValue.getCellType() == Cell.CELL_TYPE_STRING) {
+ if (cellValue != null && cellValue.getCellType() == CellType.STRING) {
return cellValue.getStringValue();
} else {
return null;
package org.apache.poi.ss.util.cellwalk;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
}
private boolean isEmpty(Cell cell) {
- return (cell.getCellType() == Cell.CELL_TYPE_BLANK);
+ return (cell.getCellType() == CellType.BLANK);
}
/**
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.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.POILogFactory;
// Evaluate what we have
for (Row r : sheet) {
for (Cell c : r) {
- if (c.getCellType() == Cell.CELL_TYPE_FORMULA) {
+ if (c.getCellType() == CellType.FORMULA) {
eval.evaluateFormulaCell(c);
}
}
* 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 HSSFCell.CELL_TYPE_FORMULA however)
+ * @return The type of the formula result (the cell's type remains as CellType.FORMULA however)
*/
public CellType evaluateFormulaCell(Cell cell) {
if (cell == null || cell.getCellType() != CellType.FORMULA) {
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.AreaReference;
//General number format
cf.setNumFmtId(0);
Cell cell = row.getCell(i);
- cell.setCellType(Cell.CELL_TYPE_STRING);
+ cell.setCellType(CellType.STRING);
cf.setName(row.getCell(i).getStringCellValue());
cf.addNewSharedItems();
}
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
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.Sheet;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.util.Internal;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheSource;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColFields;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataField;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataFields;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTField;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTItems;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLocation;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageField;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageFields;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCacheDefinition;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotTableDefinition;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotTableStyle;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRowFields;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetSource;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STAxis;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataConsolidateFunction;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STItemType;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STSourceType;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
public class XSSFPivotTable extends POIXMLDocumentPart {
dataField.setSubtotal(STDataConsolidateFunction.Enum.forInt(function.getValue()));
Cell cell = getDataSheet().getRow(pivotArea.getFirstCell().getRow())
.getCell(pivotArea.getFirstCell().getCol() + columnIndex);
- cell.setCellType(Cell.CELL_TYPE_STRING);
+ cell.setCellType(CellType.STRING);
dataField.setName(valueFieldName);
dataField.setFld(columnIndex);
dataFields.setCount(dataFields.sizeOfDataFieldArray());
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.POIXMLException;
-
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.usermodel.CellCopyPolicy;
import org.apache.poi.ss.usermodel.CellRange;
import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.usermodel.Footer;
arrayFormulas.remove(range);
CellRange<XSSFCell> cr = getCellRange(range);
for (XSSFCell c : cr) {
- c.setCellType(Cell.CELL_TYPE_BLANK);
+ c.setCellType(CellType.BLANK);
}
return cr;
}
import org.apache.poi.ss.formula.ptg.Pxg;
import org.apache.poi.ss.formula.ptg.Pxg3D;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFCell;
for (Sheet sh : _wb) {
for (Row row : sh) {
for (Cell cell : row) {
- if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
+ if (cell.getCellType() == CellType.FORMULA) {
updateFormula((XSSFCell) cell, oldName, newName);
}
}
import static org.junit.Assert.fail;
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.Table;
private static void confirm(FormulaEvaluator fe, Cell cell, double expectedResult) {
fe.clearAllCachedResultValues();
CellValue cv = fe.evaluate(cell);
- if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
+ if (cv.getCellType() != CellType.NUMERIC) {
fail("expected numeric cell type but got " + cv.formatAsString());
}
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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.Sheet;
private void confirm(Workbook wb) {
Sheet sheet = wb.createSheet("new sheet");
cell11 = sheet.createRow(0).createCell(0);
- cell11.setCellType(XSSFCell.CELL_TYPE_FORMULA);
+ cell11.setCellType(CellType.FORMULA);
confirm("PROPER(\"hi there\")", "Hi There");
confirm("PROPER(\"what's up\")", "What'S Up");
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
- if (cv.getCellType() != Cell.CELL_TYPE_STRING) {
+ if (cv.getCellType() != CellType.STRING) {
throw new AssertionFailedError("Wrong result type: " + cv.formatAsString());
}
String actualValue = cv.getStringValue();
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.XMLHelper;
Cell cString = row.createCell(0);
cString.setCellValue("somestring");
- cString.setCellType(XSSFCell.CELL_TYPE_STRING);
+ cString.setCellType(CellType.STRING);
Cell cBoolean = row.createCell(1);
cBoolean.setCellValue(true);
- cBoolean.setCellType(XSSFCell.CELL_TYPE_BOOLEAN);
+ cBoolean.setCellType(CellType.BOOLEAN);
Cell cError = row.createCell(2);
- cError.setCellType(XSSFCell.CELL_TYPE_ERROR);
+ cError.setCellType(CellType.ERROR);
Cell cFormulaString = row.createCell(3);
cFormulaString.setCellFormula("A1");
- cFormulaString.setCellType(XSSFCell.CELL_TYPE_FORMULA);
+ cFormulaString.setCellType(CellType.FORMULA);
Cell cFormulaNumeric = row.createCell(4);
cFormulaNumeric.setCellFormula("F1");
- cFormulaNumeric.setCellType(XSSFCell.CELL_TYPE_FORMULA);
+ cFormulaNumeric.setCellType(CellType.FORMULA);
Cell cNumeric = row.createCell(5);
cNumeric.setCellValue(1.2);
- cNumeric.setCellType(XSSFCell.CELL_TYPE_NUMERIC);
+ cNumeric.setCellType(CellType.NUMERIC);
Cell cDate = row.createCell(6);
cDate.setCellValue(new Date());
- cDate.setCellType(XSSFCell.CELL_TYPE_NUMERIC);
+ cDate.setCellType(CellType.NUMERIC);
boolean found = false;
for (POIXMLDocumentPart p : wb.getRelations()) {
package org.apache.poi.xssf.model;
-import org.apache.poi.xssf.usermodel.*;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcCell;
import junit.framework.TestCase;
XSSFSheet sheet = wb.getSheet("Test");
XSSFCell cell = sheet.getRow(0).getCell(4);
- assertEquals(XSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals(CellType.FORMULA, cell.getCellType());
cell.setCellFormula(null);
//the count of items is less by one
assertEquals(10, c.getI());
assertEquals("C1", c.getR());
- assertEquals(XSSFCell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals(CellType.STRING, cell.getCellType());
cell.setCellValue("ABC");
- assertEquals(XSSFCell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals(CellType.STRING, cell.getCellType());
}
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.BaseTestXWorkbook;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
Arrays.fill(useless, 0, 10, ' ');
System.arraycopy(prefix, 0, useless, 0, prefix.length);
String ul = new String(useless);
- r.createCell(col, Cell.CELL_TYPE_STRING).setCellValue(ul);
+ r.createCell(col, CellType.STRING).setCellValue(ul);
ul = null;
}
}
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellCopyPolicy;
import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Font;
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
- cell.setCellType(Cell.CELL_TYPE_STRING);
+ cell.setCellType(CellType.STRING);
cell.setCellValue("456");
wb.close();
}
assertNull(str.getString());
cell_0.setCellValue(str);
assertEquals(0, sst.getCount());
- assertEquals(Cell.CELL_TYPE_BLANK, cell_0.getCellType());
+ assertEquals(CellType.BLANK, cell_0.getCellType());
//case 2. cell.setCellValue((String)null);
Cell cell_1 = row.createCell(1);
cell_1.setCellValue((String)null);
assertEquals(0, sst.getCount());
- assertEquals(Cell.CELL_TYPE_BLANK, cell_1.getCellType());
+ assertEquals(CellType.BLANK, cell_1.getCellType());
wb.close();
}
CTCell ctCell = cell.getCTCell(); //low-level bean holding cell's xml
cell.setCellFormula("A2");
- assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals("A2", cell.getCellFormula());
//the value is not set and cell's type='N' which means blank
assertEquals(STCellType.N, ctCell.getT());
//set cached formula value
cell.setCellValue("t='str'");
//we are still of 'formula' type
- assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals("A2", cell.getCellFormula());
//cached formula value is set and cell's type='STR'
assertEquals(STCellType.STR, ctCell.getT());
//now remove the formula, the cached formula result remains
cell.setCellFormula(null);
- assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals(CellType.STRING, cell.getCellType());
assertEquals(STCellType.STR, ctCell.getT());
//the line below failed prior to fix of Bug #47889
assertEquals("t='str'", cell.getStringCellValue());
//revert to a blank cell
cell.setCellValue((String)null);
- assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType());
+ assertEquals(CellType.BLANK, cell.getCellType());
assertEquals(STCellType.N, ctCell.getT());
assertEquals("", cell.getStringCellValue());
} finally {
//try a string cell
cell = sh.getRow(0).getCell(0);
- assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals(CellType.STRING, cell.getCellType());
assertEquals("a", cell.getStringCellValue());
assertEquals("a", cell.toString());
//Gnumeric produces spreadsheets without styles
//try a numeric cell
cell = sh.getRow(1).getCell(0);
- assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCellType());
assertEquals(1.0, cell.getNumericCellValue(), 0);
assertEquals("1.0", cell.toString());
//Gnumeric produces spreadsheets without styles
final CellCopyPolicy policy = new CellCopyPolicy();
destCell.copyCellFrom(srcCell, policy);
- assertEquals(Cell.CELL_TYPE_FORMULA, destCell.getCellType());
+ assertEquals(CellType.FORMULA, destCell.getCellType());
assertEquals("2+3", destCell.getCellFormula());
assertEquals(srcCell.getCellStyle(), destCell.getCellStyle());
}
// Paste values only
final CellCopyPolicy policy = new CellCopyPolicy.Builder().cellFormula(false).build();
destCell.copyCellFrom(srcCell, policy);
- assertEquals(Cell.CELL_TYPE_NUMERIC, destCell.getCellType());
+ assertEquals(CellType.NUMERIC, destCell.getCellType());
}
@Test
assertEquals(srcCell.getCellStyle(), destCell.getCellStyle());
// Old cell value should not have been overwritten
- assertNotEquals(Cell.CELL_TYPE_BLANK, destCell.getCellType());
- assertEquals(Cell.CELL_TYPE_BOOLEAN, destCell.getCellType());
+ assertNotEquals(CellType.BLANK, destCell.getCellType());
+ assertEquals(CellType.BOOLEAN, destCell.getCellType());
assertEquals(true, destCell.getBooleanCellValue());
}
import org.apache.poi.ss.usermodel.BaseTestDataValidation;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType;
Cell cell_13 = row1.createCell(3);
- cell_13.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell_13.setCellType(CellType.NUMERIC);
cell_13.setCellValue(validationType==ValidationType.DECIMAL ? dvalue.doubleValue() : value.intValue());
String value1String = validationType==ValidationType.DECIMAL ? dvalue.toString() : value.toString();
- cell_13.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell_13.setCellType(CellType.NUMERIC);
cell_13.setCellValue(validationType==ValidationType.DECIMAL ? dvalue.doubleValue() : value.intValue());
String value2String = validationType==ValidationType.DECIMAL ? dvalue2.toString() : value2.toString();
- cell_14.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell_14.setCellType(CellType.NUMERIC);
cell_14.setCellValue(validationType==ValidationType.DECIMAL ? dvalue2.doubleValue() : value2.intValue());
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BaseTestFormulaEvaluator;
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.FormulaError;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
// sheet1 A1
XSSFCell cell = sheet1.createRow(0).createCell(0);
- cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell.setCellType(CellType.NUMERIC);
cell.setCellValue(1.0);
// sheet2 A1
cell = sheet2.createRow(0).createCell(0);
- cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell.setCellType(CellType.NUMERIC);
cell.setCellValue(1.0);
// sheet2 B1
cell = sheet2.getRow(0).createCell(1);
- cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell.setCellType(CellType.NUMERIC);
cell.setCellValue(1.0);
// sheet3 A1
cell = sheet3.createRow(0).createCell(0);
- cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell.setCellType(CellType.NUMERIC);
cell.setCellValue(1.0);
// sheet1 A2 formulae
cell = sheet1.createRow(1).createCell(0);
- cell.setCellType(Cell.CELL_TYPE_FORMULA);
+ cell.setCellType(CellType.FORMULA);
cell.setCellFormula("SUM(Sheet1:Sheet3!A1)");
// sheet1 A3 formulae
cell = sheet1.createRow(2).createCell(0);
- cell.setCellType(Cell.CELL_TYPE_FORMULA);
+ cell.setCellType(CellType.FORMULA);
cell.setCellFormula("SUM(Sheet1:Sheet3!A1:B1)");
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
- XSSFCell cellA2 = row2.createCell(0, Cell.CELL_TYPE_FORMULA);
- XSSFCell cellB1 = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
+ XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
+ XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
cellA2.setCellFormula("IF(B1=0,\"\",((ROW()-ROW(A$1))*12))");
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
- XSSFCell cellA2 = row2.createCell(0, Cell.CELL_TYPE_FORMULA);
- XSSFCell cellB1 = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
+ XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
+ XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
cellA2.setCellFormula("IF(B1=0,\"\",((ROW(A$1))))");
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
- XSSFCell cellA2 = row2.createCell(0, Cell.CELL_TYPE_FORMULA);
- XSSFCell cellB1 = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
+ XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
+ XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
- XSSFCell cellA2 = row2.createCell(0, Cell.CELL_TYPE_FORMULA);
- XSSFCell cellB1 = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
+ XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
+ XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
- XSSFCell cellA2 = row2.createCell(0, Cell.CELL_TYPE_FORMULA);
- XSSFCell cellB1 = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
+ XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
+ XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
- XSSFCell cellA2 = row2.createCell(0, Cell.CELL_TYPE_FORMULA);
- XSSFCell cellB1 = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
+ XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
+ XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
- XSSFCell cellA2 = row2.createCell(0, Cell.CELL_TYPE_FORMULA);
- XSSFCell cellB1 = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
+ XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
+ XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
- assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0,0).getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, getCell(sheet, 0,0).getCachedFormulaResultType());
assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0,0).getErrorCellValue());
- assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0,1).getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, getCell(sheet, 0,1).getCachedFormulaResultType());
assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0,1).getErrorCellValue());
wb.close();
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
- assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0, 0).getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, getCell(sheet, 0, 0).getCachedFormulaResultType());
assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0, 0).getErrorCellValue());
- assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 1, 0).getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, getCell(sheet, 1, 0).getCachedFormulaResultType());
assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 1, 0).getErrorCellValue());
- assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0, 3).getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, getCell(sheet, 0, 3).getCachedFormulaResultType());
assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0, 3).getErrorCellValue());
wb.close();
if (cell == null) {
cell = r.createCell(column);
}
- cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);
+ cell.setCellType(CellType.FORMULA);
cell.setCellFormula(formula);
}
assertEquals("MIN", toFormulaString(ptgs[1], fpb));
// Check we can round-trip - try to set a new one to a new single cell
- Cell newF = s1.getRow(0).createCell(10, Cell.CELL_TYPE_FORMULA);
+ Cell newF = s1.getRow(0).createCell(10, CellType.FORMULA);
newF.setCellFormula("SUM(Sheet2:Sheet3!A1)");
assertEquals("SUM(Sheet2:Sheet3!A1)", newF.getCellFormula());
// Check we can round-trip - try to set a new one to a cell range
- newF = s1.getRow(0).createCell(11, Cell.CELL_TYPE_FORMULA);
+ newF = s1.getRow(0).createCell(11, CellType.FORMULA);
newF.setCellFormula("MIN(Sheet1:Sheet2!A1:B2)");
assertEquals("MIN(Sheet1:Sheet2!A1:B2)", newF.getCellFormula());
for (Row row : xsheet) {
for (Cell cell : row) {
- if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
+ if (cell.getCellType() == CellType.FORMULA) {
try {
evaluator.evaluateFormulaCell(cell);
} catch (Exception e) {
==================================================================== */
package org.apache.poi.xssf.usermodel;
-import junit.framework.TestCase;
-
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.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotTableDefinition;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataConsolidateFunction;
+import junit.framework.TestCase;
+
public class TestXSSFPivotTable extends TestCase {
private XSSFPivotTable pivotTable;
private XSSFPivotTable offsetPivotTable;
*/
public void testAddDataColumnWithOffsetData() {
offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
- assertEquals(Cell.CELL_TYPE_NUMERIC, offsetOuterCell.getCellType());
+ assertEquals(CellType.NUMERIC, offsetOuterCell.getCellType());
offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 0);
}
import org.apache.poi.ss.usermodel.BaseTestXRow;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellCopyPolicy;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.XSSFITestDataProvider;
assertSame("existing references to externObserverRow are still valid", externObserverRow, sheet2.getRow(0));
// Make sure copyRowFrom actually copied row (this is tested elsewhere)
- assertEquals(Cell.CELL_TYPE_STRING, destRow.getCell(0).getCellType());
+ assertEquals(CellType.STRING, destRow.getCell(0).getCellType());
assertEquals("hello", destRow.getCell(0).getStringCellValue());
// We don't want #REF! errors if we copy a row that contains cells that are referred to by other cells outside of copied region
import org.apache.poi.ss.usermodel.BaseTestXSheet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellCopyPolicy;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.IgnoredErrorType;
// Blank
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Blank] C7 cell type", Cell.CELL_TYPE_BLANK, cell.getCellType());
+ assertEquals("[Blank] C7 cell type", CellType.BLANK, cell.getCellType());
// Error
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Error] D7 cell type", Cell.CELL_TYPE_ERROR, cell.getCellType());
+ assertEquals("[Error] D7 cell type", CellType.ERROR, cell.getCellType());
final FormulaError error = FormulaError.forInt(cell.getErrorCellValue());
assertEquals("[Error] D7 cell value", FormulaError.NA, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
// Date
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Date] E7 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Date] E7 cell type", CellType.NUMERIC, cell.getCellType());
final Date date = LocaleUtil.getLocaleCalendar(2000, Calendar.JANUARY, 1).getTime();
assertEquals("[Date] E7 cell value", date, cell.getDateCellValue());
// Boolean
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Boolean] F7 cell type", Cell.CELL_TYPE_BOOLEAN, cell.getCellType());
+ assertEquals("[Boolean] F7 cell type", CellType.BOOLEAN, cell.getCellType());
assertEquals("[Boolean] F7 cell value", true, cell.getBooleanCellValue());
// String
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[String] G7 cell type", Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals("[String] G7 cell type", CellType.STRING, cell.getCellType());
assertEquals("[String] G7 cell value", "Hello", cell.getStringCellValue());
// Int
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Int] H7 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Int] H7 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Int] H7 cell value", 15, (int) cell.getNumericCellValue());
// Float
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Float] I7 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Float] I7 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Float] I7 cell value", 12.5, cell.getNumericCellValue(), FLOAT_PRECISION);
// Cell Formula
cell = CellUtil.getCell(destRow, col++);
assertEquals("J7", new CellReference(cell).formatAsString());
- assertEquals("[Cell Formula] J7 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals("[Cell Formula] J7 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula] J7 cell formula", "5+2", cell.getCellFormula());
System.out.println("Cell formula evaluation currently unsupported");
cell = CellUtil.getCell(destRow, col++);
assertEquals("K7", new CellReference(cell).formatAsString());
assertEquals("[Cell Formula with Reference] K7 cell type",
- Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference] K7 cell formula",
"J7+H$2", cell.getCellFormula());
// Cell Formula with Reference spanning multiple rows
cell = CellUtil.getCell(destRow, col++);
assertEquals("[Cell Formula with Reference spanning multiple rows] L7 cell type",
- Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference spanning multiple rows] L7 cell formula",
"G7&\" \"&G8", cell.getCellFormula());
// Cell Formula with Reference spanning multiple rows
cell = CellUtil.getCell(destRow, col++);
assertEquals("[Cell Formula with Area Reference] M7 cell type",
- Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Area Reference] M7 cell formula",
"SUM(H7:I8)", cell.getCellFormula());
System.out.println("Array formulas currently unsupported");
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
/*
- assertEquals("[Array Formula] N7 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals("[Array Formula] N7 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Array Formula] N7 cell formula", "{SUM(H7:J7*{1,2,3})}", cell.getCellFormula());
*/
// Data Format
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Data Format] O7 cell type;", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Data Format] O7 cell type;", CellType.NUMERIC, cell.getCellType());
assertEquals("[Data Format] O7 cell value", 100.20, cell.getNumericCellValue(), FLOAT_PRECISION);
//FIXME: currently fails
final String moneyFormat = "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)";
// Blank
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Blank] C10 cell type", Cell.CELL_TYPE_BLANK, cell.getCellType());
+ assertEquals("[Blank] C10 cell type", CellType.BLANK, cell.getCellType());
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Blank] C11 cell type", Cell.CELL_TYPE_BLANK, cell.getCellType());
+ assertEquals("[Blank] C11 cell type", CellType.BLANK, cell.getCellType());
// Error
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Error] D10 cell type", Cell.CELL_TYPE_ERROR, cell.getCellType());
+ assertEquals("[Error] D10 cell type", CellType.ERROR, cell.getCellType());
FormulaError error = FormulaError.forInt(cell.getErrorCellValue());
assertEquals("[Error] D10 cell value", FormulaError.NA, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Error] D11 cell type", Cell.CELL_TYPE_ERROR, cell.getCellType());
+ assertEquals("[Error] D11 cell type", CellType.ERROR, cell.getCellType());
error = FormulaError.forInt(cell.getErrorCellValue());
assertEquals("[Error] D11 cell value", FormulaError.NAME, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
// Date
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Date] E10 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Date] E10 cell type", CellType.NUMERIC, cell.getCellType());
Date date = LocaleUtil.getLocaleCalendar(2000, Calendar.JANUARY, 1).getTime();
assertEquals("[Date] E10 cell value", date, cell.getDateCellValue());
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Date] E11 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Date] E11 cell type", CellType.NUMERIC, cell.getCellType());
date = LocaleUtil.getLocaleCalendar(2000, Calendar.JANUARY, 2).getTime();
assertEquals("[Date] E11 cell value", date, cell.getDateCellValue());
// Boolean
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Boolean] F10 cell type", Cell.CELL_TYPE_BOOLEAN, cell.getCellType());
+ assertEquals("[Boolean] F10 cell type", CellType.BOOLEAN, cell.getCellType());
assertEquals("[Boolean] F10 cell value", true, cell.getBooleanCellValue());
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Boolean] F11 cell type", Cell.CELL_TYPE_BOOLEAN, cell.getCellType());
+ assertEquals("[Boolean] F11 cell type", CellType.BOOLEAN, cell.getCellType());
assertEquals("[Boolean] F11 cell value", false, cell.getBooleanCellValue());
// String
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[String] G10 cell type", Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals("[String] G10 cell type", CellType.STRING, cell.getCellType());
assertEquals("[String] G10 cell value", "Hello", cell.getStringCellValue());
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[String] G11 cell type", Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals("[String] G11 cell type", CellType.STRING, cell.getCellType());
assertEquals("[String] G11 cell value", "World", cell.getStringCellValue());
// Int
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Int] H10 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Int] H10 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Int] H10 cell value", 15, (int) cell.getNumericCellValue());
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Int] H11 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Int] H11 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Int] H11 cell value", 42, (int) cell.getNumericCellValue());
// Float
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Float] I10 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Float] I10 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Float] I10 cell value", 12.5, cell.getNumericCellValue(), FLOAT_PRECISION);
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Float] I11 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Float] I11 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Float] I11 cell value", 5.5, cell.getNumericCellValue(), FLOAT_PRECISION);
// Cell Formula
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Cell Formula] J10 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals("[Cell Formula] J10 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula] J10 cell formula", "5+2", cell.getCellFormula());
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Cell Formula] J11 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals("[Cell Formula] J11 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula] J11 cell formula", "6+18", cell.getCellFormula());
// Cell Formula with Reference
// Formula row references should be adjusted by destRowNum-srcRowNum
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Cell Formula with Reference] K10 cell type",
- Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference] K10 cell formula",
"J10+H$2", cell.getCellFormula());
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Cell Formula with Reference] K11 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals("[Cell Formula with Reference] K11 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference] K11 cell formula", "J11+H$2", cell.getCellFormula());
// Cell Formula with Reference spanning multiple rows
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Cell Formula with Reference spanning multiple rows] L10 cell type",
- Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference spanning multiple rows] L10 cell formula",
"G10&\" \"&G11", cell.getCellFormula());
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell type",
- Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell formula",
"G11&\" \"&G12", cell.getCellFormula());
col++;
cell = CellUtil.getCell(destRow1, col);
assertEquals("[Cell Formula with Area Reference] M10 cell type",
- Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Area Reference] M10 cell formula",
"SUM(H10:I11)", cell.getCellFormula());
cell = CellUtil.getCell(destRow2, col);
assertEquals("[Cell Formula with Area Reference] M11 cell type",
- Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula with Area Reference] M11 cell formula",
"SUM($H$3:I10)", cell.getCellFormula()); //Also acceptable: SUM($H10:I$3), but this AreaReference isn't in ascending order
// System.out.println("Array formulas currently unsupported");
/*
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
- assertEquals("[Array Formula] N10 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals("[Array Formula] N10 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Array Formula] N10 cell formula", "{SUM(H10:J10*{1,2,3})}", cell.getCellFormula());
cell = CellUtil.getCell(destRow2, col);
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
- assertEquals("[Array Formula] N11 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals("[Array Formula] N11 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Array Formula] N11 cell formula", "{SUM(H11:J11*{1,2,3})}", cell.getCellFormula());
*/
// Data Format
col++;
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Data Format] O10 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals("[Data Format] O10 cell type", CellType.NUMERIC, cell.getCellType());
assertEquals("[Data Format] O10 cell value", 100.20, cell.getNumericCellValue(), FLOAT_PRECISION);
final String moneyFormat = "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)";
assertEquals("[Data Format] O10 cell data format", moneyFormat, cell.getCellStyle().getDataFormatString());
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
return;
}
Cell readCell = readRow.getCell(0);
- if(readCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
+ if(readCell.getCellType() == CellType.NUMERIC) {
assertEquals(expect, Double.toString(readCell.getNumericCellValue()));
} else {
assertEquals(expect, readCell.getStringCellValue());
package org.apache.poi.hwpf;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.FormulaParseException;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
/**
}
throw e;
}
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, result.getCellType());
+ assertEquals(CellType.NUMERIC, result.getCellType());
assertEquals(42.0, result.getNumberValue(), 0.0);
}
}
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.ss.formula.ptg.AttrPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.usermodel.CellType;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
break;
}
HSSFCell cell = row.getCell(0);
- if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
+ if (cell == null || cell.getCellType() == CellType.BLANK) {
break;
}
import org.apache.poi.ss.formula.ptg.RefPtg;
import org.apache.poi.ss.formula.SharedFormula;
import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.formula.FormulaParser;
import org.apache.poi.ss.formula.FormulaRenderer;
assertEquals("A$1*2", sheet.getRow(ROW_IX).getCell(1).getCellFormula());
cell = sheet.getRow(ROW_IX).getCell(1);
- cell.setCellType(HSSFCell.CELL_TYPE_BLANK);
+ cell.setCellType(CellType.BLANK);
assertEquals(3, countSharedFormulas(sheet));
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
private static void confirmCellEvaluation(HSSFWorkbook wb, HSSFCell cell, double expectedValue) {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue cv = fe.evaluate(cell);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(expectedValue, cv.getNumberValue(), 0.0);
}
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.formula.ptg.Ptg;
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.Row;
import org.junit.Test;
Iterator<Cell> it = row.cellIterator();
while(it.hasNext()) {
HSSFCell cell = (HSSFCell)it.next();
- if(cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
+ if(cell.getCellType() != CellType.FORMULA) {
continue;
}
FormulaRecordAggregate record = (FormulaRecordAggregate) cell.getCellValueRecord();
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
Cell cell = row.getCell(idxCell);
cell.getCellStyle().getDataFormatString();
- if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
+ if (cell.getCellType() == CellType.NUMERIC) {
boolean isDate = HSSFDateUtil.isCellDateFormatted(cell);
if (idxCell > 0 && isDate) {
fail("cell " + idxCell + " is not a date: " + idxCell.toString());
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import junit.framework.TestCase;
HSSFSheet lSheet = mainWorkbook.getSheetAt(0);
HSSFCell lA1Cell = lSheet.getRow(0).getCell(0);
- assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());
+ assertEquals(CellType.FORMULA, lA1Cell.getCellType());
HSSFFormulaEvaluator lMainWorkbookEvaluator = new HSSFFormulaEvaluator(mainWorkbook);
HSSFFormulaEvaluator lSourceEvaluator = new HSSFFormulaEvaluator(sourceWorkbook);
new String[]{MAIN_WORKBOOK_FILENAME, SOURCE_WORKBOOK_FILENAME},
new HSSFFormulaEvaluator[] {lMainWorkbookEvaluator, lSourceEvaluator});
- assertEquals(Cell.CELL_TYPE_NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell));
+ assertEquals(CellType.NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell));
assertEquals(20.0d, lA1Cell.getNumericCellValue(), 0.00001d);
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.RefPtg;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.LocaleUtil;
}
}
private Ptg[] getPtgs(HSSFCell cell) {
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals(FormulaRecordAggregate.class, cell.getCellValueRecord().getClass());
FormulaRecordAggregate agg = (FormulaRecordAggregate)cell.getCellValueRecord();
FormulaRecord rec = agg.getFormulaRecord();
import java.util.Iterator;
+import org.apache.poi.ss.usermodel.CellType;
+
import junit.framework.TestCase;
/**
for(Iterator cit = r.cellIterator(); cit.hasNext();) {
HSSFCell c = (HSSFCell)cit.next();
- if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
+ if(c.getCellType() == CellType.FORMULA) {
evaluator.evaluateFormulaCell(c);
// For testing - all should be numeric
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, evaluator.evaluateFormulaCell(c));
+ assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCell(c));
}
}
}
// Check now as expected
assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0);
assertEquals("SUM(A1:B1)", wb.getSheetAt(0).getRow(0).getCell(2).getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(0).getCell(2).getCellType());
+ assertEquals(CellType.FORMULA, wb.getSheetAt(0).getRow(0).getCell(2).getCellType());
assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0);
assertEquals("SUM(A2:B2)", wb.getSheetAt(0).getRow(1).getCell(2).getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(1).getCell(2).getCellType());
+ assertEquals(CellType.FORMULA, wb.getSheetAt(0).getRow(1).getCell(2).getCellType());
assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0);
assertEquals("'S1'!A1", wb.getSheetAt(1).getRow(0).getCell(0).getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(1).getRow(0).getCell(0).getCellType());
+ assertEquals(CellType.FORMULA, wb.getSheetAt(1).getRow(0).getCell(0).getCellType());
// Now do the alternate call, which zaps the formulas
for(Iterator cit = r.cellIterator(); cit.hasNext();) {
HSSFCell c = (HSSFCell)cit.next();
- if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
+ if(c.getCellType() == CellType.FORMULA) {
evaluator.evaluateInCell(c);
}
}
}
assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(0).getCell(2).getCellType());
+ assertEquals(CellType.NUMERIC, wb.getSheetAt(0).getRow(0).getCell(2).getCellType());
assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(1).getCell(2).getCellType());
+ assertEquals(CellType.NUMERIC, wb.getSheetAt(0).getRow(1).getCell(2).getCellType());
assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(1).getRow(0).getCell(0).getCellType());
+ assertEquals(CellType.NUMERIC, wb.getSheetAt(1).getRow(0).getCell(0).getCellType());
}
}
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.util.LocaleUtil;
import org.junit.AfterClass;
{ // formula cell
row = sheet.createRow(7);
HSSFCell cell = row.createCell(0);
- cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
+ cell.setCellType(CellType.FORMULA);
cell.setCellFormula("SUM(12.25,12.25)/100");
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat("##.00%;"));
HSSFRow row = sheet.getRow(0);
HSSFCell cellA1 = row.getCell(0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cellA1.getCellType());
+ assertEquals(CellType.NUMERIC, cellA1.getCellType());
assertEquals(2345.0, cellA1.getNumericCellValue(), 0.0001);
assertEquals("@", cellA1.getCellStyle().getDataFormatString());
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.BaseTestFormulaEvaluator;
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.FormulaError;
import org.junit.Test;
HSSFCell cell = sheet.getRow(8).getCell(0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue cv = fe.evaluate(cell);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(3.72, cv.getNumberValue(), 0.0);
wb.close();
}
try {
value = hsf.evaluate(cellA1);
- assertEquals(Cell.CELL_TYPE_NUMERIC, value.getCellType());
+ assertEquals(CellType.NUMERIC, value.getCellType());
assertEquals(5.33, value.getNumberValue(), 0.0);
} catch (RuntimeException e) {
// VLookup on a name in another file
cell = wb1.getSheetAt(0).getRow(1).getCell(2);
- assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(CellType.FORMULA, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
// WARNING - this is wrong!
// The file name should be showing, but bug #45970 is fixed
// Simple reference to a name in another file
cell = wb1.getSheetAt(0).getRow(1).getCell(4);
- assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(CellType.FORMULA, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(36.90, cell.getNumericCellValue(), 0.0001);
// TODO Correct this!
// The file name should be shown too, see bug #56742
// Re-check VLOOKUP one
cell = wb1.getSheetAt(0).getRow(1).getCell(2);
- assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(CellType.FORMULA, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(12.30, cell.getNumericCellValue(), 0.0001);
// Re-check ref one
cell = wb1.getSheetAt(0).getRow(1).getCell(4);
- assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(CellType.FORMULA, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(36.90, cell.getNumericCellValue(), 0.0001);
CellFormat cf = CellFormat.getInstance("General");
- // case Cell.CELL_TYPE_BLANK
+ // case CellType.BLANK
CellFormatResult result0 = cf.apply(cell0);
assertEquals("", result0.text);
- // case Cell.CELL_TYPE_BOOLEAN
+ // case CellType.BOOLEAN
cell1.setCellValue(true);
CellFormatResult result1 = cf.apply(cell1);
assertEquals("TRUE", result1.text);
- // case Cell.CELL_TYPE_NUMERIC
+ // case CellType.NUMERIC
cell2.setCellValue(1.23);
CellFormatResult result2 = cf.apply(cell2);
assertEquals("1.23", result2.text);
CellFormatResult result3 = cf.apply(cell3);
assertEquals("123", result3.text);
- // case Cell.CELL_TYPE_STRING
+ // case CellType.STRING
cell4.setCellValue("abc");
CellFormatResult result4 = cf.apply(cell4);
assertEquals("abc", result4.text);
CellFormat cf = CellFormat.getInstance("@");
- // case Cell.CELL_TYPE_BLANK
+ // case CellType.BLANK
CellFormatResult result0 = cf.apply(cell0);
assertEquals("", result0.text);
- // case Cell.CELL_TYPE_BOOLEAN
+ // case CellType.BOOLEAN
cell1.setCellValue(true);
CellFormatResult result1 = cf.apply(cell1);
assertEquals("TRUE", result1.text);
- // case Cell.CELL_TYPE_NUMERIC
+ // case CellType.NUMERIC
cell2.setCellValue(1.23);
CellFormatResult result2 = cf.apply(cell2);
assertEquals("1.23", result2.text);
CellFormatResult result3 = cf.apply(cell3);
assertEquals("123", result3.text);
- // case Cell.CELL_TYPE_STRING
+ // case CellType.STRING
cell4.setCellValue("abc");
CellFormatResult result4 = cf.apply(cell4);
assertEquals("abc", result4.text);
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
- // case Cell.CELL_TYPE_BLANK
+ // case CellType.BLANK
CellFormatResult result0 = cf.apply(label0, cell0);
assertEquals("", result0.text);
assertEquals("", label0.getText());
- // case Cell.CELL_TYPE_BOOLEAN
+ // case CellType.BOOLEAN
cell1.setCellValue(true);
CellFormatResult result1 = cf.apply(label1, cell1);
assertEquals("TRUE", result1.text);
assertEquals("TRUE", label1.getText());
- // case Cell.CELL_TYPE_NUMERIC
+ // case CellType.NUMERIC
cell2.setCellValue(1.23);
CellFormatResult result2 = cf.apply(label2, cell2);
assertEquals("1.23", result2.text);
assertEquals("123", result3.text);
assertEquals("123", label3.getText());
- // case Cell.CELL_TYPE_STRING
+ // case CellType.STRING
cell4.setCellValue("abc");
CellFormatResult result4 = cf.apply(label4, cell4);
assertEquals("abc", result4.text);
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
- // case Cell.CELL_TYPE_BLANK
+ // case CellType.BLANK
CellFormatResult result0 = cf.apply(label0, cell0);
assertEquals("", result0.text);
assertEquals("", label0.getText());
- // case Cell.CELL_TYPE_BOOLEAN
+ // case CellType.BOOLEAN
cell1.setCellValue(true);
CellFormatResult result1 = cf.apply(label1, cell1);
assertEquals("TRUE", result1.text);
assertEquals("TRUE", label1.getText());
- // case Cell.CELL_TYPE_NUMERIC
+ // case CellType.NUMERIC
cell2.setCellValue(1.23);
CellFormatResult result2 = cf.apply(label2, cell2);
assertEquals("1.23", result2.text);
assertEquals("123", result3.text);
assertEquals("123", label3.getText());
- // case Cell.CELL_TYPE_STRING
+ // case CellType.STRING
cell4.setCellValue("abc");
CellFormatResult result4 = cf.apply(label4, cell4);
assertEquals("abc", result4.text);
==================================================================== */
package org.apache.poi.ss.formula;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
import org.apache.poi.ss.formula.udf.DefaultUDFFinder;
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.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
Cell cell2 = sh.getRow(2).getCell(1);
assertEquals("ISODD(2)", cell2.getCellFormula());
assertEquals(false, evaluator.evaluate(cell2).getBooleanValue());
- assertEquals(Cell.CELL_TYPE_BOOLEAN, evaluator.evaluateFormulaCell(cell2));
+ assertEquals(CellType.BOOLEAN, evaluator.evaluateFormulaCell(cell2));
Cell cell3 = sh.getRow(3).getCell(1);
assertEquals("ISEVEN(2)", cell3.getCellFormula());
assertEquals(true, evaluator.evaluate(cell3).getBooleanValue());
- assertEquals(Cell.CELL_TYPE_BOOLEAN, evaluator.evaluateFormulaCell(cell3));
+ assertEquals(CellType.BOOLEAN, evaluator.evaluateFormulaCell(cell3));
wb.close();
}
public void setCellValue(String cellRefText, double value) {
HSSFCell cell = getOrCreateCell(cellRefText);
// be sure to blank cell, in case it is currently a formula
- cell.setCellType(HSSFCell.CELL_TYPE_BLANK);
+ cell.setCellType(CellType.BLANK);
// otherwise this line will only set the formula cached result;
cell.setCellValue(value);
_evaluator.notifyUpdateCell(wrapCell(cell));
}
public void clearCell(String cellRefText) {
HSSFCell cell = getOrCreateCell(cellRefText);
- cell.setCellType(HSSFCell.CELL_TYPE_BLANK);
+ cell.setCellType(CellType.BLANK);
_evaluator.notifyUpdateCell(wrapCell(cell));
}
cv = fe.evaluate(cellA1);
assertEquals(3.7, cv.getNumberValue(), 0.0);
- cellB1.setCellType(HSSFCell.CELL_TYPE_BLANK);
+ cellB1.setCellType(CellType.BLANK);
fe.notifyUpdateCell(cellB1);
cv = fe.evaluate(cellA1); // B1 was used to evaluate A1
assertEquals(2.2, cv.getNumberValue(), 0.0);
\r
import org.apache.poi.hssf.HSSFTestDataSamples;\r
import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.CellType;\r
import org.apache.poi.ss.usermodel.FormulaEvaluator;\r
import org.apache.poi.ss.usermodel.Row;\r
import org.apache.poi.ss.usermodel.Sheet;\r
Row lARow = lSheet.getRow(0);\r
Cell lA1Cell = lARow.getCell(0);\r
\r
- assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());\r
+ assertEquals(CellType.FORMULA, lA1Cell.getCellType());\r
try {\r
evaluator.evaluateFormulaCell(lA1Cell);\r
fail("Missing external workbook reference exception expected!");\r
Cell lB1Cell = lSheet.getRow(1).getCell(0);\r
Cell lC1Cell = lSheet.getRow(2).getCell(0);\r
\r
- assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());\r
- assertEquals(Cell.CELL_TYPE_FORMULA, lB1Cell.getCellType());\r
- assertEquals(Cell.CELL_TYPE_FORMULA, lC1Cell.getCellType());\r
+ assertEquals(CellType.FORMULA, lA1Cell.getCellType());\r
+ assertEquals(CellType.FORMULA, lB1Cell.getCellType());\r
+ assertEquals(CellType.FORMULA, lC1Cell.getCellType());\r
\r
// Check cached values\r
assertEquals(10.0d, lA1Cell.getNumericCellValue(), 0.00001d);\r
FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
evaluator.setIgnoreMissingWorkbooks(true);\r
\r
- assertEquals(Cell.CELL_TYPE_NUMERIC, evaluator.evaluateFormulaCell(lA1Cell));\r
- assertEquals(Cell.CELL_TYPE_STRING, evaluator.evaluateFormulaCell(lB1Cell));\r
- assertEquals(Cell.CELL_TYPE_BOOLEAN, evaluator.evaluateFormulaCell(lC1Cell));\r
+ assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCell(lA1Cell));\r
+ assertEquals(CellType.STRING, evaluator.evaluateFormulaCell(lB1Cell));\r
+ assertEquals(CellType.BOOLEAN, evaluator.evaluateFormulaCell(lC1Cell));\r
\r
assertEquals(10.0d, lA1Cell.getNumericCellValue(), 0.00001d);\r
assertEquals("POI rocks!", lB1Cell.getStringCellValue());\r
Cell lB1Cell = lSheet.getRow(1).getCell(0);\r
Cell lC1Cell = lSheet.getRow(2).getCell(0);\r
\r
- assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());\r
- assertEquals(Cell.CELL_TYPE_FORMULA, lB1Cell.getCellType());\r
- assertEquals(Cell.CELL_TYPE_FORMULA, lC1Cell.getCellType());\r
+ assertEquals(CellType.FORMULA, lA1Cell.getCellType());\r
+ assertEquals(CellType.FORMULA, lB1Cell.getCellType());\r
+ assertEquals(CellType.FORMULA, lC1Cell.getCellType());\r
\r
FormulaEvaluator lMainWorkbookEvaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
FormulaEvaluator lSourceEvaluator = sourceWorkbook.getCreationHelper().createFormulaEvaluator();\r
workbooks.put(SOURCE_DUMMY_WORKBOOK_FILENAME, lSourceEvaluator);\r
lMainWorkbookEvaluator.setupReferencedWorkbooks(workbooks);\r
\r
- assertEquals(Cell.CELL_TYPE_NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell));\r
- assertEquals(Cell.CELL_TYPE_STRING, lMainWorkbookEvaluator.evaluateFormulaCell(lB1Cell));\r
- assertEquals(Cell.CELL_TYPE_BOOLEAN, lMainWorkbookEvaluator.evaluateFormulaCell(lC1Cell));\r
+ assertEquals(CellType.NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell));\r
+ assertEquals(CellType.STRING, lMainWorkbookEvaluator.evaluateFormulaCell(lB1Cell));\r
+ assertEquals(CellType.BOOLEAN, lMainWorkbookEvaluator.evaluateFormulaCell(lC1Cell));\r
\r
assertEquals(20.0d, lA1Cell.getNumericCellValue(), 0.00001d);\r
assertEquals("Apache rocks!", lB1Cell.getStringCellValue());\r
==================================================================== */
package org.apache.poi.ss.formula.atp;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellReference;
+import junit.framework.TestCase;
+
/**
* Testcase for 'Analysis Toolpak' function IFERROR()
*
Row row2 = sh.createRow(1);
// Create cells
- row1.createCell(0, Cell.CELL_TYPE_NUMERIC);
- row1.createCell(1, Cell.CELL_TYPE_NUMERIC);
- row1.createCell(2, Cell.CELL_TYPE_NUMERIC);
- row2.createCell(0, Cell.CELL_TYPE_NUMERIC);
- row2.createCell(1, Cell.CELL_TYPE_NUMERIC);
+ row1.createCell(0, CellType.NUMERIC);
+ row1.createCell(1, CellType.NUMERIC);
+ row1.createCell(2, CellType.NUMERIC);
+ row2.createCell(0, CellType.NUMERIC);
+ row2.createCell(1, CellType.NUMERIC);
// Create references
CellReference a1 = new CellReference("A1");
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
assertEquals("Checks that the cell is numeric",
- Cell.CELL_TYPE_NUMERIC, evaluator.evaluate(cell1).getCellType());
+ CellType.NUMERIC, evaluator.evaluate(cell1).getCellType());
assertEquals("Divides 210 by 35 and returns 6.0",
6.0, evaluator.evaluate(cell1).getNumberValue(), accuracy);
assertEquals("Checks that the cell is numeric",
- Cell.CELL_TYPE_STRING, evaluator.evaluate(cell2).getCellType());
+ CellType.STRING, evaluator.evaluate(cell2).getCellType());
assertEquals("Rounds -10 to a nearest multiple of -3 (-9)",
"Error in calculation", evaluator.evaluate(cell2).getStringValue());
assertEquals("Check that C1 returns string",
- Cell.CELL_TYPE_STRING, evaluator.evaluate(cell3).getCellType());
+ CellType.STRING, evaluator.evaluate(cell3).getCellType());
assertEquals("Check that C1 returns string \"error\"",
"error", evaluator.evaluate(cell3).getStringValue());
}
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
Row row = sheet.createRow(0);
bottomValueCell = row.createCell(0);
topValueCell = row.createCell(1);
- formulaCell = row.createCell(2, Cell.CELL_TYPE_FORMULA);
+ formulaCell = row.createCell(2, CellType.FORMULA);
}
@Override
public void testRandBetweenTopBlank() {
bottomValueCell.setCellValue(-1);
- topValueCell.setCellType(Cell.CELL_TYPE_BLANK);
+ topValueCell.setCellType(CellType.BLANK);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell);
- assertEquals(Cell.CELL_TYPE_ERROR, formulaCell.getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue());
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell);
- assertEquals(Cell.CELL_TYPE_ERROR, formulaCell.getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue());
// Check case where both inputs are of wrong type
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell);
- assertEquals(Cell.CELL_TYPE_ERROR, formulaCell.getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), formulaCell.getErrorCellValue());
}
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell);
- assertEquals(Cell.CELL_TYPE_ERROR, formulaCell.getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue());
bottomValueCell.setCellValue(1);
- topValueCell.setCellType(Cell.CELL_TYPE_BLANK);
+ topValueCell.setCellType(CellType.BLANK);
formulaCell.setCellFormula("RANDBETWEEN($A$1,$B$1)");
evaluator.clearAllCachedResultValues();
evaluator.evaluateFormulaCell(formulaCell);
- assertEquals(Cell.CELL_TYPE_ERROR, formulaCell.getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, formulaCell.getCachedFormulaResultType());
assertEquals(ErrorEval.NUM_ERROR.getErrorCode(), formulaCell.getErrorCellValue());
}
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.eval.EvaluationException;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.util.LocaleUtil;
import org.junit.Test;
HSSFRow row = (HSSFRow) rowIterator.next();
HSSFCell cell = row.getCell(SS.YEARFRAC_FORMULA_COLUMN);
- if (cell == null || cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
+ if (cell == null || cell.getCellType() != CellType.FORMULA) {
continue;
}
processRow(row, cell, formulaEvaluator);
import org.apache.poi.ss.ITestDataProvider;
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.Row;
* Makes sure that the specified evaluated cell value represents a circular reference error.
*/
private static void confirmCycleErrorCode(CellValue cellValue) {
- assertTrue(cellValue.getCellType() == Cell.CELL_TYPE_ERROR);
+ assertTrue(cellValue.getCellType() == CellType.ERROR);
assertEquals(ErrorEval.CIRCULAR_REF_ERROR.getErrorCode(), cellValue.getErrorValue());
}
CellValue cellValue = evaluateWithCycles(wb, testCell);
- assertTrue(cellValue.getCellType() == Cell.CELL_TYPE_NUMERIC);
+ assertTrue(cellValue.getCellType() == CellType.NUMERIC);
assertEquals(2, cellValue.getNumberValue(), 0);
wb.close();
}
// Happy day flow - evaluate A1 first
cv = fe.evaluate(cellA1);
- assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(42.0, cv.getNumberValue(), 0.0);
cv = fe.evaluate(cellB1); // no circ-ref-error because A1 result is cached
- assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(46.0, cv.getNumberValue(), 0.0);
// Show the bug - evaluate another cell from the loop first
cv = fe.evaluate(cellB1);
// Identified bug 46898
assertNotEquals(cv.getCellType(), ErrorEval.CIRCULAR_REF_ERROR.getErrorCode());
- assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(46.0, cv.getNumberValue(), 0.0);
// start evaluation on another cell
fe.clearAllCachedResultValues();
cv = fe.evaluate(cellE1);
- assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(43.0, cv.getNumberValue(), 0.0);
wb.close();
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
CellValue cv = fe.evaluate(cell);
- assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(3.0, cv.getNumberValue(), 0.0);
wb.close();
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
CellValue cv;
cv = fe.evaluate(cell);
- assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(1.0, cv.getNumberValue(), 0.0);
cv = fe.evaluate(row.getCell(1));
- assertEquals(Cell.CELL_TYPE_BOOLEAN, cv.getCellType());
+ assertEquals(CellType.BOOLEAN, cv.getCellType());
assertEquals(true, cv.getBooleanValue());
wb.close();
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
CellValue cv = fe.evaluate(cell);
- assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
wb.close();
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
/**
// else some other unexpected error
throw e;
}
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(CellType.NUMERIC, cv.getCellType());
assertEquals(0.5, cv.getNumberValue(), 0.0);
}
}
HSSFWorkbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("test");
Row row1 = sheet.createRow(0);
- Cell cellA1 = row1.createCell(0, Cell.CELL_TYPE_FORMULA);
- Cell cellB1 = row1.createCell(1, Cell.CELL_TYPE_NUMERIC);
- Cell cellC1 = row1.createCell(2, Cell.CELL_TYPE_NUMERIC);
- Cell cellD1 = row1.createCell(3, Cell.CELL_TYPE_NUMERIC);
- Cell cellE1 = row1.createCell(4, Cell.CELL_TYPE_NUMERIC);
+ Cell cellA1 = row1.createCell(0, CellType.FORMULA);
+ Cell cellB1 = row1.createCell(1, CellType.NUMERIC);
+ Cell cellC1 = row1.createCell(2, CellType.NUMERIC);
+ Cell cellD1 = row1.createCell(3, CellType.NUMERIC);
+ Cell cellE1 = row1.createCell(4, CellType.NUMERIC);
cellB1.setCellValue(1);
cellC1.setCellValue(1);
cellD1.setCellValue(2);
HSSFWorkbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("test");
Row row1 = sheet.createRow(0);
- Cell cellA1 = row1.createCell(0, Cell.CELL_TYPE_FORMULA);
+ Cell cellA1 = row1.createCell(0, CellType.FORMULA);
cellA1.setCellFormula("COUNTIFS()");
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
CellValue evaluate = evaluator.evaluate(cellA1);
import org.apache.poi.hssf.usermodel.HSSFCell;\r
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;\r
import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+import org.apache.poi.ss.usermodel.CellType;\r
import org.apache.poi.ss.usermodel.CellValue;\r
\r
import junit.framework.TestCase;\r
cell.setCellFormula(formulaText);\r
fe.notifyUpdateCell(cell);\r
CellValue result = fe.evaluate(cell);\r
- assertEquals(result.getCellType(), HSSFCell.CELL_TYPE_STRING);\r
+ assertEquals(result.getCellType(), CellType.STRING);\r
assertEquals(expectedResult, result.getStringValue());\r
}\r
}\r
package org.apache.poi.ss.formula.functions;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
/**
* Test for YEAR / MONTH / DAY / HOUR / MINUTE / SECOND
*/
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
cell11 = sheet.createRow(0).createCell(0);
- cell11.setCellType(HSSFCell.CELL_TYPE_FORMULA);
+ cell11.setCellType(CellType.FORMULA);
evaluator = new HSSFFormulaEvaluator(wb);
}
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
- if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
+ if (cv.getCellType() != CellType.NUMERIC) {
throw new AssertionFailedError("Wrong result type: " + cv.formatAsString());
}
double actualValue = cv.getNumberValue();
import org.apache.poi.hssf.usermodel.HSSFCell;\r
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;\r
import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+import org.apache.poi.ss.usermodel.CellType;\r
import org.apache.poi.ss.usermodel.CellValue;\r
\r
import junit.framework.TestCase;\r
cell.setCellFormula(formulaText);\r
fe.notifyUpdateCell(cell);\r
CellValue result = fe.evaluate(cell);\r
- assertEquals(result.getCellType(), HSSFCell.CELL_TYPE_STRING);\r
+ assertEquals(result.getCellType(), CellType.STRING);\r
assertEquals(expectedResult, result.getStringValue());\r
}\r
}\r
package org.apache.poi.ss.formula.functions;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate;
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
-import org.apache.poi.hssf.usermodel.HSSFRow;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+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.util.CellReference;
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
/**
* Test cases for COUNT(), COUNTA() COUNTIF(), COUNTBLANK()
*/
for (int rowIx=7; rowIx<=12; rowIx++) {
HSSFRow row = sheet1.getRow(rowIx-1);
HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, cellA.getCellType());
+ assertEquals(CellType.FORMULA, cellA.getCellType());
HSSFCell cellC = row.getCell(2); // cell with a reference value
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cellC.getCellType());
+ assertEquals(CellType.NUMERIC, cellC.getCellType());
CellValue cv = fe.evaluate(cellA);
double actualValue = cv.getNumberValue();
for (int rowIx=9; rowIx<=14; rowIx++) {
HSSFRow row = sheet2.getRow(rowIx-1);
HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, cellA.getCellType());
+ assertEquals(CellType.FORMULA, cellA.getCellType());
HSSFCell cellC = row.getCell(2); // cell with a reference value
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cellC.getCellType());
+ assertEquals(CellType.NUMERIC, cellC.getCellType());
CellValue cv = fe.evaluate(cellA);
double actualValue = cv.getNumberValue();
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
/**
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
cell11 = sheet.createRow(0).createCell(0);
- cell11.setCellType(HSSFCell.CELL_TYPE_FORMULA);
+ cell11.setCellType(CellType.FORMULA);
evaluator = new HSSFFormulaEvaluator(wb);
}
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
- if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
+ if (cv.getCellType() != CellType.NUMERIC) {
throw new AssertionFailedError("Wrong result type: " + cv.formatAsString());
}
double actualValue = cv.getNumberValue();
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaError;
import org.junit.Test;
cell.setCellFormula(formulaText);
fe.notifyUpdateCell(cell);
CellValue result = fe.evaluate(cell);
- assertEquals(result.getCellType(), HSSFCell.CELL_TYPE_NUMERIC);
+ assertEquals(result.getCellType(), CellType.NUMERIC);
assertEquals(expectedResult, result.getNumberValue(), 0.0);
}
cell.setCellFormula(formulaText);
fe.notifyUpdateCell(cell);
CellValue result = fe.evaluate(cell);
- assertEquals(result.getCellType(), HSSFCell.CELL_TYPE_ERROR);
+ assertEquals(result.getCellType(), CellType.ERROR);
assertEquals(expectedErrorCode.getCode(), result.getErrorValue());
}
}
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
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.ss.usermodel.FormulaError;
import org.junit.Before;
try {
HSSFSheet sheet = wb.createSheet("new sheet");
cell11 = sheet.createRow(0).createCell(0);
- cell11.setCellType(HSSFCell.CELL_TYPE_FORMULA);
+ cell11.setCellType(CellType.FORMULA);
evaluator = new HSSFFormulaEvaluator(wb);
} finally {
wb.close();
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
- assertEquals("Wrong result type: " + cv.formatAsString(), Cell.CELL_TYPE_STRING, cv.getCellType());
+ assertEquals("Wrong result type: " + cv.formatAsString(), CellType.STRING, cv.getCellType());
String actualValue = cv.getStringValue();
assertEquals(expectedResult, actualValue);
}
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
assertTrue("Wrong result type: " + cv.formatAsString(),
- cv.getCellType() == Cell.CELL_TYPE_ERROR
+ cv.getCellType() == CellType.ERROR
&& cv.getErrorValue() == FormulaError.VALUE.getCode());
}
}
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.eval.ErrorEval;
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.junit.Test;
fe.clearAllCachedResultValues();
cell.setCellFormula(formula);
CellValue cv = fe.evaluate(cell);
- if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
+ if (cv.getCellType() != CellType.NUMERIC) {
fail("expected numeric cell type but got " + cv.formatAsString());
}
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
fe.clearAllCachedResultValues();
cell.setCellFormula(formula);
CellValue cv = fe.evaluate(cell);
- if (cv.getCellType() != Cell.CELL_TYPE_ERROR) {
+ if (cv.getCellType() != CellType.ERROR) {
fail("expected error cell type but got " + cv.formatAsString());
}
int expCode = expectedResult.getErrorCode();
package org.apache.poi.ss.formula.functions;
-import junit.framework.TestCase;
-import junit.framework.AssertionFailedError;
-import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
/**
* Tests for {@link Irr}
*
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(), HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals("Invalid formula result: " + cv.toString(), CellType.NUMERIC, cv.getCellType());
assertEquals(expectedValue, actualValue, 1E-4); // should agree within 0.01%
}
}
package org.apache.poi.ss.formula.functions;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
+
+import junit.framework.TestCase;
/**
* Tests for Excel function ISBLANK()
*
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue result = fe.evaluate(cell);
- assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
+ assertEquals(CellType.BOOLEAN, result.getCellType());
assertEquals(true, result.getBooleanValue());
cell.setCellFormula("isblank(D7:D7)");
result = fe.evaluate(cell);
- assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
+ assertEquals(CellType.BOOLEAN, result.getCellType());
assertEquals(true, result.getBooleanValue());
}
}
\r
import java.io.IOException;\r
\r
-import junit.framework.TestCase;\r
import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.CellType;\r
import org.apache.poi.ss.usermodel.CellValue;\r
import org.apache.poi.ss.usermodel.FormulaEvaluator;\r
import org.apache.poi.ss.usermodel.Row;\r
import org.apache.poi.ss.usermodel.Workbook;\r
import org.apache.poi.ss.util.CellReference;\r
\r
+import junit.framework.TestCase;\r
+\r
/**\r
* LogicalFunction unit tests.\r
*/\r
Row row2 = sh.createRow(1);\r
row3 = sh.createRow(2);\r
\r
- row1.createCell(0, Cell.CELL_TYPE_NUMERIC);\r
- row1.createCell(1, Cell.CELL_TYPE_NUMERIC);\r
+ row1.createCell(0, CellType.NUMERIC);\r
+ row1.createCell(1, CellType.NUMERIC);\r
\r
- row2.createCell(0, Cell.CELL_TYPE_NUMERIC);\r
- row2.createCell(1, Cell.CELL_TYPE_NUMERIC);\r
+ row2.createCell(0, CellType.NUMERIC);\r
+ row2.createCell(1, CellType.NUMERIC);\r
\r
row3.createCell(0);\r
row3.createCell(1);\r
\r
package org.apache.poi.ss.formula.functions;\r
\r
-import junit.framework.AssertionFailedError;\r
-import junit.framework.TestCase;\r
-\r
import org.apache.poi.hssf.HSSFTestDataSamples;\r
import org.apache.poi.hssf.usermodel.HSSFCell;\r
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;\r
import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
import org.apache.poi.ss.formula.eval.ErrorEval;\r
import org.apache.poi.ss.formula.eval.EvaluationException;\r
+import org.apache.poi.ss.usermodel.CellType;\r
import org.apache.poi.ss.usermodel.CellValue;\r
\r
+import junit.framework.AssertionFailedError;\r
+import junit.framework.TestCase;\r
+\r
/**\r
* Tests for {@link org.apache.poi.ss.formula.functions.Mirr}\r
*\r
private static void assertFormulaResult(CellValue cv, HSSFCell cell) {\r
double actualValue = cv.getNumberValue();\r
double expectedValue = cell.getNumericCellValue(); // cached formula result calculated by Excel\r
- assertEquals("Invalid formula result: " + cv.toString(), HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());\r
+ assertEquals("Invalid formula result: " + cv.toString(), CellType.NUMERIC, cv.getCellType());\r
assertEquals(expectedValue, actualValue, 1E-8);\r
}\r
}\r
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.FormulaError;
import org.junit.Test;
cell.setCellFormula("NPER(12,4500,100000,100000)");
cell.setCellValue(15.0);
assertEquals("NPER(12,4500,100000,100000)", cell.getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
+ assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType());
assertEquals(15.0, cell.getNumericCellValue(), 0.0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
fe.evaluateFormulaCell(cell);
- assertEquals(HSSFCell.CELL_TYPE_ERROR, cell.getCachedFormulaResultType());
+ assertEquals(CellType.ERROR, cell.getCachedFormulaResultType());
assertEquals(FormulaError.NUM.getCode(), cell.getErrorCellValue());
wb.close();
}
==================================================================== */
package org.apache.poi.ss.formula.udf;
-import static org.junit.Assert.assertNotNull;
-
import org.apache.poi.ss.formula.atp.AnalysisToolPak;
-import org.apache.poi.ss.formula.functions.FreeRefFunction;
-
import org.junit.Test;
public class TestAggregatingUDFFinder extends BaseTestUDFFinder {
==================================================================== */
package org.apache.poi.ss.formula.udf;
-import static org.junit.Assert.assertNotNull;
-
import org.apache.poi.ss.formula.functions.FreeRefFunction;
-
import org.junit.Test;
public class TestDefaultUDFFinder extends BaseTestUDFFinder {
Cell cell0 = row.createCell(0);
cell0.setCellValue(Double.NaN);
- assertEquals("Double.NaN should change cell type to CELL_TYPE_ERROR", CellType.ERROR, cell0.getCellType());
+ assertEquals("Double.NaN should change cell type to CellType#ERROR", CellType.ERROR, cell0.getCellType());
assertEquals("Double.NaN should change cell value to #NUM!", FormulaError.NUM, forInt(cell0.getErrorCellValue()));
Cell cell1 = row.createCell(1);
cell1.setCellValue(Double.POSITIVE_INFINITY);
- assertEquals("Double.POSITIVE_INFINITY should change cell type to CELL_TYPE_ERROR", CellType.ERROR, cell1.getCellType());
+ assertEquals("Double.POSITIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell1.getCellType());
assertEquals("Double.POSITIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell1.getErrorCellValue()));
Cell cell2 = row.createCell(2);
cell2.setCellValue(Double.NEGATIVE_INFINITY);
- assertEquals("Double.NEGATIVE_INFINITY should change cell type to CELL_TYPE_ERROR", CellType.ERROR, cell2.getCellType());
+ assertEquals("Double.NEGATIVE_INFINITY should change cell type to CellType#ERROR", CellType.ERROR, cell2.getCellType());
assertEquals("Double.NEGATIVE_INFINITY should change cell value to #DIV/0!", FormulaError.DIV0, forInt(cell2.getErrorCellValue()));
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
// 5 -> num
row.createCell(0).setCellValue("test");
row.createCell(1).setCellValue(3.2);
- row.createCell(4, Cell.CELL_TYPE_BLANK);
+ row.createCell(4, CellType.BLANK);
row.createCell(5).setCellValue(4);
// First up, no policy given, uses default
- assertEquals(Cell.CELL_TYPE_STRING, row.getCell(0).getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
+ assertEquals(CellType.STRING, row.getCell(0).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(1).getCellType());
assertEquals(null, row.getCell(2));
assertEquals(null, row.getCell(3));
- assertEquals(Cell.CELL_TYPE_BLANK, row.getCell(4).getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType());
+ assertEquals(CellType.BLANK, row.getCell(4).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(5).getCellType());
// RETURN_NULL_AND_BLANK - same as default
- assertEquals(Cell.CELL_TYPE_STRING, row.getCell(0, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
+ assertEquals(CellType.STRING, row.getCell(0, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(1, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
assertEquals(null, row.getCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK));
assertEquals(null, row.getCell(3, MissingCellPolicy.RETURN_NULL_AND_BLANK));
- assertEquals(Cell.CELL_TYPE_BLANK, row.getCell(4, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
+ assertEquals(CellType.BLANK, row.getCell(4, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(5, MissingCellPolicy.RETURN_NULL_AND_BLANK).getCellType());
// RETURN_BLANK_AS_NULL - nearly the same
- assertEquals(Cell.CELL_TYPE_STRING, row.getCell(0, MissingCellPolicy.RETURN_BLANK_AS_NULL).getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1, MissingCellPolicy.RETURN_BLANK_AS_NULL).getCellType());
+ assertEquals(CellType.STRING, row.getCell(0, MissingCellPolicy.RETURN_BLANK_AS_NULL).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(1, MissingCellPolicy.RETURN_BLANK_AS_NULL).getCellType());
assertEquals(null, row.getCell(2, MissingCellPolicy.RETURN_BLANK_AS_NULL));
assertEquals(null, row.getCell(3, MissingCellPolicy.RETURN_BLANK_AS_NULL));
assertEquals(null, row.getCell(4, MissingCellPolicy.RETURN_BLANK_AS_NULL));
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5, MissingCellPolicy.RETURN_BLANK_AS_NULL).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(5, MissingCellPolicy.RETURN_BLANK_AS_NULL).getCellType());
// CREATE_NULL_AS_BLANK - creates as needed
- assertEquals(Cell.CELL_TYPE_STRING, row.getCell(0, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
- assertEquals(Cell.CELL_TYPE_BLANK, row.getCell(2, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
- assertEquals(Cell.CELL_TYPE_BLANK, row.getCell(3, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
- assertEquals(Cell.CELL_TYPE_BLANK, row.getCell(4, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
+ assertEquals(CellType.STRING, row.getCell(0, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(1, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
+ assertEquals(CellType.BLANK, row.getCell(2, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
+ assertEquals(CellType.BLANK, row.getCell(3, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
+ assertEquals(CellType.BLANK, row.getCell(4, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(5, MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellType());
// Check created ones get the right column
assertEquals(0, row.getCell(0, MissingCellPolicy.CREATE_NULL_AS_BLANK).getColumnIndex());
// that that is now used if no policy given
workbook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
- assertEquals(Cell.CELL_TYPE_STRING, row.getCell(0).getCellType());
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
+ assertEquals(CellType.STRING, row.getCell(0).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(1).getCellType());
assertEquals(null, row.getCell(2));
assertEquals(null, row.getCell(3));
assertEquals(null, row.getCell(4));
- assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType());
+ assertEquals(CellType.NUMERIC, row.getCell(5).getCellType());
workbook.close();
}
assertFalse(it.hasNext());
// Add another cell, specifying the cellType
- Cell cell5 = row.createCell(2, Cell.CELL_TYPE_STRING);
+ Cell cell5 = row.createCell(2, CellType.STRING);
it = row.cellIterator();
assertNotNull(cell5);
assertTrue(it.hasNext());
assertTrue(cell5 == it.next());
assertTrue(it.hasNext());
assertTrue(cell2 == it.next());
- assertEquals(Cell.CELL_TYPE_STRING, cell5.getCellType());
+ assertEquals(CellType.STRING, cell5.getCellType());
wb.close();
}
Sheet sheet = workbook.getSheetAt(i);
for (Row r : sheet) {
for (Cell c : r) {
- if (c.getCellType() == Cell.CELL_TYPE_FORMULA){
+ if (c.getCellType() == CellType.FORMULA){
eval.evaluateFormulaCell(c);
}
}
Row row = sheet.createRow(i);
for (int j = 0; j < 10; j++) {
- Cell cell = row.createCell(j, Cell.CELL_TYPE_STRING);
+ Cell cell = row.createCell(j, CellType.STRING);
cell.setCellValue(i + "x" + j);
}
}
for(Cell acell : cells){
assertTrue(acell.isPartOfArrayFormulaGroup());
- assertEquals(Cell.CELL_TYPE_FORMULA, acell.getCellType());
+ assertEquals(CellType.FORMULA, acell.getCellType());
assertEquals("SUM(A1:A3*B1:B3)", acell.getCellFormula());
//retrieve the range and check it is the same
assertEquals(range.formatAsString(), acell.getArrayFormulaRange().formatAsString());
for(Cell acell : cr){
assertFalse(acell.isPartOfArrayFormulaGroup());
- assertEquals(Cell.CELL_TYPE_BLANK, acell.getCellType());
+ assertEquals(CellType.BLANK, acell.getCellType());
}
// cells C4:C6 are not included in array formula,
CellRange<? extends Cell> srange =
sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
Cell scell = srange.getTopLeftCell();
- assertEquals(Cell.CELL_TYPE_FORMULA, scell.getCellType());
+ assertEquals(CellType.FORMULA, scell.getCellType());
assertEquals(0.0, scell.getNumericCellValue(), 0);
scell.setCellValue(1.1);
assertEquals(1.1, scell.getNumericCellValue(), 0);
CellRange<? extends Cell> mrange =
sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
for(Cell mcell : mrange){
- assertEquals(Cell.CELL_TYPE_FORMULA, mcell.getCellType());
+ assertEquals(CellType.FORMULA, mcell.getCellType());
assertEquals(0.0, mcell.getNumericCellValue(), 0);
double fmlaResult = 1.2;
mcell.setCellValue(fmlaResult);
CellRange<? extends Cell> srange =
sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
Cell scell = srange.getTopLeftCell();
- assertEquals(Cell.CELL_TYPE_FORMULA, scell.getCellType());
+ assertEquals(CellType.FORMULA, scell.getCellType());
assertEquals(0.0, scell.getNumericCellValue(), 0);
- scell.setCellType(Cell.CELL_TYPE_STRING);
- assertEquals(Cell.CELL_TYPE_STRING, scell.getCellType());
+ scell.setCellType(CellType.STRING);
+ assertEquals(CellType.STRING, scell.getCellType());
scell.setCellValue("string cell");
assertEquals("string cell", scell.getStringCellValue());
sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
for(Cell mcell : mrange){
try {
- assertEquals(Cell.CELL_TYPE_FORMULA, mcell.getCellType());
- mcell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ assertEquals(CellType.FORMULA, mcell.getCellType());
+ mcell.setCellType(CellType.NUMERIC);
fail("expected exception");
} catch (IllegalStateException e){
CellReference ref = new CellReference(mcell);
}
// a failed invocation of Cell.setCellType leaves the cell
// in the state that it was in prior to the invocation
- assertEquals(Cell.CELL_TYPE_FORMULA, mcell.getCellType());
+ assertEquals(CellType.FORMULA, mcell.getCellType());
assertTrue(mcell.isPartOfArrayFormulaGroup());
}
workbook.close();
sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
Cell scell = srange.getTopLeftCell();
assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula());
- assertEquals(Cell.CELL_TYPE_FORMULA, scell.getCellType());
+ assertEquals(CellType.FORMULA, scell.getCellType());
assertTrue(scell.isPartOfArrayFormulaGroup());
scell.setCellFormula("SUM(A4,A6)");
//we are now a normal formula cell
assertEquals("SUM(A4,A6)", scell.getCellFormula());
assertFalse(scell.isPartOfArrayFormulaGroup());
- assertEquals(Cell.CELL_TYPE_FORMULA, scell.getCellType());
+ assertEquals(CellType.FORMULA, scell.getCellType());
//check that setting formula result works
assertEquals(0.0, scell.getNumericCellValue(), 0);
scell.setCellValue(33.0);
//re-create the removed cell
scell = srow.createCell(cra.getFirstColumn());
- assertEquals(Cell.CELL_TYPE_BLANK, scell.getCellType());
+ assertEquals(CellType.BLANK, scell.getCellType());
assertFalse(scell.isPartOfArrayFormulaGroup());
//we cannot remove cells included in a multi-cell array formula
// in the state that it was in prior to the invocation
assertSame(mcell, mrow.getCell(columnIndex));
assertTrue(mcell.isPartOfArrayFormulaGroup());
- assertEquals(Cell.CELL_TYPE_FORMULA, mcell.getCellType());
+ assertEquals(CellType.FORMULA, mcell.getCellType());
}
workbook.close();
CellRange<? extends Cell> srange =
sheet.setArrayFormula("SUM(A4:A6,B4:B6)", cra);
Cell scell = srange.getTopLeftCell();
- assertEquals(Cell.CELL_TYPE_FORMULA, scell.getCellType());
+ assertEquals(CellType.FORMULA, scell.getCellType());
Row srow = scell.getRow();
assertSame(srow, sheet.getRow(cra.getFirstRow()));
//re-create the removed row and cell
scell = sheet.createRow(cra.getFirstRow()).createCell(cra.getFirstColumn());
- assertEquals(Cell.CELL_TYPE_BLANK, scell.getCellType());
+ assertEquals(CellType.BLANK, scell.getCellType());
assertFalse(scell.isPartOfArrayFormulaGroup());
//we cannot remove rows with cells included in a multi-cell array formula
assertSame(mrow, sheet.getRow(mrow.getRowNum()));
assertSame(mcell, mrow.getCell(columnIndex));
assertTrue(mcell.isPartOfArrayFormulaGroup());
- assertEquals(Cell.CELL_TYPE_FORMULA, mcell.getCellType());
+ assertEquals(CellType.FORMULA, mcell.getCellType());
}
workbook.close();
Cell scell = srange.getTopLeftCell();
sheet.addMergedRegion(CellRangeAddress.valueOf("B5:C6"));
//we are still an array formula
- assertEquals(Cell.CELL_TYPE_FORMULA, scell.getCellType());
+ assertEquals(CellType.FORMULA, scell.getCellType());
assertTrue(scell.isPartOfArrayFormulaGroup());
assertEquals(1, sheet.getNumMergedRegions());
assertEquals(cra.formatAsString(), mcell.getArrayFormulaRange().formatAsString());
assertEquals("A2:A4*B2:B4", mcell.getCellFormula());
assertTrue(mcell.isPartOfArrayFormulaGroup());
- assertEquals(Cell.CELL_TYPE_FORMULA, mcell.getCellType());
+ assertEquals(CellType.FORMULA, mcell.getCellType());
}
*/
try {
Sheet s = wb.createSheet();
Row r = s.createRow(0);
- Cell c = r.createCell(0, Cell.CELL_TYPE_ERROR);
+ Cell c = r.createCell(0, CellType.ERROR);
c.setCellErrorValue(FormulaError.DIV0.getCode());
assertEquals(FormulaError.DIV0.getString(), dfUS.formatCellValue(c));
import java.util.Date;
-import junit.framework.TestCase;
-
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+
+import junit.framework.TestCase;
/**
* Tests SheetBuilder.
Row firstRow = sheet.getRow(0);
Cell firstCell = firstRow.getCell(0);
- assertEquals(firstCell.getCellType(), Cell.CELL_TYPE_NUMERIC);
+ assertEquals(firstCell.getCellType(), CellType.NUMERIC);
assertEquals(1.0, firstCell.getNumericCellValue(), 0.00001);
assertNull(secondRow.getCell(2));
Row thirdRow = sheet.getRow(2);
- assertEquals(Cell.CELL_TYPE_STRING, thirdRow.getCell(0).getCellType());
+ assertEquals(CellType.STRING, thirdRow.getCell(0).getCellType());
String cellValue = thirdRow.getCell(0).getStringCellValue();
assertEquals(testData[2][0].toString(), cellValue);
- assertEquals(Cell.CELL_TYPE_FORMULA, thirdRow.getCell(2).getCellType());
+ assertEquals(CellType.FORMULA, thirdRow.getCell(2).getCellType());
assertEquals("A1+B2", thirdRow.getCell(2).getCellFormula());
}
Cell emptyCell = sheet.getRow(1).getCell(1);
assertNotNull(emptyCell);
- assertEquals(Cell.CELL_TYPE_BLANK, emptyCell.getCellType());
+ assertEquals(CellType.BLANK, emptyCell.getCellType());
}
public void testSheetName() {