Skip to content

Commit 48cdca1

Browse files
authored
Merge pull request #1703 from antony-liu/poi/v4.0-patch6
Some patches from poi
2 parents b2938d5 + b2f805f commit 48cdca1

36 files changed

+1369
-129
lines changed

OpenXmlFormats/Spreadsheet/Sheet.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5805,6 +5805,97 @@ public static CT_HeaderFooter Parse(XmlNode node, XmlNamespaceManager namespaceM
58055805
return ctObj;
58065806
}
58075807

5808+
public bool IsSetAlignWithMargins()
5809+
{
5810+
return !this.alignWithMargins;
5811+
}
5812+
5813+
public bool IsSetDifferentFirst()
5814+
{
5815+
return this.differentFirst;
5816+
}
5817+
5818+
public bool IsSetDifferentOddEven()
5819+
{
5820+
return this.differentOddEven;
5821+
}
5822+
5823+
public bool IsSetEvenFooter()
5824+
{
5825+
return this.evenFooter != null;
5826+
}
5827+
5828+
public bool IsSetEvenHeader()
5829+
{
5830+
return this.evenHeader != null;
5831+
}
5832+
5833+
public bool IsSetFirstFooter()
5834+
{
5835+
return this.firstFooter != null;
5836+
}
5837+
5838+
public bool IsSetFirstHeader()
5839+
{
5840+
return this.firstHeader != null;
5841+
}
5842+
5843+
public bool IsSetScaleWithDoc()
5844+
{
5845+
return !this.scaleWithDoc;
5846+
}
5847+
5848+
public void UnsetScaleWithDoc()
5849+
{
5850+
this.scaleWithDoc = true;
5851+
}
5852+
5853+
public void UnsetAlignWithMargins()
5854+
{
5855+
this.alignWithMargins = true;
5856+
}
5857+
5858+
public void UnsetDifferentFirst()
5859+
{
5860+
this.differentFirst = false;
5861+
}
5862+
5863+
public void UnsetDifferentOddEven()
5864+
{
5865+
this.differentOddEven = false;
5866+
}
5867+
5868+
public void UnsetEvenFooter()
5869+
{
5870+
this.evenFooter = null;
5871+
}
5872+
5873+
public void UnsetEvenHeader()
5874+
{
5875+
this.evenHeader = null;
5876+
}
5877+
5878+
public void UnsetFirstFooter()
5879+
{
5880+
this.firstFooter = null;
5881+
}
5882+
5883+
public void UnsetFirstHeader()
5884+
{
5885+
this.firstHeader = null;
5886+
}
5887+
5888+
public void UnsetOddFooter()
5889+
{
5890+
this.oddFooter = null;
5891+
}
5892+
5893+
public void UnsetOddHeader()
5894+
{
5895+
this.oddHeader = null;
5896+
}
5897+
5898+
58085899
internal void Write(StreamWriter sw, string nodeName)
58095900
{
58105901
sw.WriteStart(nodeName);

OpenXmlFormats/Spreadsheet/Sheet/CT_SheetData.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public CT_Row GetRowArray(int index)
107107
{
108108
return (null == rowField) ? null : rowField[index];
109109
}
110+
public List<CT_Row> GetRowArray()
111+
{
112+
return row;
113+
}
110114
[XmlElement("row")]
111115
public List<CT_Row> row
112116
{

main/HSSF/UserModel/HSSFEvaluationSheet.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ public class HSSFEvaluationSheet : IEvaluationSheet
2929
{
3030

3131
private readonly HSSFSheet _hs;
32+
private int _lastDefinedRow = -1;
3233

3334
public HSSFEvaluationSheet(HSSFSheet hs)
3435
{
3536
_hs = hs;
37+
_lastDefinedRow = _hs.LastRowNum;
3638
}
3739

3840
public HSSFSheet HSSFSheet
@@ -42,6 +44,19 @@ public HSSFSheet HSSFSheet
4244
return _hs;
4345
}
4446
}
47+
48+
/* (non-Javadoc)
49+
* @see org.apache.poi.ss.formula.EvaluationSheet#getlastRowNum()
50+
* @since POI 4.0.0
51+
*/
52+
public int LastRowNum
53+
{
54+
get
55+
{
56+
return _lastDefinedRow;
57+
}
58+
}
59+
4560
public IEvaluationCell GetCell(int rowIndex, int columnIndex)
4661
{
4762
HSSFRow row = (HSSFRow)_hs.GetRow(rowIndex);
@@ -59,7 +74,7 @@ public IEvaluationCell GetCell(int rowIndex, int columnIndex)
5974

6075
public void ClearAllCachedResultValues()
6176
{
62-
// nothing to do
77+
_lastDefinedRow = _hs.LastRowNum;
6378
}
6479
}
6580
}

