You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 20:56:49 UTC
svn commit: r1890120 [10/43] - in /poi/trunk/poi/src:
main/java/org/apache/poi/ main/java/org/apache/poi/ddf/
main/java/org/apache/poi/extractor/ main/java/org/apache/poi/hpsf/
main/java/org/apache/poi/hssf/ main/java/org/apache/poi/hssf/dev/
main/java...
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/DataValidityTable.java Sat May 22 20:56:44 2021
@@ -30,38 +30,38 @@ import org.apache.poi.hssf.record.DVReco
*/
public final class DataValidityTable extends RecordAggregate {
- private final DVALRecord _headerRec;
- /**
- * The list of data validations for the current sheet.
- * Note - this may be empty (contrary to OOO documentation)
- */
- private final List<DVRecord> _validationList;
+ private final DVALRecord _headerRec;
+ /**
+ * The list of data validations for the current sheet.
+ * Note - this may be empty (contrary to OOO documentation)
+ */
+ private final List<DVRecord> _validationList;
- public DataValidityTable(RecordStream rs) {
- _headerRec = (DVALRecord) rs.getNext();
- List<DVRecord> temp = new ArrayList<>();
- while (rs.peekNextClass() == DVRecord.class) {
- temp.add((DVRecord) rs.getNext());
- }
- _validationList = temp;
- }
+ public DataValidityTable(RecordStream rs) {
+ _headerRec = (DVALRecord) rs.getNext();
+ List<DVRecord> temp = new ArrayList<>();
+ while (rs.peekNextClass() == DVRecord.class) {
+ temp.add((DVRecord) rs.getNext());
+ }
+ _validationList = temp;
+ }
- public DataValidityTable() {
- _headerRec = new DVALRecord();
- _validationList = new ArrayList<>();
- }
+ public DataValidityTable() {
+ _headerRec = new DVALRecord();
+ _validationList = new ArrayList<>();
+ }
- @Override
+ @Override
public void visitContainedRecords(RecordVisitor rv) {
- if (_validationList.isEmpty()) {
- return;
- }
- rv.visitRecord(_headerRec);
- _validationList.forEach(rv::visitRecord);
- }
+ if (_validationList.isEmpty()) {
+ return;
+ }
+ rv.visitRecord(_headerRec);
+ _validationList.forEach(rv::visitRecord);
+ }
- public void addDataValidation(DVRecord dvRecord) {
- _validationList.add(dvRecord);
- _headerRec.setDVRecNo(_validationList.size());
- }
+ public void addDataValidation(DVRecord dvRecord) {
+ _validationList.add(dvRecord);
+ _headerRec.setDVRecNo(_validationList.size());
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java Sat May 22 20:56:44 2021
@@ -38,235 +38,235 @@ import org.apache.poi.util.RecordFormatE
*/
public final class FormulaRecordAggregate extends RecordAggregate implements CellValueRecordInterface {
- private final FormulaRecord _formulaRecord;
- private SharedValueManager _sharedValueManager;
- /** caches the calculated result of the formula */
- private StringRecord _stringRecord;
- private SharedFormulaRecord _sharedFormulaRecord;
-
- /**
- * @param stringRec may be <code>null</code> if this formula does not have a cached text
- * value.
- * @param svm the {@link SharedValueManager} for the current sheet
- */
- public FormulaRecordAggregate(FormulaRecord formulaRec, StringRecord stringRec, SharedValueManager svm) {
- if (svm == null) {
- throw new IllegalArgumentException("sfm must not be null");
- }
- if (formulaRec.hasCachedResultString()) {
- if (stringRec == null) {
- throw new RecordFormatException("Formula record flag is set but String record was not found");
- }
- _stringRecord = stringRec;
- } else {
- // Usually stringRec is null here (in agreement with what the formula rec says).
- // In the case where an extra StringRecord is erroneously present, Excel (2007)
- // ignores it (see bug 46213).
- _stringRecord = null;
- }
-
- _formulaRecord = formulaRec;
- _sharedValueManager = svm;
- if (formulaRec.isSharedFormula()) {
- CellReference firstCell = formulaRec.getFormula().getExpReference();
- if (firstCell == null) {
- handleMissingSharedFormulaRecord(formulaRec);
- } else {
- _sharedFormulaRecord = svm.linkSharedFormulaRecord(firstCell, this);
- }
- }
- }
-
- /**
- * Sometimes the shared formula flag "seems" to be erroneously set (because the corresponding
- * {@link SharedFormulaRecord} does not exist). Normally this would leave no way of determining
- * the {@link Ptg} tokens for the formula. However as it turns out in these
- * cases, Excel encodes the unshared {@link Ptg} tokens in the right place (inside the {@link
- * FormulaRecord}). So the the only thing that needs to be done is to ignore the erroneous
- * shared formula flag.<br>
- *
- * This method may also be used for setting breakpoints to help diagnose issues regarding the
- * abnormally-set 'shared formula' flags.
- * (see TestValueRecordsAggregate.testSpuriousSharedFormulaFlag()).<p>
- */
- private static void handleMissingSharedFormulaRecord(FormulaRecord formula) {
- // make sure 'unshared' formula is actually available
- Ptg firstToken = formula.getParsedExpression()[0];
- if (firstToken instanceof ExpPtg) {
- throw new RecordFormatException(
- "SharedFormulaRecord not found for FormulaRecord with (isSharedFormula=true)");
- }
- // could log an info message here since this is a fairly unusual occurrence.
- formula.setSharedFormula(false); // no point leaving the flag erroneously set
- }
-
- public FormulaRecord getFormulaRecord() {
- return _formulaRecord;
- }
-
- /**
- * debug only
- * TODO - encapsulate
- */
- public StringRecord getStringRecord() {
- return _stringRecord;
- }
-
- public short getXFIndex() {
- return _formulaRecord.getXFIndex();
- }
-
- public void setXFIndex(short xf) {
- _formulaRecord.setXFIndex(xf);
- }
-
- public void setColumn(short col) {
- _formulaRecord.setColumn(col);
- }
-
- public void setRow(int row) {
- _formulaRecord.setRow(row);
- }
-
- public short getColumn() {
- return _formulaRecord.getColumn();
- }
-
- public int getRow() {
- return _formulaRecord.getRow();
- }
-
- public String toString() {
- return _formulaRecord.toString();
- }
+ private final FormulaRecord _formulaRecord;
+ private SharedValueManager _sharedValueManager;
+ /** caches the calculated result of the formula */
+ private StringRecord _stringRecord;
+ private SharedFormulaRecord _sharedFormulaRecord;
+
+ /**
+ * @param stringRec may be <code>null</code> if this formula does not have a cached text
+ * value.
+ * @param svm the {@link SharedValueManager} for the current sheet
+ */
+ public FormulaRecordAggregate(FormulaRecord formulaRec, StringRecord stringRec, SharedValueManager svm) {
+ if (svm == null) {
+ throw new IllegalArgumentException("sfm must not be null");
+ }
+ if (formulaRec.hasCachedResultString()) {
+ if (stringRec == null) {
+ throw new RecordFormatException("Formula record flag is set but String record was not found");
+ }
+ _stringRecord = stringRec;
+ } else {
+ // Usually stringRec is null here (in agreement with what the formula rec says).
+ // In the case where an extra StringRecord is erroneously present, Excel (2007)
+ // ignores it (see bug 46213).
+ _stringRecord = null;
+ }
+
+ _formulaRecord = formulaRec;
+ _sharedValueManager = svm;
+ if (formulaRec.isSharedFormula()) {
+ CellReference firstCell = formulaRec.getFormula().getExpReference();
+ if (firstCell == null) {
+ handleMissingSharedFormulaRecord(formulaRec);
+ } else {
+ _sharedFormulaRecord = svm.linkSharedFormulaRecord(firstCell, this);
+ }
+ }
+ }
+
+ /**
+ * Sometimes the shared formula flag "seems" to be erroneously set (because the corresponding
+ * {@link SharedFormulaRecord} does not exist). Normally this would leave no way of determining
+ * the {@link Ptg} tokens for the formula. However as it turns out in these
+ * cases, Excel encodes the unshared {@link Ptg} tokens in the right place (inside the {@link
+ * FormulaRecord}). So the the only thing that needs to be done is to ignore the erroneous
+ * shared formula flag.<br>
+ *
+ * This method may also be used for setting breakpoints to help diagnose issues regarding the
+ * abnormally-set 'shared formula' flags.
+ * (see TestValueRecordsAggregate.testSpuriousSharedFormulaFlag()).<p>
+ */
+ private static void handleMissingSharedFormulaRecord(FormulaRecord formula) {
+ // make sure 'unshared' formula is actually available
+ Ptg firstToken = formula.getParsedExpression()[0];
+ if (firstToken instanceof ExpPtg) {
+ throw new RecordFormatException(
+ "SharedFormulaRecord not found for FormulaRecord with (isSharedFormula=true)");
+ }
+ // could log an info message here since this is a fairly unusual occurrence.
+ formula.setSharedFormula(false); // no point leaving the flag erroneously set
+ }
+
+ public FormulaRecord getFormulaRecord() {
+ return _formulaRecord;
+ }
+
+ /**
+ * debug only
+ * TODO - encapsulate
+ */
+ public StringRecord getStringRecord() {
+ return _stringRecord;
+ }
+
+ public short getXFIndex() {
+ return _formulaRecord.getXFIndex();
+ }
+
+ public void setXFIndex(short xf) {
+ _formulaRecord.setXFIndex(xf);
+ }
+
+ public void setColumn(short col) {
+ _formulaRecord.setColumn(col);
+ }
+
+ public void setRow(int row) {
+ _formulaRecord.setRow(row);
+ }
+
+ public short getColumn() {
+ return _formulaRecord.getColumn();
+ }
+
+ public int getRow() {
+ return _formulaRecord.getRow();
+ }
+
+ public String toString() {
+ return _formulaRecord.toString();
+ }
- @Override
+ @Override
public void visitContainedRecords(RecordVisitor rv) {
- rv.visitRecord(_formulaRecord);
- Record sharedFormulaRecord = _sharedValueManager.getRecordForFirstCell(this);
- if (sharedFormulaRecord != null) {
- rv.visitRecord(sharedFormulaRecord);
- }
- if (_formulaRecord.hasCachedResultString() && _stringRecord != null) {
- rv.visitRecord(_stringRecord);
- }
- }
-
- public String getStringValue() {
- if(_stringRecord==null) {
- return null;
- }
- return _stringRecord.getString();
- }
-
- public void setCachedStringResult(String value) {
-
- // Save the string into a String Record, creating one if required
- if(_stringRecord == null) {
- _stringRecord = new StringRecord();
- }
- _stringRecord.setString(value);
- if (value.length() < 1) {
- _formulaRecord.setCachedResultTypeEmptyString();
- } else {
- _formulaRecord.setCachedResultTypeString();
- }
- }
- public void setCachedBooleanResult(boolean value) {
- _stringRecord = null;
- _formulaRecord.setCachedResultBoolean(value);
- }
- public void setCachedErrorResult(int errorCode) {
- _stringRecord = null;
- _formulaRecord.setCachedResultErrorCode(errorCode);
- }
- public void setCachedErrorResult(FormulaError error) {
- setCachedErrorResult(error.getCode());
- }
- public void setCachedDoubleResult(double value) {
- _stringRecord = null;
- _formulaRecord.setValue(value);
- }
-
- public Ptg[] getFormulaTokens() {
- if (_sharedFormulaRecord != null) {
- return _sharedFormulaRecord.getFormulaTokens(_formulaRecord);
- }
- CellReference expRef = _formulaRecord.getFormula().getExpReference();
- if (expRef != null) {
- ArrayRecord arec = _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol());
- return arec.getFormulaTokens();
- }
- return _formulaRecord.getParsedExpression();
- }
-
- /**
- * Also checks for a related shared formula and unlinks it if found
- */
- public void setParsedExpression(Ptg[] ptgs) {
- notifyFormulaChanging();
- _formulaRecord.setParsedExpression(ptgs);
- }
-
- public void unlinkSharedFormula() {
- SharedFormulaRecord sfr = _sharedFormulaRecord;
- if (sfr == null) {
- throw new IllegalStateException("Formula not linked to shared formula");
- }
- Ptg[] ptgs = sfr.getFormulaTokens(_formulaRecord);
- _formulaRecord.setParsedExpression(ptgs);
- //Now its not shared!
- _formulaRecord.setSharedFormula(false);
- _sharedFormulaRecord = null;
- }
- /**
- * Should be called by any code which is either deleting this formula cell, or changing
- * its type. This method gives the aggregate a chance to unlink any shared formula
- * that may be involved with this cell formula.
- */
- public void notifyFormulaChanging() {
- if (_sharedFormulaRecord != null) {
- _sharedValueManager.unlink(_sharedFormulaRecord);
- }
- }
- public boolean isPartOfArrayFormula() {
- if (_sharedFormulaRecord != null) {
- return false;
- }
+ rv.visitRecord(_formulaRecord);
+ Record sharedFormulaRecord = _sharedValueManager.getRecordForFirstCell(this);
+ if (sharedFormulaRecord != null) {
+ rv.visitRecord(sharedFormulaRecord);
+ }
+ if (_formulaRecord.hasCachedResultString() && _stringRecord != null) {
+ rv.visitRecord(_stringRecord);
+ }
+ }
+
+ public String getStringValue() {
+ if(_stringRecord==null) {
+ return null;
+ }
+ return _stringRecord.getString();
+ }
+
+ public void setCachedStringResult(String value) {
+
+ // Save the string into a String Record, creating one if required
+ if(_stringRecord == null) {
+ _stringRecord = new StringRecord();
+ }
+ _stringRecord.setString(value);
+ if (value.length() < 1) {
+ _formulaRecord.setCachedResultTypeEmptyString();
+ } else {
+ _formulaRecord.setCachedResultTypeString();
+ }
+ }
+ public void setCachedBooleanResult(boolean value) {
+ _stringRecord = null;
+ _formulaRecord.setCachedResultBoolean(value);
+ }
+ public void setCachedErrorResult(int errorCode) {
+ _stringRecord = null;
+ _formulaRecord.setCachedResultErrorCode(errorCode);
+ }
+ public void setCachedErrorResult(FormulaError error) {
+ setCachedErrorResult(error.getCode());
+ }
+ public void setCachedDoubleResult(double value) {
+ _stringRecord = null;
+ _formulaRecord.setValue(value);
+ }
+
+ public Ptg[] getFormulaTokens() {
+ if (_sharedFormulaRecord != null) {
+ return _sharedFormulaRecord.getFormulaTokens(_formulaRecord);
+ }
+ CellReference expRef = _formulaRecord.getFormula().getExpReference();
+ if (expRef != null) {
+ ArrayRecord arec = _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol());
+ return arec.getFormulaTokens();
+ }
+ return _formulaRecord.getParsedExpression();
+ }
+
+ /**
+ * Also checks for a related shared formula and unlinks it if found
+ */
+ public void setParsedExpression(Ptg[] ptgs) {
+ notifyFormulaChanging();
+ _formulaRecord.setParsedExpression(ptgs);
+ }
+
+ public void unlinkSharedFormula() {
+ SharedFormulaRecord sfr = _sharedFormulaRecord;
+ if (sfr == null) {
+ throw new IllegalStateException("Formula not linked to shared formula");
+ }
+ Ptg[] ptgs = sfr.getFormulaTokens(_formulaRecord);
+ _formulaRecord.setParsedExpression(ptgs);
+ //Now its not shared!
+ _formulaRecord.setSharedFormula(false);
+ _sharedFormulaRecord = null;
+ }
+ /**
+ * Should be called by any code which is either deleting this formula cell, or changing
+ * its type. This method gives the aggregate a chance to unlink any shared formula
+ * that may be involved with this cell formula.
+ */
+ public void notifyFormulaChanging() {
+ if (_sharedFormulaRecord != null) {
+ _sharedValueManager.unlink(_sharedFormulaRecord);
+ }
+ }
+ public boolean isPartOfArrayFormula() {
+ if (_sharedFormulaRecord != null) {
+ return false;
+ }
CellReference expRef = _formulaRecord.getFormula().getExpReference();
ArrayRecord arec = expRef == null ? null : _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol());
- return arec != null;
- }
+ return arec != null;
+ }
- public CellRangeAddress getArrayFormulaRange() {
- if (_sharedFormulaRecord != null) {
- throw new IllegalStateException("not an array formula cell.");
- }
- CellReference expRef = _formulaRecord.getFormula().getExpReference();
- if (expRef == null) {
- throw new IllegalStateException("not an array formula cell.");
- }
- ArrayRecord arec = _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol());
- if (arec == null) {
- throw new IllegalStateException("ArrayRecord was not found for the locator " + expRef.formatAsString());
- }
- CellRangeAddress8Bit a = arec.getRange();
- return new CellRangeAddress(a.getFirstRow(), a.getLastRow(), a.getFirstColumn(),a.getLastColumn());
- }
-
- public void setArrayFormula(CellRangeAddress r, Ptg[] ptgs) {
-
- ArrayRecord arr = new ArrayRecord(Formula.create(ptgs), new CellRangeAddress8Bit(r.getFirstRow(), r.getLastRow(), r.getFirstColumn(), r.getLastColumn()));
- _sharedValueManager.addArrayRecord(arr);
- }
- /**
- * Removes an array formula
- * @return the range of the array formula containing the specified cell. Never <code>null</code>
- */
- public CellRangeAddress removeArrayFormula(int rowIndex, int columnIndex) {
- CellRangeAddress8Bit a = _sharedValueManager.removeArrayFormula(rowIndex, columnIndex);
+ public CellRangeAddress getArrayFormulaRange() {
+ if (_sharedFormulaRecord != null) {
+ throw new IllegalStateException("not an array formula cell.");
+ }
+ CellReference expRef = _formulaRecord.getFormula().getExpReference();
+ if (expRef == null) {
+ throw new IllegalStateException("not an array formula cell.");
+ }
+ ArrayRecord arec = _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol());
+ if (arec == null) {
+ throw new IllegalStateException("ArrayRecord was not found for the locator " + expRef.formatAsString());
+ }
+ CellRangeAddress8Bit a = arec.getRange();
+ return new CellRangeAddress(a.getFirstRow(), a.getLastRow(), a.getFirstColumn(),a.getLastColumn());
+ }
+
+ public void setArrayFormula(CellRangeAddress r, Ptg[] ptgs) {
+
+ ArrayRecord arr = new ArrayRecord(Formula.create(ptgs), new CellRangeAddress8Bit(r.getFirstRow(), r.getLastRow(), r.getFirstColumn(), r.getLastColumn()));
+ _sharedValueManager.addArrayRecord(arr);
+ }
+ /**
+ * Removes an array formula
+ * @return the range of the array formula containing the specified cell. Never <code>null</code>
+ */
+ public CellRangeAddress removeArrayFormula(int rowIndex, int columnIndex) {
+ CellRangeAddress8Bit a = _sharedValueManager.removeArrayFormula(rowIndex, columnIndex);
// at this point FormulaRecordAggregate#isPartOfArrayFormula() should return false
_formulaRecord.setParsedExpression(null);
return new CellRangeAddress(a.getFirstRow(), a.getLastRow(), a.getFirstColumn(), a.getLastColumn());
- }
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/MergedCellsTable.java Sat May 22 20:56:44 2021
@@ -26,106 +26,106 @@ import org.apache.poi.ss.util.CellRangeA
import org.apache.poi.ss.util.CellRangeAddressList;
public final class MergedCellsTable extends RecordAggregate {
- // enforced by the 8224 byte limit
- private static final int MAX_MERGED_REGIONS = 1027;
+ // enforced by the 8224 byte limit
+ private static final int MAX_MERGED_REGIONS = 1027;
- private final List<CellRangeAddress> _mergedRegions;
+ private final List<CellRangeAddress> _mergedRegions;
- /**
- * Creates an empty aggregate
- */
- public MergedCellsTable() {
- _mergedRegions = new ArrayList<>();
- }
-
- /**
- * reads zero or more consecutive {@link MergeCellsRecord}s
- */
- public void read(RecordStream rs) {
+ /**
+ * Creates an empty aggregate
+ */
+ public MergedCellsTable() {
+ _mergedRegions = new ArrayList<>();
+ }
+
+ /**
+ * reads zero or more consecutive {@link MergeCellsRecord}s
+ */
+ public void read(RecordStream rs) {
while (rs.peekNextClass() == MergeCellsRecord.class) {
- MergeCellsRecord mcr = (MergeCellsRecord) rs.getNext();
- int nRegions = mcr.getNumAreas();
- for (int i = 0; i < nRegions; i++) {
- CellRangeAddress cra = mcr.getAreaAt(i);
- _mergedRegions.add(cra);
- }
- }
- }
-
- @Override
- public int getRecordSize() {
- // a bit cheaper than the default impl
- int nRegions = _mergedRegions.size();
- if (nRegions < 1) {
- // no need to write a single empty MergeCellsRecord
- return 0;
- }
- int nMergedCellsRecords = nRegions / MAX_MERGED_REGIONS;
- int nLeftoverMergedRegions = nRegions % MAX_MERGED_REGIONS;
+ MergeCellsRecord mcr = (MergeCellsRecord) rs.getNext();
+ int nRegions = mcr.getNumAreas();
+ for (int i = 0; i < nRegions; i++) {
+ CellRangeAddress cra = mcr.getAreaAt(i);
+ _mergedRegions.add(cra);
+ }
+ }
+ }
+
+ @Override
+ public int getRecordSize() {
+ // a bit cheaper than the default impl
+ int nRegions = _mergedRegions.size();
+ if (nRegions < 1) {
+ // no need to write a single empty MergeCellsRecord
+ return 0;
+ }
+ int nMergedCellsRecords = nRegions / MAX_MERGED_REGIONS;
+ int nLeftoverMergedRegions = nRegions % MAX_MERGED_REGIONS;
return nMergedCellsRecords
* (4 + CellRangeAddressList.getEncodedSize(MAX_MERGED_REGIONS)) + 4
+ CellRangeAddressList.getEncodedSize(nLeftoverMergedRegions);
- }
+ }
- @Override
+ @Override
public void visitContainedRecords(RecordVisitor rv) {
- int nRegions = _mergedRegions.size();
- if (nRegions < 1) {
- // no need to write a single empty MergeCellsRecord
- return;
- }
-
- int nFullMergedCellsRecords = nRegions / MAX_MERGED_REGIONS;
- int nLeftoverMergedRegions = nRegions % MAX_MERGED_REGIONS;
- CellRangeAddress[] cras = new CellRangeAddress[nRegions];
- _mergedRegions.toArray(cras);
-
- for (int i = 0; i < nFullMergedCellsRecords; i++) {
- int startIx = i * MAX_MERGED_REGIONS;
- rv.visitRecord(new MergeCellsRecord(cras, startIx, MAX_MERGED_REGIONS));
- }
- if (nLeftoverMergedRegions > 0) {
- int startIx = nFullMergedCellsRecords * MAX_MERGED_REGIONS;
- rv.visitRecord(new MergeCellsRecord(cras, startIx, nLeftoverMergedRegions));
- }
- }
- public void addRecords(MergeCellsRecord[] mcrs) {
- for (MergeCellsRecord mcr : mcrs) {
- addMergeCellsRecord(mcr);
- }
- }
-
- private void addMergeCellsRecord(MergeCellsRecord mcr) {
- int nRegions = mcr.getNumAreas();
- for (int i = 0; i < nRegions; i++) {
- CellRangeAddress cra = mcr.getAreaAt(i);
- _mergedRegions.add(cra);
- }
- }
-
- public CellRangeAddress get(int index) {
- checkIndex(index);
- return _mergedRegions.get(index);
- }
-
- public void remove(int index) {
- checkIndex(index);
- _mergedRegions.remove(index);
- }
-
- private void checkIndex(int index) {
- if (index < 0 || index >= _mergedRegions.size()) {
- throw new IllegalArgumentException("Specified CF index " + index
- + " is outside the allowable range (0.." + (_mergedRegions.size() - 1) + ")");
- }
- }
-
- public void addArea(int rowFrom, int colFrom, int rowTo, int colTo) {
- _mergedRegions.add(new CellRangeAddress(rowFrom, rowTo, colFrom, colTo));
- }
-
- public int getNumberOfMergedRegions() {
- return _mergedRegions.size();
- }
+ int nRegions = _mergedRegions.size();
+ if (nRegions < 1) {
+ // no need to write a single empty MergeCellsRecord
+ return;
+ }
+
+ int nFullMergedCellsRecords = nRegions / MAX_MERGED_REGIONS;
+ int nLeftoverMergedRegions = nRegions % MAX_MERGED_REGIONS;
+ CellRangeAddress[] cras = new CellRangeAddress[nRegions];
+ _mergedRegions.toArray(cras);
+
+ for (int i = 0; i < nFullMergedCellsRecords; i++) {
+ int startIx = i * MAX_MERGED_REGIONS;
+ rv.visitRecord(new MergeCellsRecord(cras, startIx, MAX_MERGED_REGIONS));
+ }
+ if (nLeftoverMergedRegions > 0) {
+ int startIx = nFullMergedCellsRecords * MAX_MERGED_REGIONS;
+ rv.visitRecord(new MergeCellsRecord(cras, startIx, nLeftoverMergedRegions));
+ }
+ }
+ public void addRecords(MergeCellsRecord[] mcrs) {
+ for (MergeCellsRecord mcr : mcrs) {
+ addMergeCellsRecord(mcr);
+ }
+ }
+
+ private void addMergeCellsRecord(MergeCellsRecord mcr) {
+ int nRegions = mcr.getNumAreas();
+ for (int i = 0; i < nRegions; i++) {
+ CellRangeAddress cra = mcr.getAreaAt(i);
+ _mergedRegions.add(cra);
+ }
+ }
+
+ public CellRangeAddress get(int index) {
+ checkIndex(index);
+ return _mergedRegions.get(index);
+ }
+
+ public void remove(int index) {
+ checkIndex(index);
+ _mergedRegions.remove(index);
+ }
+
+ private void checkIndex(int index) {
+ if (index < 0 || index >= _mergedRegions.size()) {
+ throw new IllegalArgumentException("Specified CF index " + index
+ + " is outside the allowable range (0.." + (_mergedRegions.size() - 1) + ")");
+ }
+ }
+
+ public void addArea(int rowFrom, int colFrom, int rowTo, int colTo) {
+ _mergedRegions.add(new CellRangeAddress(rowFrom, rowTo, colFrom, colTo));
+ }
+
+ public int getNumberOfMergedRegions() {
+ return _mergedRegions.size();
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java Sat May 22 20:56:44 2021
@@ -6,7 +6,7 @@
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java Sat May 22 20:56:44 2021
@@ -27,94 +27,94 @@ import org.apache.poi.hssf.record.Record
*/
public abstract class RecordAggregate extends RecordBase {
- /**
- * Visit each of the atomic BIFF records contained in this RecordAggregate in the order
- * that they should be written to file. Implementors may or may not return the actual
- * {@link Record}s being used to manage POI's internal implementation. Callers should not
- * assume either way, and therefore only attempt to modify those {@link Record}s after cloning
- *
- * @param rv The visitor to use for callbacks while walking this object
- */
- public abstract void visitContainedRecords(RecordVisitor rv);
-
- @Override
- public final int serialize(int offset, byte[] data) {
- SerializingRecordVisitor srv = new SerializingRecordVisitor(data, offset);
- visitContainedRecords(srv);
- return srv.countBytesWritten();
- }
- @Override
- public int getRecordSize() {
- RecordSizingVisitor rsv = new RecordSizingVisitor();
- visitContainedRecords(rsv);
- return rsv.getTotalSize();
- }
-
- public interface RecordVisitor {
- /**
- * Implementors may call non-mutating methods on Record r.
- * @param r must not be {@code null}
- */
- void visitRecord(org.apache.poi.hssf.record.Record r);
- }
-
- private static final class SerializingRecordVisitor implements RecordVisitor {
-
- private final byte[] _data;
- private final int _startOffset;
- private int _countBytesWritten;
-
- public SerializingRecordVisitor(byte[] data, int startOffset) {
- _data = data;
- _startOffset = startOffset;
- _countBytesWritten = 0;
- }
- public int countBytesWritten() {
- return _countBytesWritten;
- }
- @Override
- public void visitRecord(org.apache.poi.hssf.record.Record r) {
- int currentOffset = _startOffset + _countBytesWritten;
- _countBytesWritten += r.serialize(currentOffset, _data);
- }
- }
- private static final class RecordSizingVisitor implements RecordVisitor {
-
- private int _totalSize;
-
- public RecordSizingVisitor() {
- _totalSize = 0;
- }
- public int getTotalSize() {
- return _totalSize;
- }
- @Override
- public void visitRecord(org.apache.poi.hssf.record.Record r) {
- _totalSize += r.getRecordSize();
- }
- }
- /**
- * A wrapper for {@link RecordVisitor} which accumulates the sizes of all
- * records visited.
- */
- public static final class PositionTrackingVisitor implements RecordVisitor {
- private final RecordVisitor _rv;
- private int _position;
-
- public PositionTrackingVisitor(RecordVisitor rv, int initialPosition) {
- _rv = rv;
- _position = initialPosition;
- }
- @Override
- public void visitRecord(org.apache.poi.hssf.record.Record r) {
- _position += r.getRecordSize();
- _rv.visitRecord(r);
- }
- public void setPosition(int position) {
- _position = position;
- }
- public int getPosition() {
- return _position;
- }
- }
+ /**
+ * Visit each of the atomic BIFF records contained in this RecordAggregate in the order
+ * that they should be written to file. Implementors may or may not return the actual
+ * {@link Record}s being used to manage POI's internal implementation. Callers should not
+ * assume either way, and therefore only attempt to modify those {@link Record}s after cloning
+ *
+ * @param rv The visitor to use for callbacks while walking this object
+ */
+ public abstract void visitContainedRecords(RecordVisitor rv);
+
+ @Override
+ public final int serialize(int offset, byte[] data) {
+ SerializingRecordVisitor srv = new SerializingRecordVisitor(data, offset);
+ visitContainedRecords(srv);
+ return srv.countBytesWritten();
+ }
+ @Override
+ public int getRecordSize() {
+ RecordSizingVisitor rsv = new RecordSizingVisitor();
+ visitContainedRecords(rsv);
+ return rsv.getTotalSize();
+ }
+
+ public interface RecordVisitor {
+ /**
+ * Implementors may call non-mutating methods on Record r.
+ * @param r must not be {@code null}
+ */
+ void visitRecord(org.apache.poi.hssf.record.Record r);
+ }
+
+ private static final class SerializingRecordVisitor implements RecordVisitor {
+
+ private final byte[] _data;
+ private final int _startOffset;
+ private int _countBytesWritten;
+
+ public SerializingRecordVisitor(byte[] data, int startOffset) {
+ _data = data;
+ _startOffset = startOffset;
+ _countBytesWritten = 0;
+ }
+ public int countBytesWritten() {
+ return _countBytesWritten;
+ }
+ @Override
+ public void visitRecord(org.apache.poi.hssf.record.Record r) {
+ int currentOffset = _startOffset + _countBytesWritten;
+ _countBytesWritten += r.serialize(currentOffset, _data);
+ }
+ }
+ private static final class RecordSizingVisitor implements RecordVisitor {
+
+ private int _totalSize;
+
+ public RecordSizingVisitor() {
+ _totalSize = 0;
+ }
+ public int getTotalSize() {
+ return _totalSize;
+ }
+ @Override
+ public void visitRecord(org.apache.poi.hssf.record.Record r) {
+ _totalSize += r.getRecordSize();
+ }
+ }
+ /**
+ * A wrapper for {@link RecordVisitor} which accumulates the sizes of all
+ * records visited.
+ */
+ public static final class PositionTrackingVisitor implements RecordVisitor {
+ private final RecordVisitor _rv;
+ private int _position;
+
+ public PositionTrackingVisitor(RecordVisitor rv, int initialPosition) {
+ _rv = rv;
+ _position = initialPosition;
+ }
+ @Override
+ public void visitRecord(org.apache.poi.hssf.record.Record r) {
+ _position += r.getRecordSize();
+ _rv.visitRecord(r);
+ }
+ public void setPosition(int position) {
+ _position = position;
+ }
+ public int getPosition() {
+ return _position;
+ }
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java Sat May 22 20:56:44 2021
@@ -43,121 +43,121 @@ import org.apache.poi.ss.util.CellRefere
*/
public final class SharedValueManager {
- private static final class SharedFormulaGroup {
- private final SharedFormulaRecord _sfr;
- private final FormulaRecordAggregate[] _frAggs;
- private int _numberOfFormulas;
- /**
- * Coordinates of the first cell having a formula that uses this shared formula.
- * This is often <i>but not always</i> the top left cell in the range covered by
- * {@link #_sfr}
- */
- private final CellReference _firstCell;
-
- public SharedFormulaGroup(SharedFormulaRecord sfr, CellReference firstCell) {
- if (!sfr.isInRange(firstCell.getRow(), firstCell.getCol())) {
- throw new IllegalArgumentException("First formula cell " + firstCell.formatAsString()
- + " is not shared formula range " + sfr.getRange() + ".");
- }
- _sfr = sfr;
- _firstCell = firstCell;
- int width = sfr.getLastColumn() - sfr.getFirstColumn() + 1;
- int height = sfr.getLastRow() - sfr.getFirstRow() + 1;
- _frAggs = new FormulaRecordAggregate[width * height];
- _numberOfFormulas = 0;
- }
-
- public void add(FormulaRecordAggregate agg) {
- if (_numberOfFormulas == 0) {
- if (_firstCell.getRow() != agg.getRow() || _firstCell.getCol() != agg.getColumn()) {
- throw new IllegalStateException("shared formula coding error: "+_firstCell.getCol()+'/'+_firstCell.getRow()+" != "+agg.getColumn()+'/'+agg.getRow());
- }
- }
- if (_numberOfFormulas >= _frAggs.length) {
- throw new RuntimeException("Too many formula records for shared formula group");
- }
- _frAggs[_numberOfFormulas++] = agg;
- }
-
- public void unlinkSharedFormulas() {
- for (int i = 0; i < _numberOfFormulas; i++) {
- _frAggs[i].unlinkSharedFormula();
- }
- }
-
- public SharedFormulaRecord getSFR() {
- return _sfr;
- }
-
- public final String toString() {
- return getClass().getName() + " [" +
- _sfr.getRange() +
- "]";
- }
- }
-
- /**
- * @return a new empty SharedValueManager.
- */
- public static SharedValueManager createEmpty() {
- // Note - must create distinct instances because they are assumed to be mutable.
- return new SharedValueManager(
- new SharedFormulaRecord[0], new CellReference[0], new ArrayRecord[0], new TableRecord[0]);
- }
- private final List<ArrayRecord> _arrayRecords;
- private final TableRecord[] _tableRecords;
- private final Map<SharedFormulaRecord, SharedFormulaGroup> _groupsBySharedFormulaRecord;
- /** cached for optimization purposes */
+ private static final class SharedFormulaGroup {
+ private final SharedFormulaRecord _sfr;
+ private final FormulaRecordAggregate[] _frAggs;
+ private int _numberOfFormulas;
+ /**
+ * Coordinates of the first cell having a formula that uses this shared formula.
+ * This is often <i>but not always</i> the top left cell in the range covered by
+ * {@link #_sfr}
+ */
+ private final CellReference _firstCell;
+
+ public SharedFormulaGroup(SharedFormulaRecord sfr, CellReference firstCell) {
+ if (!sfr.isInRange(firstCell.getRow(), firstCell.getCol())) {
+ throw new IllegalArgumentException("First formula cell " + firstCell.formatAsString()
+ + " is not shared formula range " + sfr.getRange() + ".");
+ }
+ _sfr = sfr;
+ _firstCell = firstCell;
+ int width = sfr.getLastColumn() - sfr.getFirstColumn() + 1;
+ int height = sfr.getLastRow() - sfr.getFirstRow() + 1;
+ _frAggs = new FormulaRecordAggregate[width * height];
+ _numberOfFormulas = 0;
+ }
+
+ public void add(FormulaRecordAggregate agg) {
+ if (_numberOfFormulas == 0) {
+ if (_firstCell.getRow() != agg.getRow() || _firstCell.getCol() != agg.getColumn()) {
+ throw new IllegalStateException("shared formula coding error: "+_firstCell.getCol()+'/'+_firstCell.getRow()+" != "+agg.getColumn()+'/'+agg.getRow());
+ }
+ }
+ if (_numberOfFormulas >= _frAggs.length) {
+ throw new RuntimeException("Too many formula records for shared formula group");
+ }
+ _frAggs[_numberOfFormulas++] = agg;
+ }
+
+ public void unlinkSharedFormulas() {
+ for (int i = 0; i < _numberOfFormulas; i++) {
+ _frAggs[i].unlinkSharedFormula();
+ }
+ }
+
+ public SharedFormulaRecord getSFR() {
+ return _sfr;
+ }
+
+ public final String toString() {
+ return getClass().getName() + " [" +
+ _sfr.getRange() +
+ "]";
+ }
+ }
+
+ /**
+ * @return a new empty SharedValueManager.
+ */
+ public static SharedValueManager createEmpty() {
+ // Note - must create distinct instances because they are assumed to be mutable.
+ return new SharedValueManager(
+ new SharedFormulaRecord[0], new CellReference[0], new ArrayRecord[0], new TableRecord[0]);
+ }
+ private final List<ArrayRecord> _arrayRecords;
+ private final TableRecord[] _tableRecords;
+ private final Map<SharedFormulaRecord, SharedFormulaGroup> _groupsBySharedFormulaRecord;
+ /** cached for optimization purposes */
private Map<Integer,SharedFormulaGroup> _groupsCache;
- private SharedValueManager(SharedFormulaRecord[] sharedFormulaRecords,
- CellReference[] firstCells, ArrayRecord[] arrayRecords, TableRecord[] tableRecords) {
- int nShF = sharedFormulaRecords.length;
- if (nShF != firstCells.length) {
- throw new IllegalArgumentException("array sizes don't match: " + nShF + "!=" + firstCells.length + ".");
- }
- _arrayRecords = toList(arrayRecords);
- _tableRecords = tableRecords;
- Map<SharedFormulaRecord, SharedFormulaGroup> m = new HashMap<>(nShF * 3 / 2);
- for (int i = 0; i < nShF; i++) {
- SharedFormulaRecord sfr = sharedFormulaRecords[i];
- m.put(sfr, new SharedFormulaGroup(sfr, firstCells[i]));
- }
- _groupsBySharedFormulaRecord = m;
- }
-
- /**
- * @return a modifiable list, independent of the supplied array
- */
- private static <Z> List<Z> toList(Z[] zz) {
- List<Z> result = new ArrayList<>(zz.length);
- Collections.addAll(result, zz);
- return result;
- }
-
- /**
- */
- public static SharedValueManager create(SharedFormulaRecord[] sharedFormulaRecords,
- CellReference[] firstCells, ArrayRecord[] arrayRecords, TableRecord[] tableRecords) {
- if (sharedFormulaRecords.length + firstCells.length + arrayRecords.length + tableRecords.length < 1) {
- return createEmpty();
- }
- return new SharedValueManager(sharedFormulaRecords, firstCells, arrayRecords, tableRecords);
- }
-
-
- /**
- * @param firstCell as extracted from the {@link ExpPtg} from the cell's formula.
- * @return never {@code null}
- */
- public SharedFormulaRecord linkSharedFormulaRecord(CellReference firstCell, FormulaRecordAggregate agg) {
- SharedFormulaGroup result = findFormulaGroupForCell(firstCell);
+ private SharedValueManager(SharedFormulaRecord[] sharedFormulaRecords,
+ CellReference[] firstCells, ArrayRecord[] arrayRecords, TableRecord[] tableRecords) {
+ int nShF = sharedFormulaRecords.length;
+ if (nShF != firstCells.length) {
+ throw new IllegalArgumentException("array sizes don't match: " + nShF + "!=" + firstCells.length + ".");
+ }
+ _arrayRecords = toList(arrayRecords);
+ _tableRecords = tableRecords;
+ Map<SharedFormulaRecord, SharedFormulaGroup> m = new HashMap<>(nShF * 3 / 2);
+ for (int i = 0; i < nShF; i++) {
+ SharedFormulaRecord sfr = sharedFormulaRecords[i];
+ m.put(sfr, new SharedFormulaGroup(sfr, firstCells[i]));
+ }
+ _groupsBySharedFormulaRecord = m;
+ }
+
+ /**
+ * @return a modifiable list, independent of the supplied array
+ */
+ private static <Z> List<Z> toList(Z[] zz) {
+ List<Z> result = new ArrayList<>(zz.length);
+ Collections.addAll(result, zz);
+ return result;
+ }
+
+ /**
+ */
+ public static SharedValueManager create(SharedFormulaRecord[] sharedFormulaRecords,
+ CellReference[] firstCells, ArrayRecord[] arrayRecords, TableRecord[] tableRecords) {
+ if (sharedFormulaRecords.length + firstCells.length + arrayRecords.length + tableRecords.length < 1) {
+ return createEmpty();
+ }
+ return new SharedValueManager(sharedFormulaRecords, firstCells, arrayRecords, tableRecords);
+ }
+
+
+ /**
+ * @param firstCell as extracted from the {@link ExpPtg} from the cell's formula.
+ * @return never {@code null}
+ */
+ public SharedFormulaRecord linkSharedFormulaRecord(CellReference firstCell, FormulaRecordAggregate agg) {
+ SharedFormulaGroup result = findFormulaGroupForCell(firstCell);
if(null == result) {
throw new RuntimeException("Failed to find a matching shared formula record");
}
- result.add(agg);
- return result.getSFR();
- }
+ result.add(agg);
+ return result.getSFR();
+ }
private SharedFormulaGroup findFormulaGroupForCell(final CellReference cellRef) {
if(null == _groupsCache) {
@@ -174,34 +174,34 @@ public final class SharedValueManager {
return ((cellRef.getCol()+1)<<16 | cellRef.getRow());
}
- /**
- * Gets the {@link SharedValueRecordBase} record if it should be encoded immediately after the
- * formula record contained in the specified {@link FormulaRecordAggregate} agg. Note - the
- * shared value record always appears after the first formula record in the group. For arrays
- * and tables the first formula is always the in the top left cell. However, since shared
- * formula groups can be sparse and/or overlap, the first formula may not actually be in the
- * top left cell.
- *
- * @return the SHRFMLA, TABLE or ARRAY record for the formula cell, if it is the first cell of
- * a table or array region. {@code null} if the formula cell is not shared/array/table,
- * or if the specified formula is not the the first in the group.
- */
- public SharedValueRecordBase getRecordForFirstCell(FormulaRecordAggregate agg) {
- CellReference firstCell = agg.getFormulaRecord().getFormula().getExpReference();
- // perhaps this could be optimised by consulting the (somewhat unreliable) isShared flag
- // and/or distinguishing between tExp and tTbl.
- if (firstCell == null) {
- // not a shared/array/table formula
- return null;
- }
-
-
- int row = firstCell.getRow();
- int column = firstCell.getCol();
- if (agg.getRow() != row || agg.getColumn() != column) {
- // not the first formula cell in the group
- return null;
- }
+ /**
+ * Gets the {@link SharedValueRecordBase} record if it should be encoded immediately after the
+ * formula record contained in the specified {@link FormulaRecordAggregate} agg. Note - the
+ * shared value record always appears after the first formula record in the group. For arrays
+ * and tables the first formula is always the in the top left cell. However, since shared
+ * formula groups can be sparse and/or overlap, the first formula may not actually be in the
+ * top left cell.
+ *
+ * @return the SHRFMLA, TABLE or ARRAY record for the formula cell, if it is the first cell of
+ * a table or array region. {@code null} if the formula cell is not shared/array/table,
+ * or if the specified formula is not the the first in the group.
+ */
+ public SharedValueRecordBase getRecordForFirstCell(FormulaRecordAggregate agg) {
+ CellReference firstCell = agg.getFormulaRecord().getFormula().getExpReference();
+ // perhaps this could be optimised by consulting the (somewhat unreliable) isShared flag
+ // and/or distinguishing between tExp and tTbl.
+ if (firstCell == null) {
+ // not a shared/array/table formula
+ return null;
+ }
+
+
+ int row = firstCell.getRow();
+ int column = firstCell.getCol();
+ if (agg.getRow() != row || agg.getColumn() != column) {
+ // not the first formula cell in the group
+ return null;
+ }
if(!_groupsBySharedFormulaRecord.isEmpty()) {
SharedFormulaGroup sfg = findFormulaGroupForCell(firstCell);
@@ -210,70 +210,70 @@ public final class SharedValueManager {
}
}
- // Since arrays and tables cannot be sparse (all cells in range participate)
- // The first cell will be the top left in the range. So we can match the
- // ARRAY/TABLE record directly.
-
- for (TableRecord tr : _tableRecords) {
- if (tr.isFirstCell(row, column)) {
- return tr;
- }
- }
- for (ArrayRecord ar : _arrayRecords) {
- if (ar.isFirstCell(row, column)) {
- return ar;
- }
- }
- return null;
- }
-
- /**
- * Converts all {@link FormulaRecord}s handled by {@code sharedFormulaRecord}
- * to plain unshared formulas
- */
- public void unlink(SharedFormulaRecord sharedFormulaRecord) {
- SharedFormulaGroup svg = _groupsBySharedFormulaRecord.remove(sharedFormulaRecord);
- if (svg == null) {
- throw new IllegalStateException("Failed to find formulas for shared formula");
- }
- _groupsCache = null; // be sure to reset cached value
- svg.unlinkSharedFormulas();
- }
-
- /**
- * Add specified Array Record.
- */
- public void addArrayRecord(ArrayRecord ar) {
- // could do a check here to make sure none of the ranges overlap
- _arrayRecords.add(ar);
- }
-
- /**
- * Removes the {@link ArrayRecord} for the cell group containing the specified cell.
- * The caller should clear (set blank) all cells in the returned range.
- * @return the range of the array formula which was just removed. Never {@code null}.
- */
- public CellRangeAddress8Bit removeArrayFormula(int rowIndex, int columnIndex) {
- for (ArrayRecord ar : _arrayRecords) {
- if (ar.isInRange(rowIndex, columnIndex)) {
- _arrayRecords.remove(ar);
- return ar.getRange();
- }
- }
- String ref = new CellReference(rowIndex, columnIndex, false, false).formatAsString();
- throw new IllegalArgumentException("Specified cell " + ref
- + " is not part of an array formula.");
- }
-
- /**
- * @return the shared ArrayRecord identified by (firstRow, firstColumn). never {@code null}.
- */
- public ArrayRecord getArrayRecord(int firstRow, int firstColumn) {
- for(ArrayRecord ar : _arrayRecords) {
- if(ar.isFirstCell(firstRow, firstColumn)) {
- return ar;
- }
- }
- return null;
- }
+ // Since arrays and tables cannot be sparse (all cells in range participate)
+ // The first cell will be the top left in the range. So we can match the
+ // ARRAY/TABLE record directly.
+
+ for (TableRecord tr : _tableRecords) {
+ if (tr.isFirstCell(row, column)) {
+ return tr;
+ }
+ }
+ for (ArrayRecord ar : _arrayRecords) {
+ if (ar.isFirstCell(row, column)) {
+ return ar;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Converts all {@link FormulaRecord}s handled by {@code sharedFormulaRecord}
+ * to plain unshared formulas
+ */
+ public void unlink(SharedFormulaRecord sharedFormulaRecord) {
+ SharedFormulaGroup svg = _groupsBySharedFormulaRecord.remove(sharedFormulaRecord);
+ if (svg == null) {
+ throw new IllegalStateException("Failed to find formulas for shared formula");
+ }
+ _groupsCache = null; // be sure to reset cached value
+ svg.unlinkSharedFormulas();
+ }
+
+ /**
+ * Add specified Array Record.
+ */
+ public void addArrayRecord(ArrayRecord ar) {
+ // could do a check here to make sure none of the ranges overlap
+ _arrayRecords.add(ar);
+ }
+
+ /**
+ * Removes the {@link ArrayRecord} for the cell group containing the specified cell.
+ * The caller should clear (set blank) all cells in the returned range.
+ * @return the range of the array formula which was just removed. Never {@code null}.
+ */
+ public CellRangeAddress8Bit removeArrayFormula(int rowIndex, int columnIndex) {
+ for (ArrayRecord ar : _arrayRecords) {
+ if (ar.isInRange(rowIndex, columnIndex)) {
+ _arrayRecords.remove(ar);
+ return ar.getRange();
+ }
+ }
+ String ref = new CellReference(rowIndex, columnIndex, false, false).formatAsString();
+ throw new IllegalArgumentException("Specified cell " + ref
+ + " is not part of an array formula.");
+ }
+
+ /**
+ * @return the shared ArrayRecord identified by (firstRow, firstColumn). never {@code null}.
+ */
+ public ArrayRecord getArrayRecord(int firstRow, int firstColumn) {
+ for(ArrayRecord ar : _arrayRecords) {
+ if(ar.isFirstCell(firstRow, firstColumn)) {
+ return ar;
+ }
+ }
+ return null;
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java Sat May 22 20:56:44 2021
@@ -39,256 +39,256 @@ import org.apache.poi.util.Removal;
* Aggregate value records together. Things are easier to handle that way.
*/
public final class ValueRecordsAggregate implements Iterable<CellValueRecordInterface> {
- private static final int MAX_ROW_INDEX = 0XFFFF;
- private static final int INDEX_NOT_SET = -1;
- private int firstcell = INDEX_NOT_SET;
- private int lastcell = INDEX_NOT_SET;
- private CellValueRecordInterface[][] records;
-
- /** Creates a new instance of ValueRecordsAggregate */
-
- public ValueRecordsAggregate() {
- this(INDEX_NOT_SET, INDEX_NOT_SET, new CellValueRecordInterface[30][]); // We start with 30 Rows.
- }
- private ValueRecordsAggregate(int firstCellIx, int lastCellIx, CellValueRecordInterface[][] pRecords) {
- firstcell = firstCellIx;
- lastcell = lastCellIx;
- records = pRecords;
- }
-
- public void insertCell(CellValueRecordInterface cell) {
- short column = cell.getColumn();
- int row = cell.getRow();
- if (row >= records.length) {
- CellValueRecordInterface[][] oldRecords = records;
- int newSize = oldRecords.length * 2;
- if (newSize < row + 1)
- newSize = row + 1;
- records = new CellValueRecordInterface[newSize][];
- System.arraycopy(oldRecords, 0, records, 0, oldRecords.length);
- }
- CellValueRecordInterface[] rowCells = records[row];
- if (rowCells == null) {
- int newSize = column + 1;
- if (newSize < 10)
- newSize = 10;
- rowCells = new CellValueRecordInterface[newSize];
- records[row] = rowCells;
- }
- if (column >= rowCells.length) {
- CellValueRecordInterface[] oldRowCells = rowCells;
- int newSize = oldRowCells.length * 2;
- if (newSize < column + 1)
- newSize = column + 1;
- // if(newSize>257) newSize=257; // activate?
- rowCells = new CellValueRecordInterface[newSize];
- System.arraycopy(oldRowCells, 0, rowCells, 0, oldRowCells.length);
- records[row] = rowCells;
- }
- rowCells[column] = cell;
-
- if (column < firstcell || firstcell == INDEX_NOT_SET) {
- firstcell = column;
- }
- if (column > lastcell || lastcell == INDEX_NOT_SET) {
- lastcell = column;
- }
- }
-
- public void removeCell(CellValueRecordInterface cell) {
- if (cell == null) {
- throw new IllegalArgumentException("cell must not be null");
- }
- int row = cell.getRow();
- if (row >= records.length) {
- throw new RuntimeException("cell row is out of range");
- }
- CellValueRecordInterface[] rowCells = records[row];
- if (rowCells == null) {
- throw new RuntimeException("cell row is already empty");
- }
- short column = cell.getColumn();
- if (column >= rowCells.length) {
- throw new RuntimeException("cell column is out of range");
- }
- rowCells[column] = null;
- }
-
- public void removeAllCellsValuesForRow(int rowIndex) {
- if (rowIndex < 0 || rowIndex > MAX_ROW_INDEX) {
- throw new IllegalArgumentException("Specified rowIndex " + rowIndex
- + " is outside the allowable range (0.." +MAX_ROW_INDEX + ")");
- }
- if (rowIndex >= records.length) {
- // this can happen when the client code has created a row,
- // and then removes/replaces it before adding any cells. (see bug 46312)
- return;
- }
-
- records[rowIndex] = null;
- }
-
-
- public int getPhysicalNumberOfCells() {
- int count = 0;
- for (int r = 0; r < records.length; r++) {
- CellValueRecordInterface[] rowCells = records[r];
- if (rowCells != null) {
- for (int c = 0; c < rowCells.length; c++) {
- if (rowCells[c] != null)
- count++;
- }
- }
- }
- return count;
- }
-
- public int getFirstCellNum() {
- return firstcell;
- }
-
- public int getLastCellNum() {
- return lastcell;
- }
-
- public void addMultipleBlanks(MulBlankRecord mbr) {
- for (int j = 0; j < mbr.getNumColumns(); j++) {
- BlankRecord br = new BlankRecord();
-
- br.setColumn(( short ) (j + mbr.getFirstColumn()));
- br.setRow(mbr.getRow());
- br.setXFIndex(mbr.getXFAt(j));
- insertCell(br);
- }
- }
-
- /**
- * Processes a single cell value record
- * @param sfh used to resolve any shared-formulas/arrays/tables for the current sheet
- */
- public void construct(CellValueRecordInterface rec, RecordStream rs, SharedValueManager sfh) {
- if (rec instanceof FormulaRecord) {
- FormulaRecord formulaRec = (FormulaRecord)rec;
- // read optional cached text value
- StringRecord cachedText;
- Class<? extends Record> nextClass = rs.peekNextClass();
- if (nextClass == StringRecord.class) {
- cachedText = (StringRecord) rs.getNext();
- } else {
- cachedText = null;
- }
- insertCell(new FormulaRecordAggregate(formulaRec, cachedText, sfh));
- } else {
- insertCell(rec);
- }
- }
-
- /** Tallies a count of the size of the cell records
- * that are attached to the rows in the range specified.
- */
- public int getRowCellBlockSize(int startRow, int endRow) {
- int result = 0;
- for(int rowIx=startRow; rowIx<=endRow && rowIx<records.length; rowIx++) {
- result += getRowSerializedSize(records[rowIx]);
- }
- return result;
- }
-
- /** Returns true if the row has cells attached to it */
- public boolean rowHasCells(int row) {
- if (row >= records.length) {
- return false;
- }
- CellValueRecordInterface[] rowCells=records[row];
- if(rowCells==null) return false;
- for(int col=0;col<rowCells.length;col++) {
- if(rowCells[col]!=null) return true;
- }
- return false;
- }
-
- private static int getRowSerializedSize(CellValueRecordInterface[] rowCells) {
- if(rowCells == null) {
- return 0;
- }
- int result = 0;
- for (int i = 0; i < rowCells.length; i++) {
- RecordBase cvr = (RecordBase) rowCells[i];
- if(cvr == null) {
- continue;
- }
- int nBlank = countBlanks(rowCells, i);
- if (nBlank > 1) {
- result += (10 + 2*nBlank);
- i+=nBlank-1;
- } else {
- result += cvr.getRecordSize();
- }
- }
- return result;
- }
-
- public void visitCellsForRow(int rowIndex, RecordVisitor rv) {
-
- CellValueRecordInterface[] rowCells = records[rowIndex];
- if(rowCells == null) {
- throw new IllegalArgumentException("Row [" + rowIndex + "] is empty");
- }
-
-
- for (int i = 0; i < rowCells.length; i++) {
- RecordBase cvr = (RecordBase) rowCells[i];
- if(cvr == null) {
- continue;
- }
- int nBlank = countBlanks(rowCells, i);
- if (nBlank > 1) {
- rv.visitRecord(createMBR(rowCells, i, nBlank));
- i+=nBlank-1;
- } else if (cvr instanceof RecordAggregate) {
- RecordAggregate agg = (RecordAggregate) cvr;
- agg.visitContainedRecords(rv);
- } else {
- rv.visitRecord((org.apache.poi.hssf.record.Record) cvr);
- }
- }
- }
-
- /**
- * @return the number of <em>consecutive</em> {@link BlankRecord}s in the specified row
- * starting from startIx.
- */
- private static int countBlanks(CellValueRecordInterface[] rowCellValues, int startIx) {
- int i = startIx;
- while(i < rowCellValues.length) {
- CellValueRecordInterface cvr = rowCellValues[i];
- if (!(cvr instanceof BlankRecord)) {
- break;
- }
- i++;
- }
- return i - startIx;
- }
-
- private MulBlankRecord createMBR(CellValueRecordInterface[] cellValues, int startIx, int nBlank) {
-
- short[] xfs = new short[nBlank];
- for (int i = 0; i < xfs.length; i++) {
- xfs[i] = cellValues[startIx + i].getXFIndex();
- }
- int rowIx = cellValues[startIx].getRow();
- return new MulBlankRecord(rowIx, startIx, xfs);
- }
-
- public void updateFormulasAfterRowShift(FormulaShifter shifter, int currentExternSheetIndex) {
- for (int i = 0; i < records.length; i++) {
- CellValueRecordInterface[] rowCells = records[i];
- if (rowCells == null) {
- continue;
- }
- for (int j = 0; j < rowCells.length; j++) {
- CellValueRecordInterface cell = rowCells[j];
- if (cell instanceof FormulaRecordAggregate) {
+ private static final int MAX_ROW_INDEX = 0XFFFF;
+ private static final int INDEX_NOT_SET = -1;
+ private int firstcell = INDEX_NOT_SET;
+ private int lastcell = INDEX_NOT_SET;
+ private CellValueRecordInterface[][] records;
+
+ /** Creates a new instance of ValueRecordsAggregate */
+
+ public ValueRecordsAggregate() {
+ this(INDEX_NOT_SET, INDEX_NOT_SET, new CellValueRecordInterface[30][]); // We start with 30 Rows.
+ }
+ private ValueRecordsAggregate(int firstCellIx, int lastCellIx, CellValueRecordInterface[][] pRecords) {
+ firstcell = firstCellIx;
+ lastcell = lastCellIx;
+ records = pRecords;
+ }
+
+ public void insertCell(CellValueRecordInterface cell) {
+ short column = cell.getColumn();
+ int row = cell.getRow();
+ if (row >= records.length) {
+ CellValueRecordInterface[][] oldRecords = records;
+ int newSize = oldRecords.length * 2;
+ if (newSize < row + 1)
+ newSize = row + 1;
+ records = new CellValueRecordInterface[newSize][];
+ System.arraycopy(oldRecords, 0, records, 0, oldRecords.length);
+ }
+ CellValueRecordInterface[] rowCells = records[row];
+ if (rowCells == null) {
+ int newSize = column + 1;
+ if (newSize < 10)
+ newSize = 10;
+ rowCells = new CellValueRecordInterface[newSize];
+ records[row] = rowCells;
+ }
+ if (column >= rowCells.length) {
+ CellValueRecordInterface[] oldRowCells = rowCells;
+ int newSize = oldRowCells.length * 2;
+ if (newSize < column + 1)
+ newSize = column + 1;
+ // if(newSize>257) newSize=257; // activate?
+ rowCells = new CellValueRecordInterface[newSize];
+ System.arraycopy(oldRowCells, 0, rowCells, 0, oldRowCells.length);
+ records[row] = rowCells;
+ }
+ rowCells[column] = cell;
+
+ if (column < firstcell || firstcell == INDEX_NOT_SET) {
+ firstcell = column;
+ }
+ if (column > lastcell || lastcell == INDEX_NOT_SET) {
+ lastcell = column;
+ }
+ }
+
+ public void removeCell(CellValueRecordInterface cell) {
+ if (cell == null) {
+ throw new IllegalArgumentException("cell must not be null");
+ }
+ int row = cell.getRow();
+ if (row >= records.length) {
+ throw new RuntimeException("cell row is out of range");
+ }
+ CellValueRecordInterface[] rowCells = records[row];
+ if (rowCells == null) {
+ throw new RuntimeException("cell row is already empty");
+ }
+ short column = cell.getColumn();
+ if (column >= rowCells.length) {
+ throw new RuntimeException("cell column is out of range");
+ }
+ rowCells[column] = null;
+ }
+
+ public void removeAllCellsValuesForRow(int rowIndex) {
+ if (rowIndex < 0 || rowIndex > MAX_ROW_INDEX) {
+ throw new IllegalArgumentException("Specified rowIndex " + rowIndex
+ + " is outside the allowable range (0.." +MAX_ROW_INDEX + ")");
+ }
+ if (rowIndex >= records.length) {
+ // this can happen when the client code has created a row,
+ // and then removes/replaces it before adding any cells. (see bug 46312)
+ return;
+ }
+
+ records[rowIndex] = null;
+ }
+
+
+ public int getPhysicalNumberOfCells() {
+ int count = 0;
+ for (int r = 0; r < records.length; r++) {
+ CellValueRecordInterface[] rowCells = records[r];
+ if (rowCells != null) {
+ for (int c = 0; c < rowCells.length; c++) {
+ if (rowCells[c] != null)
+ count++;
+ }
+ }
+ }
+ return count;
+ }
+
+ public int getFirstCellNum() {
+ return firstcell;
+ }
+
+ public int getLastCellNum() {
+ return lastcell;
+ }
+
+ public void addMultipleBlanks(MulBlankRecord mbr) {
+ for (int j = 0; j < mbr.getNumColumns(); j++) {
+ BlankRecord br = new BlankRecord();
+
+ br.setColumn(( short ) (j + mbr.getFirstColumn()));
+ br.setRow(mbr.getRow());
+ br.setXFIndex(mbr.getXFAt(j));
+ insertCell(br);
+ }
+ }
+
+ /**
+ * Processes a single cell value record
+ * @param sfh used to resolve any shared-formulas/arrays/tables for the current sheet
+ */
+ public void construct(CellValueRecordInterface rec, RecordStream rs, SharedValueManager sfh) {
+ if (rec instanceof FormulaRecord) {
+ FormulaRecord formulaRec = (FormulaRecord)rec;
+ // read optional cached text value
+ StringRecord cachedText;
+ Class<? extends Record> nextClass = rs.peekNextClass();
+ if (nextClass == StringRecord.class) {
+ cachedText = (StringRecord) rs.getNext();
+ } else {
+ cachedText = null;
+ }
+ insertCell(new FormulaRecordAggregate(formulaRec, cachedText, sfh));
+ } else {
+ insertCell(rec);
+ }
+ }
+
+ /** Tallies a count of the size of the cell records
+ * that are attached to the rows in the range specified.
+ */
+ public int getRowCellBlockSize(int startRow, int endRow) {
+ int result = 0;
+ for(int rowIx=startRow; rowIx<=endRow && rowIx<records.length; rowIx++) {
+ result += getRowSerializedSize(records[rowIx]);
+ }
+ return result;
+ }
+
+ /** Returns true if the row has cells attached to it */
+ public boolean rowHasCells(int row) {
+ if (row >= records.length) {
+ return false;
+ }
+ CellValueRecordInterface[] rowCells=records[row];
+ if(rowCells==null) return false;
+ for(int col=0;col<rowCells.length;col++) {
+ if(rowCells[col]!=null) return true;
+ }
+ return false;
+ }
+
+ private static int getRowSerializedSize(CellValueRecordInterface[] rowCells) {
+ if(rowCells == null) {
+ return 0;
+ }
+ int result = 0;
+ for (int i = 0; i < rowCells.length; i++) {
+ RecordBase cvr = (RecordBase) rowCells[i];
+ if(cvr == null) {
+ continue;
+ }
+ int nBlank = countBlanks(rowCells, i);
+ if (nBlank > 1) {
+ result += (10 + 2*nBlank);
+ i+=nBlank-1;
+ } else {
+ result += cvr.getRecordSize();
+ }
+ }
+ return result;
+ }
+
+ public void visitCellsForRow(int rowIndex, RecordVisitor rv) {
+
+ CellValueRecordInterface[] rowCells = records[rowIndex];
+ if(rowCells == null) {
+ throw new IllegalArgumentException("Row [" + rowIndex + "] is empty");
+ }
+
+
+ for (int i = 0; i < rowCells.length; i++) {
+ RecordBase cvr = (RecordBase) rowCells[i];
+ if(cvr == null) {
+ continue;
+ }
+ int nBlank = countBlanks(rowCells, i);
+ if (nBlank > 1) {
+ rv.visitRecord(createMBR(rowCells, i, nBlank));
+ i+=nBlank-1;
+ } else if (cvr instanceof RecordAggregate) {
+ RecordAggregate agg = (RecordAggregate) cvr;
+ agg.visitContainedRecords(rv);
+ } else {
+ rv.visitRecord((org.apache.poi.hssf.record.Record) cvr);
+ }
+ }
+ }
+
+ /**
+ * @return the number of <em>consecutive</em> {@link BlankRecord}s in the specified row
+ * starting from startIx.
+ */
+ private static int countBlanks(CellValueRecordInterface[] rowCellValues, int startIx) {
+ int i = startIx;
+ while(i < rowCellValues.length) {
+ CellValueRecordInterface cvr = rowCellValues[i];
+ if (!(cvr instanceof BlankRecord)) {
+ break;
+ }
+ i++;
+ }
+ return i - startIx;
+ }
+
+ private MulBlankRecord createMBR(CellValueRecordInterface[] cellValues, int startIx, int nBlank) {
+
+ short[] xfs = new short[nBlank];
+ for (int i = 0; i < xfs.length; i++) {
+ xfs[i] = cellValues[startIx + i].getXFIndex();
+ }
+ int rowIx = cellValues[startIx].getRow();
+ return new MulBlankRecord(rowIx, startIx, xfs);
+ }
+
+ public void updateFormulasAfterRowShift(FormulaShifter shifter, int currentExternSheetIndex) {
+ for (int i = 0; i < records.length; i++) {
+ CellValueRecordInterface[] rowCells = records[i];
+ if (rowCells == null) {
+ continue;
+ }
+ for (int j = 0; j < rowCells.length; j++) {
+ CellValueRecordInterface cell = rowCells[j];
+ if (cell instanceof FormulaRecordAggregate) {
FormulaRecordAggregate fra = (FormulaRecordAggregate)cell;
Ptg[] ptgs = fra.getFormulaTokens(); // needs clone() inside this getter?
Ptg[] ptgs2 = ((FormulaRecordAggregate)cell).getFormulaRecord().getParsedExpression(); // needs clone() inside this getter?
@@ -297,74 +297,74 @@ public final class ValueRecordsAggregate
fra.setParsedExpression(ptgs);
}
}
- }
- }
- }
-
- /**
- * iterator for CellValueRecordInterface
- */
- class ValueIterator implements Iterator<CellValueRecordInterface> {
-
- int curRowIndex, curColIndex = -1;
- int nextRowIndex, nextColIndex = -1;
-
- public ValueIterator() {
- getNextPos();
- }
-
- void getNextPos() {
- if (nextRowIndex >= records.length)
- return; // no next already
-
- while (nextRowIndex < records.length) {
- ++nextColIndex;
- if (records[nextRowIndex] == null || nextColIndex >= records[nextRowIndex].length) {
- ++nextRowIndex;
- nextColIndex = -1;
- continue;
- }
-
- if (records[nextRowIndex][nextColIndex] != null)
- return; // next cell found
- }
- // no next found
- }
-
- public boolean hasNext() {
- return nextRowIndex < records.length;
- }
-
- public CellValueRecordInterface next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
-
- curRowIndex = nextRowIndex;
- curColIndex = nextColIndex;
- final CellValueRecordInterface ret = records[curRowIndex][curColIndex];
- getNextPos();
- return ret;
- }
-
- public void remove() {
- records[curRowIndex][curColIndex] = null;
- }
- }
-
- /** value iterator */
- public Iterator<CellValueRecordInterface> iterator() {
- return new ValueIterator();
- }
-
- /**
- * @deprecated use {@link org.apache.poi.hssf.usermodel.HSSFSheet#cloneSheet(HSSFWorkbook)} instead
- */
- @Override
- @SuppressWarnings("squid:S2975")
- @Deprecated
- @Removal(version = "5.0.0")
- public Object clone() {
- throw new RuntimeException("clone() should not be called. ValueRecordsAggregate should be copied via Sheet.cloneSheet()");
- }
+ }
+ }
+ }
+
+ /**
+ * iterator for CellValueRecordInterface
+ */
+ class ValueIterator implements Iterator<CellValueRecordInterface> {
+
+ int curRowIndex, curColIndex = -1;
+ int nextRowIndex, nextColIndex = -1;
+
+ public ValueIterator() {
+ getNextPos();
+ }
+
+ void getNextPos() {
+ if (nextRowIndex >= records.length)
+ return; // no next already
+
+ while (nextRowIndex < records.length) {
+ ++nextColIndex;
+ if (records[nextRowIndex] == null || nextColIndex >= records[nextRowIndex].length) {
+ ++nextRowIndex;
+ nextColIndex = -1;
+ continue;
+ }
+
+ if (records[nextRowIndex][nextColIndex] != null)
+ return; // next cell found
+ }
+ // no next found
+ }
+
+ public boolean hasNext() {
+ return nextRowIndex < records.length;
+ }
+
+ public CellValueRecordInterface next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ curRowIndex = nextRowIndex;
+ curColIndex = nextColIndex;
+ final CellValueRecordInterface ret = records[curRowIndex][curColIndex];
+ getNextPos();
+ return ret;
+ }
+
+ public void remove() {
+ records[curRowIndex][curColIndex] = null;
+ }
+ }
+
+ /** value iterator */
+ public Iterator<CellValueRecordInterface> iterator() {
+ return new ValueIterator();
+ }
+
+ /**
+ * @deprecated use {@link org.apache.poi.hssf.usermodel.HSSFSheet#cloneSheet(HSSFWorkbook)} instead
+ */
+ @Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
+ public Object clone() {
+ throw new RuntimeException("clone() should not be called. ValueRecordsAggregate should be copied via Sheet.cloneSheet()");
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/WorksheetProtectionBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/WorksheetProtectionBlock.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/WorksheetProtectionBlock.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/aggregates/WorksheetProtectionBlock.java Sat May 22 20:56:44 2021
@@ -33,212 +33,212 @@ import org.apache.poi.util.RecordFormatE
* (BIFF5-BIFF8)'
*/
public final class WorksheetProtectionBlock extends RecordAggregate {
- // Every one of these component records is optional
- // (The whole WorksheetProtectionBlock may not be present)
- private ProtectRecord _protectRecord;
- private ObjectProtectRecord _objectProtectRecord;
- private ScenarioProtectRecord _scenarioProtectRecord;
- private PasswordRecord _passwordRecord;
-
- /**
- * Creates an empty WorksheetProtectionBlock
- */
- public WorksheetProtectionBlock() {
- // all fields empty
- }
-
- /**
- * @return {@code true} if the specified Record sid is one belonging to
- * the 'Page Settings Block'.
- */
- public static boolean isComponentRecord(int sid) {
- switch (sid) {
- case ProtectRecord.sid:
- case ObjectProtectRecord.sid:
- case ScenarioProtectRecord.sid:
- case PasswordRecord.sid:
- return true;
- }
- return false;
- }
-
- private boolean readARecord(RecordStream rs) {
- switch (rs.peekNextSid()) {
- case ProtectRecord.sid:
- checkNotPresent(_protectRecord);
- _protectRecord = (ProtectRecord) rs.getNext();
- break;
- case ObjectProtectRecord.sid:
- checkNotPresent(_objectProtectRecord);
- _objectProtectRecord = (ObjectProtectRecord) rs.getNext();
- break;
- case ScenarioProtectRecord.sid:
- checkNotPresent(_scenarioProtectRecord);
- _scenarioProtectRecord = (ScenarioProtectRecord) rs.getNext();
- break;
- case PasswordRecord.sid:
- checkNotPresent(_passwordRecord);
- _passwordRecord = (PasswordRecord) rs.getNext();
- break;
- default:
- // all other record types are not part of the PageSettingsBlock
- return false;
- }
- return true;
- }
-
- private void checkNotPresent(org.apache.poi.hssf.record.Record rec) {
- if (rec != null) {
- throw new RecordFormatException("Duplicate PageSettingsBlock record (sid=0x"
- + Integer.toHexString(rec.getSid()) + ")");
- }
- }
+ // Every one of these component records is optional
+ // (The whole WorksheetProtectionBlock may not be present)
+ private ProtectRecord _protectRecord;
+ private ObjectProtectRecord _objectProtectRecord;
+ private ScenarioProtectRecord _scenarioProtectRecord;
+ private PasswordRecord _passwordRecord;
+
+ /**
+ * Creates an empty WorksheetProtectionBlock
+ */
+ public WorksheetProtectionBlock() {
+ // all fields empty
+ }
+
+ /**
+ * @return {@code true} if the specified Record sid is one belonging to
+ * the 'Page Settings Block'.
+ */
+ public static boolean isComponentRecord(int sid) {
+ switch (sid) {
+ case ProtectRecord.sid:
+ case ObjectProtectRecord.sid:
+ case ScenarioProtectRecord.sid:
+ case PasswordRecord.sid:
+ return true;
+ }
+ return false;
+ }
+
+ private boolean readARecord(RecordStream rs) {
+ switch (rs.peekNextSid()) {
+ case ProtectRecord.sid:
+ checkNotPresent(_protectRecord);
+ _protectRecord = (ProtectRecord) rs.getNext();
+ break;
+ case ObjectProtectRecord.sid:
+ checkNotPresent(_objectProtectRecord);
+ _objectProtectRecord = (ObjectProtectRecord) rs.getNext();
+ break;
+ case ScenarioProtectRecord.sid:
+ checkNotPresent(_scenarioProtectRecord);
+ _scenarioProtectRecord = (ScenarioProtectRecord) rs.getNext();
+ break;
+ case PasswordRecord.sid:
+ checkNotPresent(_passwordRecord);
+ _passwordRecord = (PasswordRecord) rs.getNext();
+ break;
+ default:
+ // all other record types are not part of the PageSettingsBlock
+ return false;
+ }
+ return true;
+ }
+
+ private void checkNotPresent(org.apache.poi.hssf.record.Record rec) {
+ if (rec != null) {
+ throw new RecordFormatException("Duplicate PageSettingsBlock record (sid=0x"
+ + Integer.toHexString(rec.getSid()) + ")");
+ }
+ }
- @Override
+ @Override
public void visitContainedRecords(RecordVisitor rv) {
- // Replicates record order from Excel 2007, though this is not critical
+ // Replicates record order from Excel 2007, though this is not critical
- visitIfPresent(_protectRecord, rv);
- visitIfPresent(_objectProtectRecord, rv);
- visitIfPresent(_scenarioProtectRecord, rv);
- visitIfPresent(_passwordRecord, rv);
- }
-
- private static void visitIfPresent(org.apache.poi.hssf.record.Record r, RecordVisitor rv) {
- if (r != null) {
- rv.visitRecord(r);
- }
- }
-
- public PasswordRecord getPasswordRecord() {
- return _passwordRecord;
- }
-
- public ScenarioProtectRecord getHCenter() {
- return _scenarioProtectRecord;
- }
-
- /**
- * This method reads WorksheetProtectionBlock records from the supplied RecordStream
- * until the first non-WorksheetProtectionBlock record is encountered. As each record is read,
- * it is incorporated into this WorksheetProtectionBlock.
- * <p>
- * As per the OOO documentation, the protection block records can be expected to be written
- * together (with no intervening records), but earlier versions of POI (prior to Jun 2009)
- * didn't do this. Workbooks with sheet protection created by those earlier POI versions
- * seemed to be valid (Excel opens them OK). So PO allows continues to support reading of files
- * with non continuous worksheet protection blocks.
- *
- * <p>
- * <b>Note</b> - when POI writes out this WorksheetProtectionBlock, the records will always be
- * written in one consolidated block (in the standard ordering) regardless of how scattered the
- * records were when they were originally read.
- */
- public void addRecords(RecordStream rs) {
- while (true) {
- if (!readARecord(rs)) {
- break;
- }
- }
- }
-
- /**
- * @return the ProtectRecord. If one is not contained in the sheet, then one
- * is created.
- */
- private ProtectRecord getProtect() {
- if (_protectRecord == null) {
- _protectRecord = new ProtectRecord(false);
- }
- return _protectRecord;
- }
-
- /**
- * @return the PasswordRecord. If one is not contained in the sheet, then
- * one is created.
- */
- private PasswordRecord getPassword() {
- if (_passwordRecord == null) {
- _passwordRecord = createPassword();
- }
- return _passwordRecord;
- }
-
- /**
- * protect a spreadsheet with a password (not encrypted, just sets protect
- * flags and the password.
- *
- * @param password to set. Pass {@code null} to remove all protection
- * @param shouldProtectObjects are protected
- * @param shouldProtectScenarios are protected
- */
- public void protectSheet(String password, boolean shouldProtectObjects,
- boolean shouldProtectScenarios) {
- if (password == null) {
- _passwordRecord = null;
- _protectRecord = null;
- _objectProtectRecord = null;
- _scenarioProtectRecord = null;
- return;
- }
-
- ProtectRecord prec = getProtect();
- PasswordRecord pass = getPassword();
- prec.setProtect(true);
- pass.setPassword((short)CryptoFunctions.createXorVerifier1(password));
- if (_objectProtectRecord == null && shouldProtectObjects) {
- ObjectProtectRecord rec = createObjectProtect();
- rec.setProtect(true);
- _objectProtectRecord = rec;
- }
- if (_scenarioProtectRecord == null && shouldProtectScenarios) {
- ScenarioProtectRecord srec = createScenarioProtect();
- srec.setProtect(true);
- _scenarioProtectRecord = srec;
- }
- }
-
- public boolean isSheetProtected() {
- return _protectRecord != null && _protectRecord.getProtect();
- }
-
- public boolean isObjectProtected() {
- return _objectProtectRecord != null && _objectProtectRecord.getProtect();
- }
-
- public boolean isScenarioProtected() {
- return _scenarioProtectRecord != null && _scenarioProtectRecord.getProtect();
- }
-
- /**
- * creates an ObjectProtect record with protect set to false.
- */
- private static ObjectProtectRecord createObjectProtect() {
- ObjectProtectRecord retval = new ObjectProtectRecord();
- retval.setProtect(false);
- return retval;
- }
-
- /**
- * creates a ScenarioProtect record with protect set to false.
- */
- private static ScenarioProtectRecord createScenarioProtect() {
- ScenarioProtectRecord retval = new ScenarioProtectRecord();
- retval.setProtect(false);
- return retval;
- }
-
- /**
- * creates a Password record with password set to 0x0000.
- */
- private static PasswordRecord createPassword() {
- return new PasswordRecord(0x0000);
- }
-
- public int getPasswordHash() {
- if (_passwordRecord == null) {
- return 0;
- }
- return _passwordRecord.getPassword();
- }
+ visitIfPresent(_protectRecord, rv);
+ visitIfPresent(_objectProtectRecord, rv);
+ visitIfPresent(_scenarioProtectRecord, rv);
+ visitIfPresent(_passwordRecord, rv);
+ }
+
+ private static void visitIfPresent(org.apache.poi.hssf.record.Record r, RecordVisitor rv) {
+ if (r != null) {
+ rv.visitRecord(r);
+ }
+ }
+
+ public PasswordRecord getPasswordRecord() {
+ return _passwordRecord;
+ }
+
+ public ScenarioProtectRecord getHCenter() {
+ return _scenarioProtectRecord;
+ }
+
+ /**
+ * This method reads WorksheetProtectionBlock records from the supplied RecordStream
+ * until the first non-WorksheetProtectionBlock record is encountered. As each record is read,
+ * it is incorporated into this WorksheetProtectionBlock.
+ * <p>
+ * As per the OOO documentation, the protection block records can be expected to be written
+ * together (with no intervening records), but earlier versions of POI (prior to Jun 2009)
+ * didn't do this. Workbooks with sheet protection created by those earlier POI versions
+ * seemed to be valid (Excel opens them OK). So PO allows continues to support reading of files
+ * with non continuous worksheet protection blocks.
+ *
+ * <p>
+ * <b>Note</b> - when POI writes out this WorksheetProtectionBlock, the records will always be
+ * written in one consolidated block (in the standard ordering) regardless of how scattered the
+ * records were when they were originally read.
+ */
+ public void addRecords(RecordStream rs) {
+ while (true) {
+ if (!readARecord(rs)) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * @return the ProtectRecord. If one is not contained in the sheet, then one
+ * is created.
+ */
+ private ProtectRecord getProtect() {
+ if (_protectRecord == null) {
+ _protectRecord = new ProtectRecord(false);
+ }
+ return _protectRecord;
+ }
+
+ /**
+ * @return the PasswordRecord. If one is not contained in the sheet, then
+ * one is created.
+ */
+ private PasswordRecord getPassword() {
+ if (_passwordRecord == null) {
+ _passwordRecord = createPassword();
+ }
+ return _passwordRecord;
+ }
+
+ /**
+ * protect a spreadsheet with a password (not encrypted, just sets protect
+ * flags and the password.
+ *
+ * @param password to set. Pass {@code null} to remove all protection
+ * @param shouldProtectObjects are protected
+ * @param shouldProtectScenarios are protected
+ */
+ public void protectSheet(String password, boolean shouldProtectObjects,
+ boolean shouldProtectScenarios) {
+ if (password == null) {
+ _passwordRecord = null;
+ _protectRecord = null;
+ _objectProtectRecord = null;
+ _scenarioProtectRecord = null;
+ return;
+ }
+
+ ProtectRecord prec = getProtect();
+ PasswordRecord pass = getPassword();
+ prec.setProtect(true);
+ pass.setPassword((short)CryptoFunctions.createXorVerifier1(password));
+ if (_objectProtectRecord == null && shouldProtectObjects) {
+ ObjectProtectRecord rec = createObjectProtect();
+ rec.setProtect(true);
+ _objectProtectRecord = rec;
+ }
+ if (_scenarioProtectRecord == null && shouldProtectScenarios) {
+ ScenarioProtectRecord srec = createScenarioProtect();
+ srec.setProtect(true);
+ _scenarioProtectRecord = srec;
+ }
+ }
+
+ public boolean isSheetProtected() {
+ return _protectRecord != null && _protectRecord.getProtect();
+ }
+
+ public boolean isObjectProtected() {
+ return _objectProtectRecord != null && _objectProtectRecord.getProtect();
+ }
+
+ public boolean isScenarioProtected() {
+ return _scenarioProtectRecord != null && _scenarioProtectRecord.getProtect();
+ }
+
+ /**
+ * creates an ObjectProtect record with protect set to false.
+ */
+ private static ObjectProtectRecord createObjectProtect() {
+ ObjectProtectRecord retval = new ObjectProtectRecord();
+ retval.setProtect(false);
+ return retval;
+ }
+
+ /**
+ * creates a ScenarioProtect record with protect set to false.
+ */
+ private static ScenarioProtectRecord createScenarioProtect() {
+ ScenarioProtectRecord retval = new ScenarioProtectRecord();
+ retval.setProtect(false);
+ return retval;
+ }
+
+ /**
+ * creates a Password record with password set to 0x0000.
+ */
+ private static PasswordRecord createPassword() {
+ return new PasswordRecord(0x0000);
+ }
+
+ public int getPasswordHash() {
+ if (_passwordRecord == null) {
+ return 0;
+ }
+ return _passwordRecord.getPassword();
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/cf/FontFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/cf/FontFormatting.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/cf/FontFormatting.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/cf/FontFormatting.java Sat May 22 20:56:44 2021
@@ -71,7 +71,7 @@ public final class FontFormatting implem
/**
* Bold boldness (bold)
*/
- private static final short FONT_WEIGHT_BOLD = 0x2bc;
+ private static final short FONT_WEIGHT_BOLD = 0x2bc;
private final byte[] _rawData = new byte[RAW_DATA_SIZE];
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org