示例#1
0
        /**
         * Creates a comment.
         * @param anchor the client anchor describes how this comment is attached
         *               to the sheet.
         * @return the newly Created comment.
         */
        public IComment CreateCellComment(IClientAnchor anchor)
        {
            XSSFClientAnchor ca    = (XSSFClientAnchor)anchor;
            XSSFSheet        sheet = (XSSFSheet)GetParent();

            //create comments and vmlDrawing parts if they don't exist
            CommentsTable  comments = sheet.GetCommentsTable(true);
            XSSFVMLDrawing vml      = sheet.GetVMLDrawing(true);

            NPOI.OpenXmlFormats.Vml.CT_Shape vmlShape = vml.newCommentShape();
            if (ca.IsSet())
            {
                // convert offsets from emus to pixels since we get a DrawingML-anchor
                // but create a VML Drawing
                int    dx1Pixels = ca.Dx1 / Units.EMU_PER_PIXEL;
                int    dy1Pixels = ca.Dy1 / Units.EMU_PER_PIXEL;
                int    dx2Pixels = ca.Dx2 / Units.EMU_PER_PIXEL;
                int    dy2Pixels = ca.Dy2 / Units.EMU_PER_PIXEL;
                String position  =
                    ca.Col1 + ", " + dx1Pixels + ", " +
                    ca.Row1 + ", " + dy1Pixels + ", " +
                    ca.Col2 + ", " + dx2Pixels + ", " +
                    ca.Row2 + ", " + dy2Pixels;
                vmlShape.GetClientDataArray(0).SetAnchorArray(0, position);
            }
            String ref1 = new CellReference(ca.Row1, ca.Col1).FormatAsString();

            if (comments.FindCellComment(ref1) != null)
            {
                throw new ArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref1);
            }

            return(new XSSFComment(comments, comments.NewComment(ref1), vmlShape));
        }
示例#2
0
        public IComment CreateCellComment(IClientAnchor anchor)
        {
            XSSFClientAnchor xssfClientAnchor = (XSSFClientAnchor)anchor;
            XSSFSheet        parent           = (XSSFSheet)this.GetParent();
            CommentsTable    commentsTable    = parent.GetCommentsTable(true);

            NPOI.OpenXmlFormats.Vml.CT_Shape vmlShape = parent.GetVMLDrawing(true).newCommentShape();
            if (xssfClientAnchor.IsSet())
            {
                string str = xssfClientAnchor.Col1.ToString() + ", 0, " + (object)xssfClientAnchor.Row1 + ", 0, " + (object)xssfClientAnchor.Col2 + ", 0, " + (object)xssfClientAnchor.Row2 + ", 0";
                vmlShape.GetClientDataArray(0).SetAnchorArray(0, str);
            }
            return((IComment) new XSSFComment(commentsTable, commentsTable.CreateComment(), vmlShape)
            {
                Column = xssfClientAnchor.Col1, Row = xssfClientAnchor.Row1
            });
        }
示例#3
0
        /**
         * Creates a comment.
         * @param anchor the client anchor describes how this comment is attached
         *               to the sheet.
         * @return the newly Created comment.
         */
        public IComment CreateCellComment(IClientAnchor anchor)
        {
            XSSFClientAnchor ca    = (XSSFClientAnchor)anchor;
            XSSFSheet        sheet = (XSSFSheet)GetParent();

            //create comments and vmlDrawing parts if they don't exist
            CommentsTable  comments = sheet.GetCommentsTable(true);
            XSSFVMLDrawing vml      = sheet.GetVMLDrawing(true);

            NPOI.OpenXmlFormats.Vml.CT_Shape vmlShape = vml.newCommentShape();
            if (ca.IsSet())
            {
                String position =
                    ca.Col1 + ", 0, " + ca.Row1 + ", 0, " +
                    ca.Col2 + ", 0, " + ca.Row2 + ", 0";
                vmlShape.GetClientDataArray(0).SetAnchorArray(0, position);
            }
            String      ref1  = new CellReference(ca.Row1, ca.Col1).FormatAsString();
            XSSFComment shape = new XSSFComment(comments, comments.NewComment(ref1), vmlShape);

            return(shape);
        }
