Hey,
I have found a problem with the CellArea of a hyperlink. In my test file I have three hyperlinks in merged cells, but the last one is not recognized as Range.
Sample file
HyperlinkRange.zip (6.2 KB)
Code
_workbook = new Workbook(Example);
var links = _workbook.Worksheets[0].Hyperlinks;
The last Hyperlink CellArea is wrong.
@mservdev
Thanks for using Aspose APIs.
We were able to observe this issue as per your description as shown in the following screenshot. We have logged it in our database for investigation and for a fix. Once, the issue is resolved or we have some other news for you, we will let you know asap.
This issue has been logged as
- CELLSNET-45972 - Hyperlink range is not determined correctly
Screenshot:
1 Like
@mservdev
Thanks for using Aspose APIs.
The last hyperlink is
<hyperlink ref="A5" r:id="rId5"/>
so we simply return A5. Please get the range by the following code.
worksheet.Cells["A5"].GetMergedRange();
@shakeel.faiz
Thanks for your answer. I still think that this is a “bug”, because Excel displays this as a merged cell.
<mergeCells count="3">
<mergeCell ref="A1:C1"/>
<mergeCell ref="A2:C4"/>
<mergeCell ref="A5:C5"/> <-- A5 is in a merged cell range
</mergeCells>
<hyperlinks>
<hyperlink ref="A1" r:id="rId1" display="http://www.aspose.com"/>
<hyperlink ref="A1:C1" r:id="rId2" display="Aspose"/>
<hyperlink ref="A2" r:id="rId3" display="www.microsoft.com"/>
<hyperlink ref="A2:C4" r:id="rId4" display="Microsoft"/>
<hyperlink ref="A5" r:id="rId5"/> <-- In my opinion, it's wrong.
</hyperlinks>
Here you can see that the A5 cell is directly affected by a merged cell. Couldn’t there be any way to check it out?
My problem is, if I don’t run through the cells but have to access the hyperlinks, I won’t get all affected cells at this point.
Here a concrete problem of mine, in which the hyperlinks are traversed and the combined result gets the cell value, see example:
private void ProcessHyperlinks()
{
foreach (var item in Sheet.Hyperlinks)
{
var upperLeft = CellsHelper.CellIndexToName(item.Area.StartRow, item.Area.StartColumn);
var lowerRight = CellsHelper.CellIndexToName(item.Area.EndRow, item.Area.EndColumn);
var range = Sheet.Cells.CreateRange(upperLeft, lowerRight);
range.PutValue($"{item.TextToDisplay} ({item.Address})", false, false);
}
}
@mservdev
You may use these properties and methods for your needs. It should help you fix your problem.
Cell.IsMerged
It will tell, if the cell is a merged cell or not.
Cell.GetMergedRange()
If the cell is merged cell, it will return the merged range.
Worksheet.Cells.MergedCells
It will return all the merged cells inside the worksheet.
Thank you. Cell.IsMerged with Cell.GetMergedRange() helps me in this case.