added Cell.setBlank() - as an alias, for now

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1852244 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Vladislav Galas 2019-01-26 19:40:56 +00:00
parent 1253a29571
commit d60cb3a18c
4 changed files with 30 additions and 4 deletions

View File

@ -89,6 +89,13 @@ public interface Cell {
*/ */
void setCellType(CellType cellType); void setCellType(CellType cellType);
/**
* Removes formula and value from the cell, and sets its type to {@link CellType#BLANK}.
* Preserves comments and hyperlinks.
* While {@link #setCellType(CellType)} exists, is an alias for {@code setCellType(CellType.BLANK)}.
*/
void setBlank();
/** /**
* Return the cell type. * Return the cell type.
* *

View File

@ -40,6 +40,14 @@ public abstract class CellBase implements Cell {
setCellTypeImpl(cellType); setCellTypeImpl(cellType);
} }
/**
* {@inheritDoc}
*/
@Override
public void setBlank() {
setCellType(CellType.BLANK);
}
/** /**
* Implementation-specific logic * Implementation-specific logic
* @param cellType new cell type. Guaranteed non-null, not _NONE. * @param cellType new cell type. Guaranteed non-null, not _NONE.

View File

@ -944,7 +944,7 @@ public final class XSSFCell extends CellBase {
* Blanks this cell. Blank cells have no formula or value but may have styling. * Blanks this cell. Blank cells have no formula or value but may have styling.
* This method erases all the data previously associated with this cell. * This method erases all the data previously associated with this cell.
*/ */
private void setBlank(){ private void setBlankPrivate(){
CTCell blank = CTCell.Factory.newInstance(); CTCell blank = CTCell.Factory.newInstance();
blank.setR(_cell.getR()); blank.setR(_cell.getR());
if(_cell.isSetS()) { if(_cell.isSetS()) {
@ -1010,7 +1010,7 @@ public final class XSSFCell extends CellBase {
} }
break; break;
case BLANK: case BLANK:
setBlank(); setBlankPrivate();
break; break;
case BOOLEAN: case BOOLEAN:
String newVal = convertCellValueToBoolean() ? TRUE_AS_STRING : FALSE_AS_STRING; String newVal = convertCellValueToBoolean() ? TRUE_AS_STRING : FALSE_AS_STRING;

View File

@ -24,6 +24,9 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -32,13 +35,11 @@ import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.function.Consumer;
import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.LocaleUtil;
import org.junit.Test; import org.junit.Test;
@ -1357,6 +1358,16 @@ public abstract class BaseTestCell {
assertTrue(cell.getBooleanCellValue()); assertTrue(cell.getBooleanCellValue());
} }
@Test
public final void setBlank_delegatesTo_setCellType_BLANK() {
Cell cell = mock(CellBase.class);
doCallRealMethod().when(cell).setBlank();
cell.setBlank();
verify(cell).setCellType(CellType.BLANK);
}
private Cell getInstance() { private Cell getInstance() {
return _testDataProvider.createWorkbook().createSheet().createRow(0).createCell(0); return _testDataProvider.createWorkbook().createSheet().createRow(0).createCell(0);
} }