public void TestCopyCellFrom_CellCopyPolicy_value() { setUp_testCopyCellFrom_CellCopyPolicy(); // Paste values only CellCopyPolicy policy = new CellCopyPolicy.Builder().CellFormula(false).Build(); destCell.CopyCellFrom(srcCell, policy); Assert.AreEqual(CellType.Numeric, destCell.CellType); }
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(); }
public void TestCopyCellFrom_CellCopyPolicy_formulaWithUnregisteredUDF() { //setUp_testCopyCellFrom_CellCopyPolicy(); srcCell.CellFormula = ("MYFUNC2(123, $A5, Sheet1!$B7)"); // Copy formula verbatim (no shifting). This is okay because copyCellFrom is Internal. // Users should use higher-level copying functions to row- or column-shift formulas. CellCopyPolicy policy = new CellCopyPolicy.Builder().CellFormula(true).Build(); destCell.CopyCellFrom(srcCell, policy); Assert.AreEqual("MYFUNC2(123, $A5, Sheet1!$B7)", destCell.CellFormula); }
public void TestCopyCellFrom_CellCopyPolicy_style() { setUp_testCopyCellFrom_CellCopyPolicy(); srcCell.SetCellValue((String)null); // Paste styles only CellCopyPolicy policy = new CellCopyPolicy.Builder().CellValue(false).Build(); destCell.CopyCellFrom(srcCell, policy); Assert.AreEqual(srcCell.CellStyle, destCell.CellStyle); // Old cell value should not have been overwritten Assert.AreNotEqual(CellType.Blank, destCell.CellType); Assert.AreEqual(CellType.Boolean, destCell.CellType); Assert.AreEqual(true, destCell.BooleanCellValue); }
public void TestCopyCellFrom_CellCopyPolicy_copyHyperlink() { //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/"); srcCell.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); srcCell.CellStyle = (hlinkStyle); // Copy hyperlink CellCopyPolicy policy = new CellCopyPolicy.Builder().CopyHyperlink(true).MergeHyperlink(false).Build(); destCell.CopyCellFrom(srcCell, policy); Assert.IsNotNull(destCell.Hyperlink); Assert.AreSame(srcCell.Sheet, destCell.Sheet, "unit test assumes srcCell and destCell are on the same sheet"); List <IHyperlink> links = srcCell.Sheet.GetHyperlinkList(); Assert.AreEqual(2, links.Count, "number of hyperlinks on sheet"); Assert.AreEqual(new CellReference(srcCell).FormatAsString(), (links[(0)] as XSSFHyperlink).CellRef, "source hyperlink"); Assert.AreEqual(new CellReference(destCell).FormatAsString(), (links[(1)] as XSSFHyperlink).CellRef, "destination hyperlink"); wb.Close(); }