main/SS/Formula/CellEvaluationFrame.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ private CellCacheEntry[] GetSensitiveInputCells()
7171
}
7272
return _sensitiveInputCells.ToArray();
7373
}
74-
public void AddUsedBlankCell(int bookIndex, int sheetIndex, int rowIndex, int columnIndex)
74+
public void AddUsedBlankCell(IEvaluationWorkbook evalWorkbook, int bookIndex, int sheetIndex, int rowIndex, int columnIndex)
7575
{
7676
if (_usedBlankCellGroup == null)
7777
{
7878
_usedBlankCellGroup = new FormulaUsedBlankCellSet();
7979
}
80-
_usedBlankCellGroup.AddCell(bookIndex, sheetIndex, rowIndex, columnIndex);
80+
_usedBlankCellGroup.AddCell(evalWorkbook, bookIndex, sheetIndex, rowIndex, columnIndex);
8181
}
8282

8383
public void UpdateFormulaResult(ValueEval result)

main/SS/Formula/Eval/Forked/ForkedEvaluationSheet.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ public ForkedEvaluationSheet(IEvaluationSheet masterSheet)
4747
_sharedCellsByRowCol = new Dictionary<RowColKey, ForkedEvaluationCell>();
4848
}
4949

50+
/* (non-Javadoc)
51+
* @see org.apache.poi.ss.formula.EvaluationSheet#getlastRowNum()
52+
* @since POI 4.0.0
53+
*/
54+
public int LastRowNum
55+
{
56+
get
57+
{
58+
return _masterSheet.LastRowNum;
59+
}
60+
}
61+
5062
public IEvaluationCell GetCell(int rowIndex, int columnIndex)
5163
{
5264
RowColKey key = new RowColKey(rowIndex, columnIndex);

main/SS/Formula/EvaluationSheet.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,11 @@ public interface IEvaluationSheet
3939
* @see EvaluationWorkbook#clearAllCachedResultValues()
4040
*/
4141
void ClearAllCachedResultValues();
42+
43+
/**
44+
* @return last row index referenced on this sheet, for evaluation optimization
45+
* @since POI 4.0.0
46+
*/
47+
public int LastRowNum { get; }
4248
}
4349
}

main/SS/Formula/EvaluationTracker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void AcceptFormulaDependency(CellCacheEntry cce)
133133
}
134134
}
135135

