Allow to specify SpreadsheetVersion when instantiating blank HSSFWorkbook
This commit is contained in:
parent
9e63166ac3
commit
c2cd1b48ca
@ -70,6 +70,7 @@ import org.apache.poi.hssf.record.aggregates.RecordAggregate.PositionTrackingVis
|
||||
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
|
||||
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
|
||||
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.formula.FormulaShifter;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.PaneInformation;
|
||||
@ -444,9 +445,12 @@ public final class InternalSheet {
|
||||
* @return Sheet object with all values set to defaults
|
||||
*/
|
||||
public static InternalSheet createSheet() {
|
||||
return new InternalSheet();
|
||||
return new InternalSheet(SpreadsheetVersion.EXCEL97);
|
||||
}
|
||||
private InternalSheet() {
|
||||
public static InternalSheet createSheet(final SpreadsheetVersion spreadsheetVersion) {
|
||||
return new InternalSheet(spreadsheetVersion);
|
||||
}
|
||||
private InternalSheet(final SpreadsheetVersion spreadsheetVersion) {
|
||||
_mergedCellsTable = new MergedCellsTable();
|
||||
List<RecordBase> records = new ArrayList<RecordBase>(32);
|
||||
|
||||
@ -487,7 +491,7 @@ public final class InternalSheet {
|
||||
_columnInfos = columns;
|
||||
_dimensions = createDimensions();
|
||||
records.add(_dimensions);
|
||||
_rowsAggregate = new RowRecordsAggregate();
|
||||
_rowsAggregate = new RowRecordsAggregate(spreadsheetVersion);
|
||||
records.add(_rowsAggregate);
|
||||
// 'Sheet View Settings'
|
||||
records.add(windowTwo = createWindowTwo());
|
||||
|
@ -109,7 +109,7 @@ public final class SharedFormulaRecord extends SharedValueRecordBase {
|
||||
throw new RuntimeException("Shared Formula Conversion: Coding Error");
|
||||
}
|
||||
|
||||
SharedFormula sf = new SharedFormula(org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion);
|
||||
SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL97);
|
||||
return sf.convertSharedFormulas(field_7_parsed_expr.getTokens(), formulaRow, formulaColumn);
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ public final class RowRecordsAggregate extends RecordAggregate {
|
||||
private final ValueRecordsAggregate _valuesAgg;
|
||||
private final List<Record> _unknownRecords;
|
||||
private final SharedValueManager _sharedValueManager;
|
||||
private final SpreadsheetVersion _spreadsheetVersion;
|
||||
|
||||
// Cache values to speed up performance of
|
||||
// getStartRowNumberForBlock / getEndRowNumberForBlock, see Bugzilla 47405
|
||||
@ -47,9 +48,15 @@ public final class RowRecordsAggregate extends RecordAggregate {
|
||||
|
||||
/** Creates a new instance of ValueRecordsAggregate */
|
||||
public RowRecordsAggregate() {
|
||||
this(SharedValueManager.createEmpty());
|
||||
this(SharedValueManager.createEmpty(), SpreadsheetVersion.EXCEL97);
|
||||
}
|
||||
private RowRecordsAggregate(SharedValueManager svm) {
|
||||
public RowRecordsAggregate(final SpreadsheetVersion spreadsheetVersion) {
|
||||
this(SharedValueManager.createEmpty(), spreadsheetVersion);
|
||||
if (spreadsheetVersion == null) {
|
||||
throw new IllegalArgumentException("SpreadsheetVersion must be provided.");
|
||||
}
|
||||
}
|
||||
private RowRecordsAggregate(SharedValueManager svm, final SpreadsheetVersion spreadsheetVersion) {
|
||||
if (svm == null) {
|
||||
throw new IllegalArgumentException("SharedValueManager must be provided.");
|
||||
}
|
||||
@ -57,6 +64,7 @@ public final class RowRecordsAggregate extends RecordAggregate {
|
||||
_valuesAgg = new ValueRecordsAggregate();
|
||||
_unknownRecords = new ArrayList<Record>();
|
||||
_sharedValueManager = svm;
|
||||
_spreadsheetVersion = spreadsheetVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +74,7 @@ public final class RowRecordsAggregate extends RecordAggregate {
|
||||
* and table records of the current sheet). Never <code>null</code>.
|
||||
*/
|
||||
public RowRecordsAggregate(RecordStream rs, SharedValueManager svm) {
|
||||
this(svm);
|
||||
this(svm, SpreadsheetVersion.EXCEL97);
|
||||
while(rs.hasNext()) {
|
||||
Record rec = rs.getNext();
|
||||
switch (rec.getSid()) {
|
||||
@ -143,7 +151,7 @@ public final class RowRecordsAggregate extends RecordAggregate {
|
||||
}
|
||||
|
||||
public RowRecord getRow(int rowIndex) {
|
||||
int maxrow = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex();
|
||||
int maxrow = _spreadsheetVersion.getLastRowIndex();
|
||||
if (rowIndex < 0 || rowIndex > maxrow) {
|
||||
throw new IllegalArgumentException("The row number must be between 0 and " + maxrow + ", but had: " + rowIndex);
|
||||
}
|
||||
|
@ -42,13 +42,7 @@ import org.apache.poi.ss.formula.FormulaType;
|
||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||
import org.apache.poi.ss.formula.ptg.ExpPtg;
|
||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
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.FormulaError;
|
||||
import org.apache.poi.ss.usermodel.Hyperlink;
|
||||
import org.apache.poi.ss.usermodel.RichTextString;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
@ -70,11 +64,6 @@ import org.apache.poi.util.LocaleUtil;
|
||||
*/
|
||||
public class HSSFCell implements Cell {
|
||||
private static final String FILE_FORMAT_NAME = "BIFF8";
|
||||
/**
|
||||
* The maximum number of columns in BIFF8
|
||||
*/
|
||||
public static final int LAST_COLUMN_NUMBER = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastColumnIndex(); // 2^8 - 1
|
||||
private static final String LAST_COLUMN_NAME = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastColumnName();
|
||||
|
||||
public final static short ENCODING_UNCHANGED = -1;
|
||||
public final static short ENCODING_COMPRESSED_UNICODE = 0;
|
||||
@ -105,7 +94,7 @@ public class HSSFCell implements Cell {
|
||||
*/
|
||||
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col)
|
||||
{
|
||||
checkBounds(col);
|
||||
checkBounds(col, book);
|
||||
_stringValue = null;
|
||||
_book = book;
|
||||
_sheet = sheet;
|
||||
@ -150,7 +139,7 @@ public class HSSFCell implements Cell {
|
||||
protected HSSFCell(HSSFWorkbook book, HSSFSheet sheet, int row, short col,
|
||||
CellType type)
|
||||
{
|
||||
checkBounds(col);
|
||||
checkBounds(col, book);
|
||||
_cellType = CellType._NONE; // Force 'setCellType' to create a first Record
|
||||
_stringValue = null;
|
||||
_book = book;
|
||||
@ -570,8 +559,8 @@ public class HSSFCell implements Cell {
|
||||
return;
|
||||
}
|
||||
|
||||
if(value.length() > org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getMaxTextLength()){
|
||||
throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters");
|
||||
if(value.length() > _book.getSpreadsheetVersion().getMaxTextLength()){
|
||||
throw new IllegalArgumentException("The maximum length of cell contents (text) is "+_book.getSpreadsheetVersion().getMaxTextLength()+" characters");
|
||||
}
|
||||
|
||||
if (_cellType == CellType.FORMULA) {
|
||||
@ -977,8 +966,10 @@ public class HSSFCell implements Cell {
|
||||
/**
|
||||
* @throws RuntimeException if the bounds are exceeded.
|
||||
*/
|
||||
private static void checkBounds(int cellIndex) {
|
||||
private static void checkBounds(int cellIndex, final HSSFWorkbook book) {
|
||||
final int LAST_COLUMN_NUMBER = book.getSpreadsheetVersion().getLastColumnIndex(); // 2^8 - 1
|
||||
if (cellIndex < 0 || cellIndex > LAST_COLUMN_NUMBER) {
|
||||
final String LAST_COLUMN_NAME = book.getSpreadsheetVersion().getLastColumnName();
|
||||
throw new IllegalArgumentException("Invalid column index (" + cellIndex
|
||||
+ "). Allowable column range for " + FILE_FORMAT_NAME + " is (0.."
|
||||
+ LAST_COLUMN_NUMBER + ") or ('A'..'" + LAST_COLUMN_NAME + "')");
|
||||
|
@ -29,8 +29,8 @@ import org.apache.poi.util.Removal;
|
||||
*/
|
||||
public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
|
||||
|
||||
public static final int MAX_COL = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastColumnIndex();
|
||||
public static final int MAX_ROW = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex();
|
||||
public static final int MAX_COL = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
|
||||
public static final int MAX_ROW = SpreadsheetVersion.EXCEL97.getLastRowIndex();
|
||||
|
||||
private EscherClientAnchorRecord _escherClientAnchor;
|
||||
|
||||
|
@ -296,7 +296,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
|
||||
|
||||
@Override
|
||||
public SpreadsheetVersion getSpreadsheetVersion(){
|
||||
return org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion;
|
||||
return _uBook.getSpreadsheetVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +129,7 @@ public final class HSSFName implements Name {
|
||||
* @throws IllegalArgumentException if the name is invalid or the name already exists (case-insensitive)
|
||||
*/
|
||||
public void setNameName(String nameName){
|
||||
validateName(nameName);
|
||||
validateName(nameName, _book.getSpreadsheetVersion());
|
||||
|
||||
InternalWorkbook wb = _book.getWorkbook();
|
||||
_definedNameRec.setNameText(nameName);
|
||||
@ -178,7 +178,7 @@ public final class HSSFName implements Name {
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
private static void validateName(String name) {
|
||||
private static void validateName(String name, SpreadsheetVersion spreadsheetVersion) {
|
||||
|
||||
if (name.length() == 0) {
|
||||
throw new IllegalArgumentException("Name cannot be blank");
|
||||
@ -212,7 +212,7 @@ public final class HSSFName implements Name {
|
||||
if (name.matches("[A-Za-z]+\\d+")) {
|
||||
String col = name.replaceAll("\\d", "");
|
||||
String row = name.replaceAll("[A-Za-z]", "");
|
||||
if (CellReference.cellReferenceIsWithinRange(col, row, org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion)) {
|
||||
if (CellReference.cellReferenceIsWithinRange(col, row, spreadsheetVersion)) {
|
||||
throw new IllegalArgumentException("Invalid name: '"+name+"': cannot be $A$1-style cell reference");
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ public final class HSSFRow implements Row, Comparable<HSSFRow> {
|
||||
*/
|
||||
@Override
|
||||
public void setRowNum(int rowIndex) {
|
||||
int maxrow = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex();
|
||||
int maxrow = book.getSpreadsheetVersion().getLastRowIndex();
|
||||
if ((rowIndex < 0) || (rowIndex > maxrow)) {
|
||||
throw new IllegalArgumentException("Invalid row number (" + rowIndex
|
||||
+ ") outside allowable range (0.." + maxrow + ")");
|
||||
|
@ -123,7 +123,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createSheet()
|
||||
*/
|
||||
protected HSSFSheet(HSSFWorkbook workbook) {
|
||||
_sheet = InternalSheet.createSheet();
|
||||
_sheet = InternalSheet.createSheet(workbook.getSpreadsheetVersion());
|
||||
_rows = new TreeMap<Integer, HSSFRow>();
|
||||
this._workbook = workbook;
|
||||
this._book = workbook.getWorkbook();
|
||||
@ -715,7 +715,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
if (region.getNumberOfCells() < 2) {
|
||||
throw new IllegalArgumentException("Merged region " + region.formatAsString() + " must contain 2 or more cells");
|
||||
}
|
||||
region.validate(org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion);
|
||||
region.validate(_workbook.getSpreadsheetVersion());
|
||||
|
||||
if (validate) {
|
||||
// throw IllegalStateException if the argument CellRangeAddress intersects with
|
||||
@ -1453,7 +1453,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
*/
|
||||
@Override
|
||||
public void showInPane(int toprow, int leftcol) {
|
||||
int maxrow = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex();
|
||||
final int maxrow = _workbook.getSpreadsheetVersion().getLastRowIndex();
|
||||
if (toprow > maxrow) throw new IllegalArgumentException("Maximum row number is " + maxrow);
|
||||
|
||||
showInPane((short)toprow, (short)leftcol);
|
||||
@ -1530,10 +1530,10 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
*
|
||||
* @param row the row number
|
||||
*/
|
||||
private static int clip(int row) {
|
||||
private int clip(int row) {
|
||||
return Math.min(
|
||||
Math.max(0, row),
|
||||
org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex());
|
||||
_workbook.getSpreadsheetVersion().getLastRowIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1677,7 +1677,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
}
|
||||
}
|
||||
if (endRow + n > _lastrow) {
|
||||
_lastrow = Math.min(endRow + n, org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex());
|
||||
_lastrow = Math.min(endRow + n, _workbook.getSpreadsheetVersion().getLastRowIndex());
|
||||
}
|
||||
} else {
|
||||
// Rows are moving up
|
||||
@ -1687,7 +1687,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
if (endRow == _lastrow) {
|
||||
// Need to walk backward to find the last non-blank row
|
||||
// NOTE: n is always negative here
|
||||
_lastrow = Math.min(endRow + n, org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex());
|
||||
_lastrow = Math.min(endRow + n, _workbook.getSpreadsheetVersion().getLastRowIndex());
|
||||
for (int i = endRow - 1; i > endRow + n; i--) {
|
||||
if (getRow(i) != null) {
|
||||
_lastrow = i;
|
||||
@ -1703,7 +1703,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
String sheetName = _workbook.getSheetName(sheetIndex);
|
||||
short externSheetIndex = _book.checkExternSheet(sheetIndex);
|
||||
FormulaShifter shifter = FormulaShifter.createForRowShift(
|
||||
externSheetIndex, sheetName, startRow, endRow, n, org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion);
|
||||
externSheetIndex, sheetName, startRow, endRow, n, _workbook.getSpreadsheetVersion());
|
||||
_sheet.updateFormulasAfterCellShift(shifter, externSheetIndex);
|
||||
|
||||
int nSheets = _workbook.getNumberOfSheets();
|
||||
@ -1923,7 +1923,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
@Override
|
||||
public void setColumnBreak(int column) {
|
||||
validateColumn((short) column);
|
||||
_sheet.getPageSettings().setColumnBreak((short) column, (short) 0, (short) org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex());
|
||||
_sheet.getPageSettings().setColumnBreak((short) column, (short) 0, (short) _workbook.getSpreadsheetVersion().getLastRowIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1953,7 +1953,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
* @param row the index of the row to validate, zero-based
|
||||
*/
|
||||
protected void validateRow(int row) {
|
||||
int maxrow = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex();
|
||||
final int maxrow = _workbook.getSpreadsheetVersion().getLastRowIndex();
|
||||
if (row > maxrow) throw new IllegalArgumentException("Maximum row number is " + maxrow);
|
||||
if (row < 0) throw new IllegalArgumentException("Minumum row number is 0");
|
||||
}
|
||||
@ -1964,7 +1964,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
* @param column the index of the column to validate, zero-based
|
||||
*/
|
||||
protected void validateColumn(int column) {
|
||||
int maxcol = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastColumnIndex();
|
||||
final int maxcol = _workbook.getSpreadsheetVersion().getLastColumnIndex();
|
||||
if (column > maxcol) throw new IllegalArgumentException("Maximum column number is " + maxcol);
|
||||
if (column < 0) throw new IllegalArgumentException("Minimum column number is 0");
|
||||
}
|
||||
@ -2496,8 +2496,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
private void setRepeatingRowsAndColumns(
|
||||
CellRangeAddress rowDef, CellRangeAddress colDef) {
|
||||
int sheetIndex = _workbook.getSheetIndex(this);
|
||||
int maxRowIndex = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex();
|
||||
int maxColIndex = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastColumnIndex();
|
||||
final int maxRowIndex = _workbook.getSpreadsheetVersion().getLastRowIndex();
|
||||
final int maxColIndex = _workbook.getSpreadsheetVersion().getLastColumnIndex();
|
||||
|
||||
int col1 = -1;
|
||||
int col2 = -1;
|
||||
@ -2582,8 +2582,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
return null;
|
||||
}
|
||||
|
||||
int maxRowIndex = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex();
|
||||
int maxColIndex = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastColumnIndex();
|
||||
final int maxRowIndex = _workbook.getSpreadsheetVersion().getLastRowIndex();
|
||||
final int maxColIndex = _workbook.getSpreadsheetVersion().getLastColumnIndex();
|
||||
|
||||
for (Ptg ptg : nameDefinition) {
|
||||
|
||||
|
@ -174,7 +174,7 @@ public final class HSSFSheetConditionalFormatting implements SheetConditionalFor
|
||||
if (regions == null) {
|
||||
throw new IllegalArgumentException("regions must not be null");
|
||||
}
|
||||
for(CellRangeAddress range : regions) range.validate(org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion);
|
||||
for(CellRangeAddress range : regions) range.validate(_sheet._workbook.getSpreadsheetVersion());
|
||||
|
||||
if (cfRules == null) {
|
||||
throw new IllegalArgumentException("cfRules must not be null");
|
||||
|
@ -124,7 +124,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
private static final Pattern COMMA_PATTERN = Pattern.compile(",");
|
||||
|
||||
// org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion
|
||||
public static SpreadsheetVersion spreadsheetVersion = SpreadsheetVersion. EXCEL97;
|
||||
public final SpreadsheetVersion spreadsheetVersion;
|
||||
|
||||
/**
|
||||
* The maximum number of cell styles in a .xls workbook.
|
||||
@ -210,8 +210,19 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
this(InternalWorkbook.createWorkbook());
|
||||
}
|
||||
|
||||
public HSSFWorkbook(final SpreadsheetVersion spreadsheetVersion) {
|
||||
this(InternalWorkbook.createWorkbook(), spreadsheetVersion);
|
||||
if(spreadsheetVersion == null)
|
||||
throw new IllegalArgumentException("SpreadsheetVersion must be non-null");
|
||||
}
|
||||
|
||||
private HSSFWorkbook(InternalWorkbook book) {
|
||||
this(book, SpreadsheetVersion.EXCEL97);
|
||||
}
|
||||
|
||||
private HSSFWorkbook(InternalWorkbook book, final SpreadsheetVersion spreadsheetVersion) {
|
||||
super((DirectoryNode)null);
|
||||
this.spreadsheetVersion = spreadsheetVersion;
|
||||
workbook = book;
|
||||
_sheets = new ArrayList<HSSFSheet>(INITIAL_CAPACITY);
|
||||
names = new ArrayList<HSSFName>(INITIAL_CAPACITY);
|
||||
@ -331,6 +342,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
throws IOException
|
||||
{
|
||||
super(directory);
|
||||
spreadsheetVersion = SpreadsheetVersion.EXCEL97;
|
||||
String workbookName = getWorkbookDirEntryName(directory);
|
||||
|
||||
this.preserveNodes = preserveNodes;
|
||||
@ -1366,6 +1378,12 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
super.close();
|
||||
}
|
||||
|
||||
protected void validateSpreadsheetVersionWritePossible() throws IllegalStateException {
|
||||
if (this.spreadsheetVersion != SpreadsheetVersion.EXCEL97) {
|
||||
throw new IllegalStateException("SpreadsheetVersion not EXCEL97, cannot write file meant only for in-memory calculations");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out this workbook to the currently open {@link File} via the
|
||||
* writeable {@link POIFSFileSystem} it was opened as.
|
||||
@ -1378,6 +1396,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
*/
|
||||
@Override
|
||||
public void write() throws IOException {
|
||||
validateSpreadsheetVersionWritePossible();
|
||||
validateInPlaceWritePossible();
|
||||
final DirectoryNode dir = getDirectory();
|
||||
|
||||
@ -1411,6 +1430,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
*/
|
||||
@Override
|
||||
public void write(File newFile) throws IOException {
|
||||
validateSpreadsheetVersionWritePossible();
|
||||
POIFSFileSystem fs = POIFSFileSystem.create(newFile);
|
||||
try {
|
||||
write(fs);
|
||||
@ -1437,6 +1457,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
*/
|
||||
@Override
|
||||
public void write(OutputStream stream) throws IOException {
|
||||
validateSpreadsheetVersionWritePossible();
|
||||
NPOIFSFileSystem fs = new NPOIFSFileSystem();
|
||||
try {
|
||||
write(fs);
|
||||
@ -1448,6 +1469,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
|
||||
/** Writes the workbook out to a brand new, empty POIFS */
|
||||
private void write(NPOIFSFileSystem fs) throws IOException {
|
||||
validateSpreadsheetVersionWritePossible();
|
||||
// For tracking what we've written out, used if we're
|
||||
// going to be preserving nodes
|
||||
List<String> excepts = new ArrayList<String>(1);
|
||||
@ -2328,6 +2350,6 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
*/
|
||||
@Override
|
||||
public SpreadsheetVersion getSpreadsheetVersion() {
|
||||
return org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion;
|
||||
return this.spreadsheetVersion;
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ public final class FormulaParser {
|
||||
_formulaString = formula;
|
||||
_pointer=0;
|
||||
_book = book;
|
||||
_ssVersion = book == null ? org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion : book.getSpreadsheetVersion();
|
||||
_ssVersion = book == null ? SpreadsheetVersion.EXCEL97 : book.getSpreadsheetVersion();
|
||||
_formulaLength = _formulaString.length();
|
||||
_sheetIndex = sheetIndex;
|
||||
_rowIndex = rowIndex;
|
||||
|
@ -184,7 +184,7 @@ public final class SheetNameFormatter {
|
||||
* @see org.apache.poi.ss.util.CellReference
|
||||
*/
|
||||
/* package */ static boolean cellReferenceIsWithinRange(String lettersPrefix, String numbersSuffix) {
|
||||
return CellReference.cellReferenceIsWithinRange(lettersPrefix, numbersSuffix, org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion);
|
||||
return CellReference.cellReferenceIsWithinRange(lettersPrefix, numbersSuffix, SpreadsheetVersion.EXCEL97);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -286,7 +286,7 @@ public abstract class AreaPtgBase extends OperandPtg implements AreaI {
|
||||
CellReference topLeft = new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative());
|
||||
CellReference botRight = new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative());
|
||||
|
||||
if(AreaReference.isWholeColumnReference(org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion, topLeft, botRight)) {
|
||||
if(AreaReference.isWholeColumnReference(SpreadsheetVersion.EXCEL97, topLeft, botRight)) {
|
||||
return (new AreaReference(topLeft, botRight)).formatAsString();
|
||||
}
|
||||
return topLeft.formatAsString() + ":" + botRight.formatAsString();
|
||||
|
@ -31,7 +31,7 @@ public class AreaReference {
|
||||
private static final char CELL_DELIMITER = ':';
|
||||
/** The character (') used to quote sheet names when they contain special characters */
|
||||
private static final char SPECIAL_NAME_DELIMITER = '\'';
|
||||
private static final SpreadsheetVersion DEFAULT_SPREADSHEET_VERSION = org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion;
|
||||
private static final SpreadsheetVersion DEFAULT_SPREADSHEET_VERSION = SpreadsheetVersion.EXCEL97;
|
||||
|
||||
private final CellReference _firstCell;
|
||||
private final CellReference _lastCell;
|
||||
|
@ -75,12 +75,12 @@ public abstract class CellRangeAddressBase {
|
||||
|
||||
//TODO use the correct SpreadsheetVersion
|
||||
public final boolean isFullColumnRange() {
|
||||
return (_firstRow == 0 && _lastRow == org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastRowIndex())
|
||||
return (_firstRow == 0 && _lastRow == SpreadsheetVersion.EXCEL97.getLastRowIndex())
|
||||
|| (_firstRow == -1 && _lastRow == -1);
|
||||
}
|
||||
//TODO use the correct SpreadsheetVersion
|
||||
public final boolean isFullRowRange() {
|
||||
return (_firstCol == 0 && _lastCol == org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion.getLastColumnIndex())
|
||||
return (_firstCol == 0 && _lastCol == SpreadsheetVersion.EXCEL97.getLastColumnIndex())
|
||||
|| (_firstCol == -1 && _lastCol == -1);
|
||||
}
|
||||
|
||||
|
@ -402,7 +402,7 @@ public final class XSSFName implements Name {
|
||||
if (name.matches("[A-Za-z]+\\d+")) {
|
||||
String col = name.replaceAll("\\d", "");
|
||||
String row = name.replaceAll("[A-Za-z]", "");
|
||||
if (CellReference.cellReferenceIsWithinRange(col, row, org.apache.poi.hssf.usermodel.HSSFWorkbook.spreadsheetVersion)) {
|
||||
if (CellReference.cellReferenceIsWithinRange(col, row, SpreadsheetVersion.EXCEL97)) { // todo: is EXCEL97 correct? sounds wrong...
|
||||
throw new IllegalArgumentException("Invalid name: '"+name+"': cannot be $A$1-style cell reference");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user