public void TestCopyCellFrom_CellCopyPolicy_mergeHyperlink() { //setUp_testCopyCellFrom_CellCopyPolicy(); IWorkbook wb = srcCell.Sheet.Workbook; ICreationHelper createHelper = wb.GetCreationHelper(); srcCell.SetCellValue("URL LINK"); IHyperlink link = createHelper.CreateHyperlink(HyperlinkType.Url); link.Address = ("http://poi.apache.org/"); destCell.Hyperlink = (link); // Set link cell style (optional) ICellStyle hlinkStyle = wb.CreateCellStyle(); IFont hlinkFont = wb.CreateFont(); hlinkFont.Underline = FontUnderlineType.Single; hlinkFont.Color = (IndexedColors.Blue.Index); hlinkStyle.SetFont(hlinkFont); destCell.CellStyle = (hlinkStyle); // Pre-condition assumptions. This test is broken if either of these Assert.Fail. Assert.AreSame(srcCell.Sheet, destCell.Sheet, "unit test assumes srcCell and destCell are on the same sheet"); Assert.IsNull(srcCell.Hyperlink); // Merge hyperlink - since srcCell doesn't have a hyperlink, destCell's hyperlink is not overwritten (cleared). CellCopyPolicy policy = new CellCopyPolicy.Builder().MergeHyperlink(true).CopyHyperlink(false).Build(); destCell.CopyCellFrom(srcCell, policy); Assert.IsNull(srcCell.Hyperlink); Assert.IsNotNull(destCell.Hyperlink); Assert.AreSame(link, destCell.Hyperlink); List <IHyperlink> links; links = srcCell.Sheet.GetHyperlinkList(); Assert.AreEqual(1, links.Count, "number of hyperlinks on sheet"); Assert.AreEqual(new CellReference(destCell).FormatAsString(), (links[(0)] as XSSFHyperlink).CellRef, "source hyperlink"); // Merge destCell's hyperlink to srcCell. Since destCell does have a hyperlink, this should copy destCell's hyperlink to srcCell. srcCell.CopyCellFrom(destCell, policy); Assert.IsNotNull(srcCell.Hyperlink); Assert.IsNotNull(destCell.Hyperlink); links = srcCell.Sheet.GetHyperlinkList(); Assert.AreEqual(2, links.Count, "number of hyperlinks on sheet"); Assert.AreEqual(new CellReference(destCell).FormatAsString(), (links[(0)] as XSSFHyperlink).CellRef, "dest hyperlink"); Assert.AreEqual(new CellReference(srcCell).FormatAsString(), (links[(1)] as XSSFHyperlink).CellRef, "source hyperlink"); wb.Close(); }