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
This commit is contained in:
Vladislav Galas 2019-01-26 19:41:36 +00:00
parent 39d963aa33
commit a8a0cb56f7
13 changed files with 8 additions and 51 deletions

View File

@ -26,7 +26,6 @@ import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
/** /**
* Demonstrates how to use newlines in cells. * Demonstrates how to use newlines in cells.
@ -46,7 +45,6 @@ public class NewLinesInCells {
HSSFRow r = s.createRow(2); HSSFRow r = s.createRow(2);
r.setHeight((short) 0x349); r.setHeight((short) 0x349);
HSSFCell c = r.createCell(2); HSSFCell c = r.createCell(2);
c.setCellType(CellType.STRING);
c.setCellValue("Use \n with word wrap on to create a new line"); c.setCellValue("Use \n with word wrap on to create a new line");
c.setCellStyle(cs); c.setCellStyle(cs);
s.setColumnWidth(2, (int) ((50 * 8) / ((double) 1 / 20))); s.setColumnWidth(2, (int) ((50 * 8) / ((double) 1 / 20)));

View File

@ -26,7 +26,6 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.CellType;
/** /**
* This example demonstrates opening a workbook, modifying it and writing * This example demonstrates opening a workbook, modifying it and writing
@ -46,7 +45,6 @@ public class ReadWriteWorkbook {
HSSFCell cell = row.getCell(3); HSSFCell cell = row.getCell(3);
if (cell == null) if (cell == null)
cell = row.createCell(3); cell = row.createCell(3);
cell.setCellType(CellType.STRING);
cell.setCellValue("a test"); cell.setCellValue("a test");
// Write the output to a file // Write the output to a file

View File

@ -28,8 +28,6 @@ import javax.xml.namespace.QName;
import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.SpreadsheetVersion; 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.Name;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
@ -181,8 +179,6 @@ public class XSSFPivotCacheDefinition extends POIXMLDocumentPart{
} }
//General number format //General number format
cf.setNumFmtId(0); cf.setNumFmtId(0);
Cell cell = row.getCell(i);
cell.setCellType(CellType.STRING);
cf.setName(row.getCell(i).getStringCellValue()); cf.setName(row.getCell(i).getStringCellValue());
cf.addNewSharedItems(); cf.addNewSharedItems();
} }

View File

@ -36,7 +36,7 @@ import javax.xml.parsers.ParserConfigurationException;
import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.Cell; 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.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ooxml.util.DocumentHelper; import org.apache.poi.ooxml.util.DocumentHelper;
@ -526,14 +526,12 @@ public final class TestXSSFExportToXML {
Cell cString = row.createCell(0); Cell cString = row.createCell(0);
cString.setCellValue("somestring"); cString.setCellValue("somestring");
cString.setCellType(CellType.STRING);
Cell cBoolean = row.createCell(1); Cell cBoolean = row.createCell(1);
cBoolean.setCellValue(true); cBoolean.setCellValue(true);
cBoolean.setCellType(CellType.BOOLEAN);
Cell cError = row.createCell(2); Cell cError = row.createCell(2);
cError.setCellType(CellType.ERROR); cError.setCellErrorValue(FormulaError.NUM.getCode());
Cell cFormulaString = row.createCell(3); Cell cFormulaString = row.createCell(3);
cFormulaString.setCellFormula("A1"); cFormulaString.setCellFormula("A1");

View File

@ -30,7 +30,6 @@ import java.util.Date;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
import org.apache.poi.ss.usermodel.Cell; 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.PrintSetup;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
@ -136,10 +135,8 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
Row row = sheet.createRow(rowIndex++); Row row = sheet.createRow(rowIndex++);
Cell cell = row.createCell(colIndex++); Cell cell = row.createCell(colIndex++);
cell.setCellType(CellType.STRING);
cell.setCellValue("multiple"); cell.setCellValue("multiple");
cell = row.createCell(colIndex); cell = row.createCell(colIndex);
cell.setCellType(CellType.STRING);
cell.setCellValue("unique"); cell.setCellValue("unique");
writeRow(sheet, rowIndex++, 80d, "INDEX(A2:A7, MATCH(FALSE, ISBLANK(A2:A7), 0))"); 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 // numeric value cell
Cell cell = row.createCell(colIndex++); Cell cell = row.createCell(colIndex++);
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(col0Value); cell.setCellValue(col0Value);
// formula value cell // formula value cell

View File

@ -629,7 +629,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
sheet.getRow(3).getCell(0).setCellFormula("14"); // stay sheet.getRow(3).getCell(0).setCellFormula("14"); // stay
XSSFTestDataSamples.writeOutAndReadBack(wb1).close(); XSSFTestDataSamples.writeOutAndReadBack(wb1).close();
sheet.getRow(4).getCell(0).setCellType(CellType.STRING); // go sheet.getRow(4).getCell(0).setBlank(); // go
XSSFTestDataSamples.writeOutAndReadBack(wb1).close(); XSSFTestDataSamples.writeOutAndReadBack(wb1).close();
validateCells(sheet); validateCells(sheet);

View File

@ -71,7 +71,6 @@ public final class TestXSSFCell extends BaseTestXCell {
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(0); Row row = sheet.getRow(0);
Cell cell = row.getCell(0); Cell cell = row.getCell(0);
cell.setCellType(CellType.STRING);
cell.setCellValue("456"); cell.setCellValue("456");
wb.close(); wb.close();
} }

View File

@ -26,7 +26,6 @@ import org.apache.poi.ss.formula.DataValidationEvaluator;
import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.BaseTestDataValidation; import org.apache.poi.ss.usermodel.BaseTestDataValidation;
import org.apache.poi.ss.usermodel.Cell; 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.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint; import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType; 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_22 = i==0 && j < 2 ? (row2 == null ? null : row2.createCell(2)) : null;
Cell cell_13 = row1.createCell(3); Cell cell_13 = row1.createCell(3);
cell_13.setCellType(CellType.NUMERIC);
cell_13.setCellValue(validationType==ValidationType.DECIMAL ? dvalue.doubleValue() : value.intValue()); 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(); String value1String = validationType==ValidationType.DECIMAL ? dvalue.toString() : value.toString();
cell_13.setCellType(CellType.NUMERIC);
cell_13.setCellValue(validationType==ValidationType.DECIMAL ? dvalue.doubleValue() : value.intValue()); cell_13.setCellValue(validationType==ValidationType.DECIMAL ? dvalue.doubleValue() : value.intValue());
String value2String = validationType==ValidationType.DECIMAL ? dvalue2.toString() : value2.toString(); String value2String = validationType==ValidationType.DECIMAL ? dvalue2.toString() : value2.toString();
cell_14.setCellType(CellType.NUMERIC);
cell_14.setCellValue(validationType==ValidationType.DECIMAL ? dvalue2.doubleValue() : value2.intValue()); cell_14.setCellValue(validationType==ValidationType.DECIMAL ? dvalue2.doubleValue() : value2.intValue());

View File

@ -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.ClientAnchor.AnchorType;
import org.apache.poi.ss.usermodel.ComparisonOperator; import org.apache.poi.ss.usermodel.ComparisonOperator;
import org.apache.poi.ss.usermodel.DataFormatter; 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.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
@ -177,7 +178,6 @@ public final class TestBugs extends BaseTestBugzillaIssues {
cell = row.createCell(3); cell = row.createCell(3);
// Write test // Write test
cell.setCellType(CellType.STRING);
setCellText(cell, "a test"); setCellText(cell, "a test");
// change existing numeric cell value // change existing numeric cell value
@ -2550,7 +2550,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
row.createCell(2).setCellValue(cal); row.createCell(2).setCellValue(cal);
row.createCell(3).setCellValue(String.format(Locale.ROOT, "row:%d/col:%d", r, 3)); row.createCell(3).setCellValue(String.format(Locale.ROOT, "row:%d/col:%d", r, 3));
row.createCell(4).setCellValue(true); row.createCell(4).setCellValue(true);
row.createCell(5).setCellType(CellType.ERROR); row.createCell(5).setCellErrorValue(FormulaError.NUM.getCode());
row.createCell(6).setCellValue("added cells."); row.createCell(6).setCellValue("added cells.");
} }

View File

@ -45,8 +45,6 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.LocaleUtil;
import org.junit.Test; import org.junit.Test;
import junit.framework.AssertionFailedError;
/** /**
* Tests various functionality having to do with {@link HSSFCell}. For instance support for * Tests various functionality having to do with {@link HSSFCell}. For instance support for
* particular datatypes, etc. * particular datatypes, etc.
@ -443,28 +441,22 @@ public final class TestHSSFCell extends BaseTestCell {
cell.setCellType(CellType.STRING); cell.setCellType(CellType.STRING);
assertEquals("", cell.toString()); assertEquals("", cell.toString());
cell.setCellType(CellType.STRING);
cell.setCellValue(1.2); cell.setCellValue(1.2);
cell.setCellType(CellType.NUMERIC);
assertEquals("1.2", cell.toString()); assertEquals("1.2", cell.toString());
cell.setCellType(CellType.BOOLEAN); cell.setCellType(CellType.BOOLEAN);
assertEquals("TRUE", cell.toString()); assertEquals("TRUE", cell.toString());
cell.setCellType(CellType.BOOLEAN); cell.setCellType(CellType.BOOLEAN);
cell.setCellValue("" + FormulaError.VALUE.name()); cell.setCellValue("" + FormulaError.VALUE.name());
cell.setCellType(CellType.ERROR); assertEquals(CellType.STRING, cell.getCellType());
assertEquals("#VALUE!", cell.toString());
cell.setCellType(CellType.ERROR);
cell.setCellType(CellType.BOOLEAN); cell.setCellType(CellType.BOOLEAN);
assertEquals("FALSE", cell.toString()); assertEquals("FALSE", cell.toString());
cell.setCellValue(1.2); cell.setCellValue(1.2);
cell.setCellType(CellType.NUMERIC);
assertEquals("1.2", cell.toString()); assertEquals("1.2", cell.toString());
cell.setCellType(CellType.BOOLEAN); cell.setCellType(CellType.BOOLEAN);
cell.setCellType(CellType.STRING); cell.setCellType(CellType.STRING);
cell.setCellType(CellType.ERROR); cell.setCellType(CellType.ERROR);
cell.setCellType(CellType.STRING); cell.setCellType(CellType.STRING);
cell.setCellValue(1.2); cell.setCellValue(1.2);
cell.setCellType(CellType.NUMERIC);
cell.setCellType(CellType.STRING); cell.setCellType(CellType.STRING);
assertEquals("1.2", cell.toString()); assertEquals("1.2", cell.toString());

View File

@ -1228,7 +1228,6 @@ public abstract class BaseTestBugzillaIssues {
value == null || value.length() == 0); value == null || value.length() == 0);
// set some value // set some value
cell.setCellType(CellType.STRING);
cell.setCellValue("somevalue"); cell.setCellValue("somevalue");
value = cell.getStringCellValue(); value = cell.getStringCellValue();

View File

@ -1356,45 +1356,36 @@ public abstract class BaseTestConditionalFormatting {
Row row = sheet.createRow(0); Row row = sheet.createRow(0);
Cell cell0 = row.createCell(0); Cell cell0 = row.createCell(0);
cell0.setCellType(CellType.NUMERIC);
cell0.setCellValue(100); cell0.setCellValue(100);
Cell cell1 = row.createCell(1); Cell cell1 = row.createCell(1);
cell1.setCellType(CellType.NUMERIC);
cell1.setCellValue(120); cell1.setCellValue(120);
Cell cell2 = row.createCell(2); Cell cell2 = row.createCell(2);
cell2.setCellType(CellType.NUMERIC);
cell2.setCellValue(130); cell2.setCellValue(130);
// row 1 // row 1
row = sheet.createRow(1); row = sheet.createRow(1);
cell0 = row.createCell(0); cell0 = row.createCell(0);
cell0.setCellType(CellType.NUMERIC);
cell0.setCellValue(200); cell0.setCellValue(200);
cell1 = row.createCell(1); cell1 = row.createCell(1);
cell1.setCellType(CellType.NUMERIC);
cell1.setCellValue(220); cell1.setCellValue(220);
cell2 = row.createCell(2); cell2 = row.createCell(2);
cell2.setCellType(CellType.NUMERIC);
cell2.setCellValue(230); cell2.setCellValue(230);
// row 2 // row 2
row = sheet.createRow(2); row = sheet.createRow(2);
cell0 = row.createCell(0); cell0 = row.createCell(0);
cell0.setCellType(CellType.NUMERIC);
cell0.setCellValue(300); cell0.setCellValue(300);
cell1 = row.createCell(1); cell1 = row.createCell(1);
cell1.setCellType(CellType.NUMERIC);
cell1.setCellValue(320); cell1.setCellValue(320);
cell2 = row.createCell(2); cell2 = row.createCell(2);
cell2.setCellType(CellType.NUMERIC);
cell2.setCellValue(330); cell2.setCellValue(330);
// Create conditional formatting, CELL1 should be yellow if CELL0 is not blank. // Create conditional formatting, CELL1 should be yellow if CELL0 is not blank.

View File

@ -364,22 +364,18 @@ public abstract class BaseTestFormulaEvaluator {
// sheet1 A1 // sheet1 A1
Cell cell = sheet1.createRow(0).createCell(0); Cell cell = sheet1.createRow(0).createCell(0);
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(1.0); cell.setCellValue(1.0);
// sheet2 A1 // sheet2 A1
cell = sheet2.createRow(0).createCell(0); cell = sheet2.createRow(0).createCell(0);
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(1.0); cell.setCellValue(1.0);
// sheet2 B1 // sheet2 B1
cell = sheet2.getRow(0).createCell(1); cell = sheet2.getRow(0).createCell(1);
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(1.0); cell.setCellValue(1.0);
// sheet3 A1 // sheet3 A1
cell = sheet3.createRow(0).createCell(0); cell = sheet3.createRow(0).createCell(0);
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(1.0); cell.setCellValue(1.0);
// sheet1 A2 formulae // sheet1 A2 formulae