136-
public void AcceptPlainValueDependency(int bookIndex, int sheetIndex,
136+
public void AcceptPlainValueDependency(IEvaluationWorkbook evalWorkbook, int bookIndex, int sheetIndex,
137137
int rowIndex, int columnIndex, ValueEval value)
138138
{
139139
// Tell the currently evaluating cell frame that it Has a dependency on the specified
@@ -147,7 +147,7 @@ public void AcceptPlainValueDependency(int bookIndex, int sheetIndex,
147147
CellEvaluationFrame consumingFrame = (CellEvaluationFrame)_evaluationFrames[prevFrameIndex];
148148
if (value == BlankEval.instance)
149149
{
150-
consumingFrame.AddUsedBlankCell(bookIndex, sheetIndex, rowIndex, columnIndex);
150+
consumingFrame.AddUsedBlankCell(evalWorkbook, bookIndex, sheetIndex, rowIndex, columnIndex);
151151
}
152152
else
153153
{

main/SS/Formula/FormulaShifter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private Ptg AdjustPtgDueToRowMove(Ptg ptg, int currentExternSheetIx)
305305
if (ptg is Ref3DPxg rpxg)
306306
{
307307
if (rpxg.ExternalWorkbookNumber > 0 ||
308-
!_sheetName.Equals(rpxg.SheetName))
308+
!_sheetName.Equals(rpxg.SheetName, StringComparison.OrdinalIgnoreCase))
309309
{
310310
// only move 3D refs that refer to the sheet with cells
311311
// being moved
@@ -341,7 +341,7 @@ private Ptg AdjustPtgDueToRowMove(Ptg ptg, int currentExternSheetIx)
341341
if (ptg is Area3DPxg apxg)
342342
{
343343
if (apxg.ExternalWorkbookNumber > 0 ||
344-
!_sheetName.Equals(apxg.SheetName))
344+
!_sheetName.Equals(apxg.SheetName, StringComparison.OrdinalIgnoreCase))
345345
{
346346
// only move 3D refs that refer to the sheet with cells
347347
// being moved
@@ -390,7 +390,7 @@ private Ptg AdjustPtgDueToColumnMove(Ptg ptg, int currentExternSheetIx)
390390
if (ptg is Ref3DPxg rpxg)
391391
{
392392
if (rpxg.ExternalWorkbookNumber > 0 ||
393-
!_sheetName.Equals(rpxg.SheetName))
393+
!_sheetName.Equals(rpxg.SheetName, StringComparison.OrdinalIgnoreCase))
394394
{
395395
// only move 3D refs that refer to the sheet with cells
396396
// being moved
@@ -426,7 +426,7 @@ private Ptg AdjustPtgDueToColumnMove(Ptg ptg, int currentExternSheetIx)
426426
if (ptg is Area3DPxg apxg)
427427
{
428428
if (apxg.ExternalWorkbookNumber > 0 ||
429-
!_sheetName.Equals(apxg.SheetName))
429+
!_sheetName.Equals(apxg.SheetName, StringComparison.OrdinalIgnoreCase))
430430
{
431431
// only move 3D refs that refer to the sheet with cells
432432
// being moved

main/SS/Formula/FormulaUsedBlankCellSet.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@ private class BlankCellSheetGroup
6262
private int _firstColumnIndex;
6363
private int _lastColumnIndex;
6464
private BlankCellRectangleGroup _currentRectangleGroup;
65+
private int _lastDefinedRow;
6566

66-
public BlankCellSheetGroup()
67+
public BlankCellSheetGroup(int lastDefinedRow)
6768
{
6869
_rectangleGroups = [];
6970
_currentRowIndex = -1;
71+
_lastDefinedRow = lastDefinedRow;
7072
}
7173

7274
public void AddCell(int rowIndex, int columnIndex)
7375
{
76+
if(rowIndex > _lastDefinedRow)
77+
return;
7478
if (_currentRowIndex == -1)
7579
{
7680
_currentRowIndex = rowIndex;
@@ -107,6 +111,8 @@ public void AddCell(int rowIndex, int columnIndex)
107111

108112
public bool ContainsCell(int rowIndex, int columnIndex)
109113
{
114+
if(rowIndex > _lastDefinedRow)
115+
return true;
110116
for (int i = _rectangleGroups.Count - 1; i >= 0; i--)
111117
{
112118
BlankCellRectangleGroup bcrg = (BlankCellRectangleGroup)_rectangleGroups[i];
@@ -203,20 +209,20 @@ public FormulaUsedBlankCellSet()
203209
_sheetGroupsByBookSheet = new Hashtable();
204210
}
205211

206-
public void AddCell(int bookIndex, int sheetIndex, int rowIndex, int columnIndex)
212+
public void AddCell(IEvaluationWorkbook evalWorkbook, int bookIndex, int sheetIndex, int rowIndex, int columnIndex)
207213
{
208-
BlankCellSheetGroup sbcg = GetSheetGroup(bookIndex, sheetIndex);
214+
BlankCellSheetGroup sbcg = GetSheetGroup(evalWorkbook, bookIndex, sheetIndex);
209215
sbcg.AddCell(rowIndex, columnIndex);
210216
}
211217

212-
private BlankCellSheetGroup GetSheetGroup(int bookIndex, int sheetIndex)
218+
private BlankCellSheetGroup GetSheetGroup(IEvaluationWorkbook evalWorkbook, int bookIndex, int sheetIndex)
213219
{
214220
BookSheetKey key = new BookSheetKey(bookIndex, sheetIndex);
215221

216222
BlankCellSheetGroup result = (BlankCellSheetGroup)_sheetGroupsByBookSheet[key];
217223
if (result == null)
218224
{
219-
result = new BlankCellSheetGroup();
225+
result = new BlankCellSheetGroup(evalWorkbook.GetSheet(sheetIndex).LastRowNum);
220226
_sheetGroupsByBookSheet[key]= result;
221227
}
222228
return result;

main/SS/Formula/WorkbookEvaluator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private ValueEval EvaluateAny(IEvaluationCell srcCell, int sheetIndex,
407407
result = GetValueFromNonFormulaCell(srcCell);
408408
if (shouldCellDependencyBeRecorded)
409409
{
410-
tracker.AcceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result);
410+
tracker.AcceptPlainValueDependency(_workbook, _workbookIx, sheetIndex, rowIndex, columnIndex, result);
411411
}
412412
return result;
413413
}

0 commit comments

Comments
 (0)