Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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();
        }