コード例 #1
0
ファイル: TestXSSFComment.cs プロジェクト: xewn/Npoi.Core
        public void SetString()
        {
            XSSFWorkbook wb      = new XSSFWorkbook();
            XSSFSheet    sh      = (XSSFSheet)wb.CreateSheet();
            XSSFComment  comment = (XSSFComment)sh.CreateDrawingPatriarch().CreateCellComment(new XSSFClientAnchor());

            //passing HSSFRichTextString is incorrect
            try
            {
                comment.String = (new HSSFRichTextString(TEST_RICHTEXTSTRING));
                Assert.Fail("expected exception");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual("Only XSSFRichTextString argument is supported", e.Message);
            }

            //simple string argument
            comment.SetString(TEST_RICHTEXTSTRING);
            Assert.AreEqual(TEST_RICHTEXTSTRING, comment.String.String);

            //if the text is already Set, it should be overridden, not Added twice!
            comment.SetString(TEST_RICHTEXTSTRING);

            CT_Comment ctComment = comment.GetCTComment();

            //  Assert.Fail("TODO test case incomplete!?");
            //XmlObject[] obj = ctComment.selectPath(
            //        "declare namespace w='http://schemas.Openxmlformats.org/spreadsheetml/2006/main' .//w:text");
            //Assert.AreEqual(1, obj.Length);
            Assert.AreEqual(TEST_RICHTEXTSTRING, comment.String.String);

            //sequential call of comment.String should return the same XSSFRichTextString object
            Assert.AreSame(comment.String, comment.String);

            XSSFRichTextString richText = new XSSFRichTextString(TEST_RICHTEXTSTRING);
            XSSFFont           font1    = (XSSFFont)wb.CreateFont();

            font1.FontName   = ("Tahoma");
            font1.FontHeight = 8.5;
            font1.IsItalic   = true;
            font1.Color      = IndexedColors.BlueGrey.Index;
            richText.ApplyFont(0, 5, font1);

            //check the low-level stuff
            comment.String = richText;
            //obj = ctComment.selectPath(
            //        "declare namespace w='http://schemas.Openxmlformats.org/spreadsheetml/2006/main' .//w:text");
            //Assert.AreEqual(1, obj.Length);
            Assert.AreSame(comment.String, richText);
            //check that the rich text is Set in the comment
            CT_RPrElt rPr = richText.GetCTRst().GetRArray(0).rPr;

            Assert.AreEqual(true, rPr.GetIArray(0).val);
            Assert.AreEqual(8.5, rPr.GetSzArray(0).val);
            Assert.AreEqual(IndexedColors.BlueGrey.Index, (short)rPr.GetColorArray(0).indexed);
            Assert.AreEqual("Tahoma", rPr.GetRFontArray(0).val);

            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb));
        }
コード例 #2
0
        public void TestBug56835CellComment()
        {
            XSSFWorkbook wb = new XSSFWorkbook();

            try
            {
                XSSFSheet   sheet   = wb.CreateSheet() as XSSFSheet;
                XSSFDrawing Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

                // first comment works
                IClientAnchor anchor  = new XSSFClientAnchor(1, 1, 2, 2, 3, 3, 4, 4);
                XSSFComment   comment = Drawing.CreateCellComment(anchor) as XSSFComment;
                Assert.IsNotNull(comment);

                try
                {
                    Drawing.CreateCellComment(anchor);
                    Assert.Fail("Should fail if we try to add the same comment for the same cell");
                }
                catch (ArgumentException)
                {
                    // expected
                }
            }
            finally
            {
                wb.Close();
            }
        }
コード例 #3
0
ファイル: TestXSSFComment.cs プロジェクト: xewn/Npoi.Core
        public void Author()
        {
            CommentsTable sheetComments = new CommentsTable();
            CT_Comment    ctComment     = sheetComments.NewComment("A1");

            Assert.AreEqual(1, sheetComments.GetNumberOfAuthors());
            XSSFComment comment = new XSSFComment(sheetComments, ctComment, null);

            Assert.AreEqual("", comment.Author);
            comment.Author = ("Apache POI");
            Assert.AreEqual("Apache POI", comment.Author);
            Assert.AreEqual(2, sheetComments.GetNumberOfAuthors());
            comment.Author = ("Apache POI");
            Assert.AreEqual(2, sheetComments.GetNumberOfAuthors());
            comment.Author = ("");
            Assert.AreEqual("", comment.Author);
            Assert.AreEqual(2, sheetComments.GetNumberOfAuthors());
        }