示例#4
0
        public void TestBug58175()
        {
            IWorkbook wb = new SXSSFWorkbook();

            try
            {
                ISheet sheet = wb.CreateSheet();
                IRow   row   = sheet.CreateRow(1);
                ICell  cell  = row.CreateCell(3);
                cell.SetCellValue("F4");
                ICreationHelper factory = wb.GetCreationHelper();
                // When the comment box is visible, have it show in a 1x3 space
                IClientAnchor anchor = factory.CreateClientAnchor();
                anchor.Col1 = (cell.ColumnIndex);
                anchor.Col2 = (cell.ColumnIndex + 1);
                anchor.Row1 = (row.RowNum);
                anchor.Row2 = (row.RowNum + 3);
                XSSFClientAnchor ca = (XSSFClientAnchor)anchor;
                // create comments and vmlDrawing parts if they don't exist
                CommentsTable comments = (((SXSSFWorkbook)wb).XssfWorkbook
                                          .GetSheetAt(0) as XSSFSheet).GetCommentsTable(true);
                XSSFVMLDrawing vml = (((SXSSFWorkbook)wb).XssfWorkbook
                                      .GetSheetAt(0) as XSSFSheet).GetVMLDrawing(true);
                CT_Shape vmlShape1 = vml.newCommentShape();
                if (ca.IsSet())
                {
                    String position = ca.Col1 + ", 0, " + ca.Row1
                                      + ", 0, " + ca.Col2 + ", 0, " + ca.Row2
                                      + ", 0";
                    vmlShape1.GetClientDataArray(0).SetAnchorArray(0, position);
                }
                // create the comment in two different ways and verify that there is no difference

                XSSFComment shape1 = new XSSFComment(comments, comments.NewComment(CellAddress.A1), vmlShape1);
                shape1.Column = (ca.Col1);
                shape1.Row    = (ca.Row1);
                CT_Shape vmlShape2 = vml.newCommentShape();
                if (ca.IsSet())
                {
                    String position = ca.Col1 + ", 0, " + ca.Row1
                                      + ", 0, " + ca.Col2 + ", 0, " + ca.Row2
                                      + ", 0";
                    vmlShape2.GetClientDataArray(0).SetAnchorArray(0, position);
                }

                CellAddress ref1   = new CellAddress(ca.Row1, ca.Col1);
                XSSFComment shape2 = new XSSFComment(comments, comments.NewComment(ref1), vmlShape2);

                Assert.AreEqual(shape1.Author, shape2.Author);
                Assert.AreEqual(shape1.ClientAnchor, shape2.ClientAnchor);
                Assert.AreEqual(shape1.Column, shape2.Column);
                Assert.AreEqual(shape1.Row, shape2.Row);
                Assert.AreEqual(shape1.GetCTComment().ToString(), shape2.GetCTComment().ToString());
                Assert.AreEqual(shape1.GetCTComment().@ref, shape2.GetCTComment().@ref);

                /*CommentsTable table1 = shape1.CommentsTable;
                 * CommentsTable table2 = shape2.CommentsTable;
                 * Assert.AreEqual(table1.CTComments.toString(), table2.CTComments.toString());
                 * Assert.AreEqual(table1.NumberOfComments, table2.NumberOfComments);
                 * Assert.AreEqual(table1.Relations, table2.Relations);*/

                Assert.AreEqual(vmlShape1.ToString().Replace("_x0000_s\\d+", "_x0000_s0000"),
                                vmlShape2.ToString().Replace("_x0000_s\\d+", "_x0000_s0000"),
                                "The vmlShapes should have equal content afterwards");
            }
            finally
            {
                wb.Close();
            }
        }