Use more specific return types in SXSSF, which avoids casts, and also fix some long-standing TODOs on 1904 dates

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1693633 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-07-31 17:23:01 +00:00
parent 402c445599
commit 92d27b6262
4 changed files with 23 additions and 25 deletions

View File

@ -33,18 +33,18 @@ import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.usermodel.RichTextString;
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.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.xssf.usermodel.XSSFHyperlink; import org.apache.poi.xssf.usermodel.XSSFHyperlink;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
/** /**
* Streaming version of XSSFRow implementing the "BigGridDemo" strategy. * Streaming version of XSSFRow implementing the "BigGridDemo" strategy.
*
* @author Alex Geller, Four J's Development Tools
*/ */
public class SXSSFCell implements Cell public class SXSSFCell implements Cell {
{ private static POILogger logger = POILogFactory.getLogger(SXSSFCell.class);
SXSSFRow _row; SXSSFRow _row;
Value _value; Value _value;
@ -84,7 +84,7 @@ public class SXSSFCell implements Cell
* *
* @return the sheet this cell belongs to * @return the sheet this cell belongs to
*/ */
public Sheet getSheet() public SXSSFSheet getSheet()
{ {
return _row.getSheet(); return _row.getSheet();
} }
@ -185,11 +185,8 @@ public class SXSSFCell implements Cell
* precalculated value, for numerics we'll set its value. For other types we * precalculated value, for numerics we'll set its value. For other types we
* will change the cell to a numerics cell and set its value. * will change the cell to a numerics cell and set its value.
*/ */
public void setCellValue(Date value) public void setCellValue(Date value) {
{ boolean date1904 = getSheet().getWorkbook().isDate1904();
//TODO: activate this when compiling against 3.7.
//boolean date1904 = getSheet().getXSSFWorkbook().isDate1904();
boolean date1904 = false;
setCellValue(DateUtil.getExcelDate(value, date1904)); setCellValue(DateUtil.getExcelDate(value, date1904));
} }
@ -209,11 +206,8 @@ public class SXSSFCell implements Cell
* precalculated value, for numerics we'll set its value. For othertypes we * precalculated value, for numerics we'll set its value. For othertypes we
* will change the cell to a numeric cell and set its value. * will change the cell to a numeric cell and set its value.
*/ */
public void setCellValue(Calendar value) public void setCellValue(Calendar value) {
{ boolean date1904 = getSheet().getWorkbook().isDate1904();
//TODO: activate this when compiling against 3.7.
//boolean date1904 = getSheet().getXSSFWorkbook().isDate1904();
boolean date1904 = false;
setCellValue( DateUtil.getExcelDate(value, date1904 )); setCellValue( DateUtil.getExcelDate(value, date1904 ));
} }
@ -234,6 +228,9 @@ public class SXSSFCell implements Cell
} }
((RichTextValue)_value).setValue(value); ((RichTextValue)_value).setValue(value);
if (((XSSFRichTextString)value).hasFormatting())
logger.log(POILogger.WARN, "SXSSF doesn't support Shared Strings, rich text formatting information has be lost");
} }
/** /**
@ -343,9 +340,7 @@ public class SXSSFCell implements Cell
} }
double value = getNumericCellValue(); double value = getNumericCellValue();
//TODO: activate this when compiling against 3.7. boolean date1904 = getSheet().getWorkbook().isDate1904();
//boolean date1904 = getSheet().getXSSFWorkbook().isDate1904();
boolean date1904 = false;
return DateUtil.getJavaDate(value, date1904); return DateUtil.getJavaDate(value, date1904);
} }
@ -603,8 +598,7 @@ public class SXSSFCell implements Cell
xssfobj.getCTHyperlink().setRef( ref.formatAsString() ); xssfobj.getCTHyperlink().setRef( ref.formatAsString() );
// Add to the lists // Add to the lists
((SXSSFSheet)getSheet())._sh.addHyperlink(xssfobj); getSheet()._sh.addHyperlink(xssfobj);
} }
/** /**
@ -614,7 +608,7 @@ public class SXSSFCell implements Cell
{ {
removeProperty(Property.HYPERLINK); removeProperty(Property.HYPERLINK);
((SXSSFSheet) getSheet())._sh.removeHyperlink(getRowIndex(), getColumnIndex()); getSheet()._sh.removeHyperlink(getRowIndex(), getColumnIndex());
} }
/** /**

View File

@ -420,7 +420,7 @@ public class SXSSFRow implements Row
* *
* @return the Sheet that owns this row * @return the Sheet that owns this row
*/ */
public Sheet getSheet() public SXSSFSheet getSheet()
{ {
return _sheet; return _sheet;
} }

View File

@ -1344,7 +1344,7 @@ public class SXSSFSheet implements Sheet, Cloneable
* *
* @return the parent workbook * @return the parent workbook
*/ */
public Workbook getWorkbook() public SXSSFWorkbook getWorkbook()
{ {
return _workbook; return _workbook;
} }

View File

@ -622,7 +622,7 @@ public class SXSSFWorkbook implements Workbook
* @return Sheet representing the new sheet. * @return Sheet representing the new sheet.
*/ */
@Override @Override
public Sheet createSheet() public SXSSFSheet createSheet()
{ {
return createAndRegisterSXSSFSheet(_wb.createSheet()); return createAndRegisterSXSSFSheet(_wb.createSheet());
} }
@ -1122,6 +1122,10 @@ public class SXSSFWorkbook implements Workbook
return _wb.getCreationHelper(); return _wb.getCreationHelper();
} }
protected boolean isDate1904() {
return _wb.isDate1904();
}
/** /**
* @return <code>false</code> if this workbook is not visible in the GUI * @return <code>false</code> if this workbook is not visible in the GUI
*/ */