コード例 #4
0
ファイル: TestXSSFComment.cs プロジェクト: xewn/Npoi.Core
        public void GetSetRow()
        {
            CommentsTable  sheetComments = new CommentsTable();
            XSSFVMLDrawing vml           = new XSSFVMLDrawing();
            CT_Comment     ctComment     = sheetComments.NewComment("A1");
            CT_Shape       vmlShape      = vml.newCommentShape();

            XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);

            comment.Row = (1);
            Assert.AreEqual(1, comment.Row);
            Assert.AreEqual(1, new CellReference(ctComment.@ref).Row);
            Assert.AreEqual(1, vmlShape.GetClientDataArray(0).GetRowArray(0));

            comment.Row = (5);
            Assert.AreEqual(5, comment.Row);
            Assert.AreEqual(5, new CellReference(ctComment.@ref).Row);
            Assert.AreEqual(5, vmlShape.GetClientDataArray(0).GetRowArray(0));
        }
コード例 #5
0
ファイル: TestXSSFComment.cs プロジェクト: xewn/Npoi.Core
        public void Constructor()
        {
            CommentsTable sheetComments = new CommentsTable();

            Assert.IsNotNull(sheetComments.GetCTComments().commentList);
            Assert.IsNotNull(sheetComments.GetCTComments().authors);
            Assert.AreEqual(1, sheetComments.GetCTComments().authors.SizeOfAuthorArray());
            Assert.AreEqual(1, sheetComments.GetNumberOfAuthors());

            CT_Comment ctComment = sheetComments.NewComment("A1");
            CT_Shape   vmlShape  = new CT_Shape();

            XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);

            Assert.AreEqual(null, comment.String.String);
            Assert.AreEqual(0, comment.Row);
            Assert.AreEqual(0, comment.Column);
            Assert.AreEqual("", comment.Author);
            Assert.AreEqual(false, comment.Visible);
        }
コード例 #6
0
ファイル: TestXSSFWorkbook.cs プロジェクト: ruo2012/Npoi.Core
        public void Bug51158()
        {
            // create a workbook
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet    sheet    = workbook.CreateSheet("Test Sheet") as XSSFSheet;
            XSSFRow      row      = sheet.CreateRow(2) as XSSFRow;
            XSSFCell     cell     = row.CreateCell(3) as XSSFCell;

            cell.SetCellValue("test1");

            //XSSFCreationHelper helper = workbook.GetCreationHelper();
            //cell.Hyperlink=(/*setter*/helper.CreateHyperlink(0));

            XSSFComment comment = (sheet.CreateDrawingPatriarch() as XSSFDrawing).CreateCellComment(new XSSFClientAnchor()) as XSSFComment;

            Assert.IsNotNull(comment);
            comment.SetString("some comment");

            //        ICellStyle cs = workbook.CreateCellStyle();
            //        cs.ShrinkToFit=(/*setter*/false);
            //        row.CreateCell(0).CellStyle=(/*setter*/cs);

            // write the first excel file
            XSSFWorkbook readBack = XSSFTestDataSamples.WriteOutAndReadBack(workbook) as XSSFWorkbook;

            Assert.IsNotNull(readBack);
            Assert.AreEqual("test1", readBack.GetSheetAt(0).GetRow(2).GetCell(3).StringCellValue);
            Assert.IsNull(readBack.GetSheetAt(0).GetRow(2).GetCell(4));

            // add a new cell to the sheet
            cell = row.CreateCell(4) as XSSFCell;
            cell.SetCellValue("test2");

            // write the second excel file
            readBack = XSSFTestDataSamples.WriteOutAndReadBack(workbook) as XSSFWorkbook;
            Assert.IsNotNull(readBack);
            Assert.AreEqual("test1", readBack.GetSheetAt(0).GetRow(2).GetCell(3).StringCellValue);
            Assert.AreEqual("test2", readBack.GetSheetAt(0).GetRow(2).GetCell(4).StringCellValue);
        }