Пример #1
0
        public void GetCellComment()
        {
            CommentsTable sheetComments = new CommentsTable();

            CT_Comments    comments    = sheetComments.GetCTComments();
            CT_CommentList commentList = comments.commentList;

            // Create 2 comments for A1 and A" cells
            CT_Comment comment0 = commentList.InsertNewComment(0);

            comment0.@ref = "A1";
            CT_Rst ctrst0 = new CT_Rst();

            ctrst0.t      = (TEST_A1_TEXT);
            comment0.text = (ctrst0);
            CT_Comment comment1 = commentList.InsertNewComment(0);

            comment1.@ref = ("A2");
            CT_Rst ctrst1 = new CT_Rst();

            ctrst1.t      = (TEST_A2_TEXT);
            comment1.text = (ctrst1);

            // Test Finding the right comment for a cell
            Assert.AreSame(comment0, sheetComments.GetCTComment("A1"));
            Assert.AreSame(comment1, sheetComments.GetCTComment("A2"));
            Assert.IsNull(sheetComments.GetCTComment("A3"));
        }
Пример #2
0
        public void RemoveComment()
        {
            CommentsTable sheetComments = new CommentsTable();
            CT_Comment    a1            = sheetComments.NewComment("A1");
            CT_Comment    a2            = sheetComments.NewComment("A2");
            CT_Comment    a3            = sheetComments.NewComment("A3");

            Assert.AreSame(a1, sheetComments.GetCTComment("A1"));
            Assert.AreSame(a2, sheetComments.GetCTComment("A2"));
            Assert.AreSame(a3, sheetComments.GetCTComment("A3"));
            Assert.AreEqual(3, sheetComments.GetNumberOfComments());

            Assert.IsTrue(sheetComments.RemoveComment("A1"));
            Assert.AreEqual(2, sheetComments.GetNumberOfComments());
            Assert.IsNull(sheetComments.GetCTComment("A1"));
            Assert.AreSame(a2, sheetComments.GetCTComment("A2"));
            Assert.AreSame(a3, sheetComments.GetCTComment("A3"));

            Assert.IsTrue(sheetComments.RemoveComment("A2"));
            Assert.AreEqual(1, sheetComments.GetNumberOfComments());
            Assert.IsNull(sheetComments.GetCTComment("A1"));
            Assert.IsNull(sheetComments.GetCTComment("A2"));
            Assert.AreSame(a3, sheetComments.GetCTComment("A3"));

            Assert.IsTrue(sheetComments.RemoveComment("A3"));
            Assert.AreEqual(0, sheetComments.GetNumberOfComments());
            Assert.IsNull(sheetComments.GetCTComment("A1"));
            Assert.IsNull(sheetComments.GetCTComment("A2"));
            Assert.IsNull(sheetComments.GetCTComment("A3"));
        }
Пример #3
0
        public void RemoveComment()
        {
            CellAddress addrA1 = new CellAddress("A1");
            CellAddress addrA2 = new CellAddress("A2");
            CellAddress addrA3 = new CellAddress("A3");

            CommentsTable sheetComments = new CommentsTable();
            CT_Comment    a1            = sheetComments.NewComment(addrA1);
            CT_Comment    a2            = sheetComments.NewComment(addrA2);
            CT_Comment    a3            = sheetComments.NewComment(addrA3);

            Assert.AreSame(a1, sheetComments.GetCTComment(addrA1));
            Assert.AreSame(a2, sheetComments.GetCTComment(addrA2));
            Assert.AreSame(a3, sheetComments.GetCTComment(addrA3));
            Assert.AreEqual(3, sheetComments.GetNumberOfComments());

            Assert.IsTrue(sheetComments.RemoveComment(addrA1));
            Assert.AreEqual(2, sheetComments.GetNumberOfComments());
            Assert.IsNull(sheetComments.GetCTComment(addrA1));
            Assert.AreSame(a2, sheetComments.GetCTComment(addrA2));
            Assert.AreSame(a3, sheetComments.GetCTComment(addrA3));

            Assert.IsTrue(sheetComments.RemoveComment(addrA2));
            Assert.AreEqual(1, sheetComments.GetNumberOfComments());
            Assert.IsNull(sheetComments.GetCTComment(addrA1));
            Assert.IsNull(sheetComments.GetCTComment(addrA2));
            Assert.AreSame(a3, sheetComments.GetCTComment(addrA3));

            Assert.IsTrue(sheetComments.RemoveComment(addrA3));
            Assert.AreEqual(0, sheetComments.GetNumberOfComments());
            Assert.IsNull(sheetComments.GetCTComment(addrA1));
            Assert.IsNull(sheetComments.GetCTComment(addrA2));
            Assert.IsNull(sheetComments.GetCTComment(addrA3));
        }
