Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Hyperlink without Remove #727

Merged
merged 2 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion main/HSSF/Record/Aggregates/RowRecordsAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ public class RowRecordsAggregate : RecordAggregate
private SortedList _rowRecords;
//private int size = 0;
private ValueRecordsAggregate _valuesAgg;
private List<HyperlinkRecord> _hyperlinkRecordRecords;
private List<Record> _unknownRecords;
private SharedValueManager _sharedValueManager;

// Cache values to speed up performance of
// getStartRowNumberForBlock / getEndRowNumberForBlock, see Bugzilla 47405
private RowRecord[] _rowRecordValues = null;

public IEnumerable<HyperlinkRecord> HyperlinkRecordRecords { get => _hyperlinkRecordRecords; }

/** Creates a new instance of ValueRecordsAggregate */

Expand All @@ -60,6 +61,7 @@ private RowRecordsAggregate(SharedValueManager svm)
{
_rowRecords = new SortedList();
_valuesAgg = new ValueRecordsAggregate();
_hyperlinkRecordRecords = new List<HyperlinkRecord>();
_unknownRecords = new List<Record>();
_sharedValueManager = svm;
}
Expand Down Expand Up @@ -124,6 +126,10 @@ public override void VisitContainedRecords(RecordVisitor rv)
// Calculate Offset from the start of a DBCellRecord to the first Row
cellRecord.RowOffset = (pos);
rv.VisitRecord(cellRecord);
}
foreach (Record _hyperlinkRecord in _hyperlinkRecordRecords)
{
rv.VisitRecord(_hyperlinkRecord);
}
foreach (Record _unknownRecord in _unknownRecords)
{
Expand All @@ -149,6 +155,9 @@ public RowRecordsAggregate(RecordStream rs, SharedValueManager svm)
case DConRefRecord.sid:
AddUnknownRecord(rec);
continue;
case HyperlinkRecord.sid:
_hyperlinkRecordRecords.Add((HyperlinkRecord)rec);
continue;
case DBCellRecord.sid:
// end of 'Row Block'. Should only occur after cell records
// ignore DBCELL records because POI generates them upon re-serialization
Expand Down
17 changes: 17 additions & 0 deletions main/HSSF/UserModel/HSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,15 @@ public IHyperlink GetHyperlink(int row, int column)
{
return new HSSFHyperlink(link);
}
}
else if (rec is RowRecordsAggregate rra) {
foreach (var link in rra.HyperlinkRecordRecords)
{
if (link.FirstColumn == column && link.FirstRow == row)
{
return new HSSFHyperlink(link);
}
}
}
}
return null;
Expand Down Expand Up @@ -2448,6 +2457,14 @@ public List<IHyperlink> GetHyperlinkList()
if (rec is HyperlinkRecord){
HyperlinkRecord link = (HyperlinkRecord)rec;
hyperlinkList.Add(new HSSFHyperlink(link));
}
else if (rec is RowRecordsAggregate rra) {
foreach (var link in rra.HyperlinkRecordRecords)
{
if (link is HyperlinkRecord hylink){
hyperlinkList.Add(new HSSFHyperlink(link));
}
}
}
}
return hyperlinkList;
Expand Down
11 changes: 11 additions & 0 deletions testcases/main/HSSF/UserModel/TestBugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3485,5 +3485,16 @@ public void Test53564()
//fos.Close();
wb.Close();
}


// follow https://svn.apache.org/viewvc?view=revision&revision=1896552 to write a unit test for this fix.
[Test]
public void test52447()
{
using (IWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("52447.xls"))
{
Assert.IsNotNull(cell.CellFormula);
}
}
}
}
Binary file added testcases/test-data/spreadsheet/52447.xls
Binary file not shown.