fix problem test (SXXSF)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2025-02-14 21:25:55 +00:00
parent bd6fddbcc4
commit 7d87f1b5cd
3 changed files with 6 additions and 32 deletions

View File

@ -27,16 +27,7 @@ import java.util.Map;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellBase;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.*;
@ -722,6 +713,8 @@ public class SXSSFCell extends CellBase {
}
//end of interface implementation
private static final DataFormatter DATA_FORMATTER = new DataFormatter();
/**
* Returns a string representation of the cell
* <p>
@ -742,14 +735,8 @@ public class SXSSFCell extends CellBase {
case FORMULA:
return getCellFormula();
case NUMERIC:
if (DateUtil.isCellDateFormatted(this)) {
DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", LocaleUtil.getUserLocale());
sdf.setTimeZone(LocaleUtil.getUserTimeZone());
return sdf.format(getDateCellValue());
}
return getNumericCellValue() + "";
case STRING:
return getRichStringCellValue().toString();
return DATA_FORMATTER.formatCellValue(this);
default:
return "Unknown Cell Type: " + getCellType();
}

View File

@ -169,9 +169,4 @@ class TestSXSSFCell extends BaseTestXCell {
@Disabled
protected void setCellType_FORMULA_onAnArrayFormulaCell_doesNothing() {
}
@Override
protected boolean enableDateTest() {
return false;
}
}

View File

@ -340,10 +340,6 @@ public abstract class BaseTestCell {
}
}
protected boolean enableDateTest() {
return true;
}
/**tests the toString() method of HSSFCell*/
@Test
void testToString() throws Exception {
@ -377,9 +373,7 @@ public abstract class BaseTestCell {
assertEquals("", r.getCell(6).toString(), "Blank");
// toString on a date-formatted cell displays dates as dd-MMM-yyyy, which has locale problems with the month
String dateCell1 = r.getCell(7).toString();
if (enableDateTest()) {
assertEquals("2/2/10 0:00", dateCell1);
}
assertEquals("2/2/10 0:00", dateCell1);
//Write out the file, read it in, and then check cell values
try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
@ -392,9 +386,7 @@ public abstract class BaseTestCell {
assertEquals("A1+B1", r.getCell(5).toString(), "Formula");
assertEquals("", r.getCell(6).toString(), "Blank");
String dateCell2 = r.getCell(7).toString();
if (enableDateTest()) {
assertEquals(dateCell1, dateCell2, "Date");
}
assertEquals(dateCell1, dateCell2, "Date");
}
}
}