Пример #4
0
        public void FindAuthor()
        {
            CommentsTable sheetComments = new CommentsTable();
            Assert.AreEqual(1, sheetComments.GetNumberOfAuthors());
            Assert.AreEqual(0, sheetComments.FindAuthor(""));
            Assert.AreEqual("", sheetComments.GetAuthor(0));

            Assert.AreEqual(1, sheetComments.FindAuthor(TEST_AUTHOR));
            Assert.AreEqual(2, sheetComments.FindAuthor("another author"));
            Assert.AreEqual(1, sheetComments.FindAuthor(TEST_AUTHOR));
            Assert.AreEqual(3, sheetComments.FindAuthor("YAA"));
            Assert.AreEqual(2, sheetComments.FindAuthor("another author"));
        }
Пример #5
0
        public void FindAuthor()
        {
            CommentsTable sheetComments = new CommentsTable();

            Assert.AreEqual(1, sheetComments.GetNumberOfAuthors());
            Assert.AreEqual(0, sheetComments.FindAuthor(""));
            Assert.AreEqual("", sheetComments.GetAuthor(0));

            Assert.AreEqual(1, sheetComments.FindAuthor(TEST_AUTHOR));
            Assert.AreEqual(2, sheetComments.FindAuthor("another author"));
            Assert.AreEqual(1, sheetComments.FindAuthor(TEST_AUTHOR));
            Assert.AreEqual(3, sheetComments.FindAuthor("YAA"));
            Assert.AreEqual(2, sheetComments.FindAuthor("another author"));
        }
Пример #6
0
        public void TestAuthor()
        {
            CommentsTable sheetComments = new CommentsTable();
            CT_Comment ctComment = sheetComments.CreateComment();

            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());
        }
Пример #7
0
        public void TestGetSetCol()
        {
            CommentsTable sheetComments = new CommentsTable();
            XSSFVMLDrawing vml = new XSSFVMLDrawing();
            CT_Comment ctComment = sheetComments.CreateComment();
            CT_Shape vmlShape = vml.newCommentShape();

            XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);
            comment.Column = (1);
            Assert.AreEqual(1, comment.Column);
            Assert.AreEqual(1, new CellReference(ctComment.@ref).Col);
            Assert.AreEqual(1, vmlShape.GetClientDataArray(0).GetColumnArray(0));

            comment.Column = (5);
            Assert.AreEqual(5, comment.Column);
            Assert.AreEqual(5, new CellReference(ctComment.@ref).Col);
            Assert.AreEqual(5, vmlShape.GetClientDataArray(0).GetColumnArray(0));
        }
Пример #8
0
        public void TestConstructor()
        {
            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.CreateComment();
            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);
        }
Пример #9
0
        public void GetCellComment()
        {
            CommentsTable sheetComments = new CommentsTable();

            CT_Comments comments = sheetComments.GetCTComments();
            CT_CommentList commentList = comments.commentList;

            // Create 2 comments for A1 and A" cells
            CT_Comment comment0 = commentList.InsertNewComment(0);
            comment0.@ref = "A1";
            CT_Rst ctrst0 = new CT_Rst();
            ctrst0.t = (TEST_A1_TEXT);
            comment0.text = (ctrst0);
            CT_Comment comment1 = commentList.InsertNewComment(0);
            comment1.@ref = ("A2");
            CT_Rst ctrst1 = new CT_Rst();
            ctrst1.t = (TEST_A2_TEXT);
            comment1.text = (ctrst1);

            // Test Finding the right comment for a cell
            Assert.AreSame(comment0, sheetComments.GetCTComment("A1"));
            Assert.AreSame(comment1, sheetComments.GetCTComment("A2"));
            Assert.IsNull(sheetComments.GetCTComment("A3"));
        }
