From a8a0cb56f780188d0894168b212559b738acca79 Mon Sep 17 00:00:00 2001 From: Vladislav Galas Date: Sat, 26 Jan 2019 19:41:36 +0000 Subject: [PATCH] purged usages of Cell.setCellType (left only in tests, where conversions are tested) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1852247 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/usermodel/examples/NewLinesInCells.java | 2 -- .../poi/hssf/usermodel/examples/ReadWriteWorkbook.java | 2 -- .../poi/xssf/usermodel/XSSFPivotCacheDefinition.java | 4 ---- .../apache/poi/xssf/extractor/TestXSSFExportToXML.java | 10 ++++------ .../org/apache/poi/xssf/usermodel/TestSXSSFBugs.java | 4 ---- .../org/apache/poi/xssf/usermodel/TestXSSFBugs.java | 2 +- .../org/apache/poi/xssf/usermodel/TestXSSFCell.java | 1 - .../poi/xssf/usermodel/TestXSSFDataValidation.java | 6 ------ .../org/apache/poi/hssf/usermodel/TestBugs.java | 4 ++-- .../org/apache/poi/hssf/usermodel/TestHSSFCell.java | 10 +--------- .../poi/ss/usermodel/BaseTestBugzillaIssues.java | 1 - .../ss/usermodel/BaseTestConditionalFormatting.java | 9 --------- .../poi/ss/usermodel/BaseTestFormulaEvaluator.java | 4 ---- 13 files changed, 8 insertions(+), 51 deletions(-) diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/NewLinesInCells.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/NewLinesInCells.java index 24f1f3dbc0..2b7ce2d96d 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/NewLinesInCells.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/NewLinesInCells.java @@ -26,7 +26,6 @@ import org.apache.poi.hssf.usermodel.HSSFFont; 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; /** * Demonstrates how to use newlines in cells. @@ -46,7 +45,6 @@ public class NewLinesInCells { HSSFRow r = s.createRow(2); r.setHeight((short) 0x349); HSSFCell c = r.createCell(2); - 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))); diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java index 2979ef0667..9b856f99b8 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java @@ -26,7 +26,6 @@ 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 @@ -46,7 +45,6 @@ public class ReadWriteWorkbook { HSSFCell cell = row.getCell(3); if (cell == null) cell = row.createCell(3); - cell.setCellType(CellType.STRING); cell.setCellValue("a test"); // Write the output to a file diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java index 33a095bb9a..540494c35f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java @@ -28,8 +28,6 @@ import javax.xml.namespace.QName; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.ss.SpreadsheetVersion; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -181,8 +179,6 @@ public class XSSFPivotCacheDefinition extends POIXMLDocumentPart{ } //General number format cf.setNumFmtId(0); - Cell cell = row.getCell(i); - cell.setCellType(CellType.STRING); cf.setName(row.getCell(i).getStringCellValue()); cf.addNewSharedItems(); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java index 46f01eb850..25af5f6935 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java @@ -36,7 +36,7 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.FormulaError; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ooxml.util.DocumentHelper; @@ -526,14 +526,12 @@ public final class TestXSSFExportToXML { Cell cString = row.createCell(0); cString.setCellValue("somestring"); - cString.setCellType(CellType.STRING); - + Cell cBoolean = row.createCell(1); cBoolean.setCellValue(true); - cBoolean.setCellType(CellType.BOOLEAN); - + Cell cError = row.createCell(2); - cError.setCellType(CellType.ERROR); + cError.setCellErrorValue(FormulaError.NUM.getCode()); Cell cFormulaString = row.createCell(3); cFormulaString.setCellFormula("A1"); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java index 79d805b6ef..3aee0c54c9 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java @@ -30,7 +30,6 @@ import java.util.Date; import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.PrintSetup; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -136,10 +135,8 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues { Row row = sheet.createRow(rowIndex++); Cell cell = row.createCell(colIndex++); - cell.setCellType(CellType.STRING); cell.setCellValue("multiple"); cell = row.createCell(colIndex); - cell.setCellType(CellType.STRING); cell.setCellValue("unique"); writeRow(sheet, rowIndex++, 80d, "INDEX(A2:A7, MATCH(FALSE, ISBLANK(A2:A7), 0))"); @@ -166,7 +163,6 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues { // numeric value cell Cell cell = row.createCell(colIndex++); - cell.setCellType(CellType.NUMERIC); cell.setCellValue(col0Value); // formula value cell diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 99d95e1b5b..bdc9b6ddc8 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -629,7 +629,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { sheet.getRow(3).getCell(0).setCellFormula("14"); // stay XSSFTestDataSamples.writeOutAndReadBack(wb1).close(); - sheet.getRow(4).getCell(0).setCellType(CellType.STRING); // go + sheet.getRow(4).getCell(0).setBlank(); // go XSSFTestDataSamples.writeOutAndReadBack(wb1).close(); validateCells(sheet); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java index 6e83a5e6e2..993e2c9b21 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java @@ -71,7 +71,6 @@ public final class TestXSSFCell extends BaseTestXCell { Sheet sheet = wb.getSheetAt(0); Row row = sheet.getRow(0); Cell cell = row.getCell(0); - cell.setCellType(CellType.STRING); cell.setCellValue("456"); wb.close(); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java index 06d7866f8a..0394f6fdd2 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java @@ -26,7 +26,6 @@ import org.apache.poi.ss.formula.DataValidationEvaluator; import org.apache.poi.ss.formula.eval.ValueEval; 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; @@ -142,9 +141,6 @@ public class TestXSSFDataValidation extends BaseTestDataValidation { Cell cell_22 = i==0 && j < 2 ? (row2 == null ? null : row2.createCell(2)) : null; Cell cell_13 = row1.createCell(3); - - - cell_13.setCellType(CellType.NUMERIC); cell_13.setCellValue(validationType==ValidationType.DECIMAL ? dvalue.doubleValue() : value.intValue()); @@ -210,11 +206,9 @@ public class TestXSSFDataValidation extends BaseTestDataValidation { String value1String = validationType==ValidationType.DECIMAL ? dvalue.toString() : value.toString(); - 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(CellType.NUMERIC); cell_14.setCellValue(validationType==ValidationType.DECIMAL ? dvalue2.doubleValue() : value2.intValue()); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 32ec25bcf5..1beb8ff11d 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -79,6 +79,7 @@ import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.ComparisonOperator; import org.apache.poi.ss.usermodel.DataFormatter; +import org.apache.poi.ss.usermodel.FormulaError; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Row; @@ -177,7 +178,6 @@ public final class TestBugs extends BaseTestBugzillaIssues { cell = row.createCell(3); // Write test - cell.setCellType(CellType.STRING); setCellText(cell, "a test"); // change existing numeric cell value @@ -2550,7 +2550,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { row.createCell(2).setCellValue(cal); row.createCell(3).setCellValue(String.format(Locale.ROOT, "row:%d/col:%d", r, 3)); row.createCell(4).setCellValue(true); - row.createCell(5).setCellType(CellType.ERROR); + row.createCell(5).setCellErrorValue(FormulaError.NUM.getCode()); row.createCell(6).setCellValue("added cells."); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index 5f37ad44fd..aac0747579 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -45,8 +45,6 @@ import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.util.LocaleUtil; import org.junit.Test; -import junit.framework.AssertionFailedError; - /** * Tests various functionality having to do with {@link HSSFCell}. For instance support for * particular datatypes, etc. @@ -443,28 +441,22 @@ public final class TestHSSFCell extends BaseTestCell { cell.setCellType(CellType.STRING); assertEquals("", cell.toString()); - cell.setCellType(CellType.STRING); cell.setCellValue(1.2); - cell.setCellType(CellType.NUMERIC); assertEquals("1.2", cell.toString()); cell.setCellType(CellType.BOOLEAN); assertEquals("TRUE", cell.toString()); cell.setCellType(CellType.BOOLEAN); cell.setCellValue("" + FormulaError.VALUE.name()); - cell.setCellType(CellType.ERROR); - assertEquals("#VALUE!", cell.toString()); - cell.setCellType(CellType.ERROR); + assertEquals(CellType.STRING, cell.getCellType()); cell.setCellType(CellType.BOOLEAN); assertEquals("FALSE", cell.toString()); cell.setCellValue(1.2); - cell.setCellType(CellType.NUMERIC); assertEquals("1.2", cell.toString()); cell.setCellType(CellType.BOOLEAN); cell.setCellType(CellType.STRING); cell.setCellType(CellType.ERROR); cell.setCellType(CellType.STRING); cell.setCellValue(1.2); - cell.setCellType(CellType.NUMERIC); cell.setCellType(CellType.STRING); assertEquals("1.2", cell.toString()); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java index ae389c05b2..fcc6eb9425 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java @@ -1228,7 +1228,6 @@ public abstract class BaseTestBugzillaIssues { value == null || value.length() == 0); // set some value - cell.setCellType(CellType.STRING); cell.setCellValue("somevalue"); value = cell.getStringCellValue(); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java index bbcafbaebd..6bdeccddf7 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java @@ -1356,45 +1356,36 @@ public abstract class BaseTestConditionalFormatting { Row row = sheet.createRow(0); Cell cell0 = row.createCell(0); - cell0.setCellType(CellType.NUMERIC); cell0.setCellValue(100); Cell cell1 = row.createCell(1); - cell1.setCellType(CellType.NUMERIC); cell1.setCellValue(120); Cell cell2 = row.createCell(2); - cell2.setCellType(CellType.NUMERIC); cell2.setCellValue(130); // row 1 row = sheet.createRow(1); cell0 = row.createCell(0); - cell0.setCellType(CellType.NUMERIC); cell0.setCellValue(200); cell1 = row.createCell(1); - cell1.setCellType(CellType.NUMERIC); cell1.setCellValue(220); cell2 = row.createCell(2); - cell2.setCellType(CellType.NUMERIC); cell2.setCellValue(230); // row 2 row = sheet.createRow(2); cell0 = row.createCell(0); - cell0.setCellType(CellType.NUMERIC); cell0.setCellValue(300); cell1 = row.createCell(1); - cell1.setCellType(CellType.NUMERIC); cell1.setCellValue(320); cell2 = row.createCell(2); - cell2.setCellType(CellType.NUMERIC); cell2.setCellValue(330); // Create conditional formatting, CELL1 should be yellow if CELL0 is not blank. diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java index 4712a85536..b47f3453f1 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java @@ -364,22 +364,18 @@ public abstract class BaseTestFormulaEvaluator { // sheet1 A1 Cell cell = sheet1.createRow(0).createCell(0); - cell.setCellType(CellType.NUMERIC); cell.setCellValue(1.0); // sheet2 A1 cell = sheet2.createRow(0).createCell(0); - cell.setCellType(CellType.NUMERIC); cell.setCellValue(1.0); // sheet2 B1 cell = sheet2.getRow(0).createCell(1); - cell.setCellType(CellType.NUMERIC); cell.setCellValue(1.0); // sheet3 A1 cell = sheet3.createRow(0).createCell(0); - cell.setCellType(CellType.NUMERIC); cell.setCellValue(1.0); // sheet1 A2 formulae -- 2.39.5