Пример #10
0
        public void RemoveComment()
        {
            CommentsTable sheetComments = new CommentsTable();
            CT_Comment a1 = sheetComments.NewComment("A1");
            CT_Comment a2 = sheetComments.NewComment("A2");
            CT_Comment a3 = sheetComments.NewComment("A3");

            Assert.AreSame(a1, sheetComments.GetCTComment("A1"));
            Assert.AreSame(a2, sheetComments.GetCTComment("A2"));
            Assert.AreSame(a3, sheetComments.GetCTComment("A3"));
            Assert.AreEqual(3, sheetComments.GetNumberOfComments());

            Assert.IsTrue(sheetComments.RemoveComment("A1"));
            Assert.AreEqual(2, sheetComments.GetNumberOfComments());
            Assert.IsNull(sheetComments.GetCTComment("A1"));
            Assert.AreSame(a2, sheetComments.GetCTComment("A2"));
            Assert.AreSame(a3, sheetComments.GetCTComment("A3"));

            Assert.IsTrue(sheetComments.RemoveComment("A2"));
            Assert.AreEqual(1, sheetComments.GetNumberOfComments());
            Assert.IsNull(sheetComments.GetCTComment("A1"));
            Assert.IsNull(sheetComments.GetCTComment("A2"));
            Assert.AreSame(a3, sheetComments.GetCTComment("A3"));

            Assert.IsTrue(sheetComments.RemoveComment("A3"));
            Assert.AreEqual(0, sheetComments.GetNumberOfComments());
            Assert.IsNull(sheetComments.GetCTComment("A1"));
            Assert.IsNull(sheetComments.GetCTComment("A2"));
            Assert.IsNull(sheetComments.GetCTComment("A3"));
        }
Пример #11
0
 /**
  * Returns the sheet's comments object if there is one,
  *  or null if not
  *
  * @param create create a new comments table if it does not exist
  */
 protected internal CommentsTable GetCommentsTable(bool create)
 {
     if (sheetComments == null && create)
     {
         // Try to create a comments table with the same number as
         //  the sheet has (i.e. sheet 1 -> comments 1)
         try
         {
             sheetComments = (CommentsTable)CreateRelationship(
                   XSSFRelation.SHEET_COMMENTS, XSSFFactory.GetInstance(), (int)sheet.sheetId);
         }
         catch (PartAlreadyExistsException e)
         {
             // Technically a sheet doesn't need the same number as
             //  it's comments, and clearly someone has already pinched
             //  our number! Go for the next available one instead
             sheetComments = (CommentsTable)CreateRelationship(
                   XSSFRelation.SHEET_COMMENTS, XSSFFactory.GetInstance(), -1);
         }
     }
     return sheetComments;
 }
Пример #12
0
        internal virtual void Read(Stream is1)
        {
            //try
            //{
            worksheet = WorksheetDocument.Parse(is1).GetWorksheet();
            //}
            //catch (XmlException e)
            //{
            //    throw new POIXMLException(e);
            //}

            InitRows(worksheet);
            columnHelper = new ColumnHelper(worksheet);

            // Look for bits we're interested in
            foreach (POIXMLDocumentPart p in GetRelations())
            {
                if (p is CommentsTable)
                {
                    sheetComments = (CommentsTable)p;
                    break;
                }
                if (p is XSSFTable)
                {
                    tables[p.GetPackageRelationship().Id] = (XSSFTable)p;
                }
            }

            // Process external hyperlinks for the sheet, if there are any
            InitHyperlinks();
        }
Пример #13
0
 /**
  * Returns the sheet's comments object if there is one,
  *  or null if not
  *
  * @param create create a new comments table if it does not exist
  */
 internal CommentsTable GetCommentsTable(bool Create)
 {
     if (sheetComments == null && Create)
     {
         sheetComments = (CommentsTable)CreateRelationship(XSSFRelation.SHEET_COMMENTS, XSSFFactory.GetInstance(), (int)sheet.sheetId);
     }
     return sheetComments;
 }
Пример #14
0
        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));
        }
Пример #15
0
 /**
  * Creates a new XSSFComment, associated with a given
  *  low level comment object.
  */
 public XSSFComment(CommentsTable comments, CT_Comment comment, CT_Shape vmlShape)
 {
     _comment = comment;
     _comments = comments;
     _vmlShape = vmlShape;
 }