Пример #1
0
        public void TestReadTextBox()
        {
            XSSFWorkbook wb    = XSSFTestDataSamples.OpenSampleWorkbook("WithDrawing.xlsx");
            XSSFSheet    sheet = wb.GetSheetAt(0) as XSSFSheet;
            //the sheet has one relationship and it is XSSFDrawing
            List <RelationPart> rels = sheet.RelationParts;

            Assert.AreEqual(1, rels.Count);
            RelationPart rp = rels[0];

            Assert.IsTrue(rp.DocumentPart is XSSFDrawing);

            XSSFDrawing drawing = (XSSFDrawing)rp.DocumentPart;

            //sheet.CreateDrawingPatriarch() should return the same instance of XSSFDrawing
            Assert.AreSame(drawing, sheet.CreateDrawingPatriarch());
            String drawingId = rp.Relationship.Id;

            //there should be a relation to this Drawing in the worksheet
            Assert.IsTrue(sheet.GetCTWorksheet().IsSetDrawing());
            Assert.AreEqual(drawingId, sheet.GetCTWorksheet().drawing.id);

            List <XSSFShape> shapes = drawing.GetShapes();

            Assert.AreEqual(6, shapes.Count);

            Assert.IsTrue(shapes[0] is XSSFSimpleShape);

            XSSFSimpleShape textbox = (XSSFSimpleShape)shapes[0];

            Assert.AreEqual("Sheet with various pictures\n(jpeg, png, wmf, emf and pict)", textbox.Text);

            checkRewrite(wb);
            wb.Close();
        }
Пример #2
0
        public void TestReadTextBox2()
        {
            XSSFWorkbook     wb        = XSSFTestDataSamples.OpenSampleWorkbook("WithTextBox2.xlsx");
            XSSFSheet        sheet     = wb.GetSheetAt(0) as XSSFSheet;
            XSSFDrawing      drawing   = sheet.CreateDrawingPatriarch() as XSSFDrawing;
            List <XSSFShape> shapes    = drawing.GetShapes();
            XSSFSimpleShape  textbox   = (XSSFSimpleShape)shapes[0];
            String           extracted = textbox.Text;
            StringBuilder    sb        = new StringBuilder();

            sb.Append("1. content1A\n");
            sb.Append("\t1. content1B\n");
            sb.Append("\t2. content2B\n");
            sb.Append("\t3. content3B\n");
            sb.Append("2. content2A\n");
            sb.Append("\t3. content2BStartAt3\n");
            sb.Append("\t\n\t\n\t");
            sb.Append("4. content2BStartAt3Incremented\n");
            sb.Append("\t\n\t\n\t\n\t");

            Assert.AreEqual(sb.ToString(), extracted);

            checkRewrite(wb);
            wb.Close();
        }
Пример #3
0
        public void SetText(XSSFRichTextString str)
        {
            XSSFWorkbook parent = (XSSFWorkbook)this.GetDrawing().GetParent().GetParent();

            str.SetStylesTableReference(parent.GetStylesSource());
            CT_TextParagraph ctTextParagraph = new CT_TextParagraph();

            if (str.NumFormattingRuns == 0)
            {
                CT_RegularTextRun          ctRegularTextRun    = ctTextParagraph.AddNewR();
                CT_TextCharacterProperties characterProperties = ctRegularTextRun.AddNewRPr();
                characterProperties.lang = "en-US";
                characterProperties.sz   = 1100;
                ctRegularTextRun.t       = str.String;
            }
            else
            {
                for (int index = 0; index < str.GetCTRst().sizeOfRArray(); ++index)
                {
                    CT_RElt                    rarray           = str.GetCTRst().GetRArray(index);
                    CT_RPrElt                  pr               = rarray.rPr ?? rarray.AddNewRPr();
                    CT_RegularTextRun          ctRegularTextRun = ctTextParagraph.AddNewR();
                    CT_TextCharacterProperties rPr              = ctRegularTextRun.AddNewRPr();
                    rPr.lang = "en-US";
                    XSSFSimpleShape.ApplyAttributes(pr, rPr);
                    ctRegularTextRun.t = rarray.t;
                }
            }
            this.ctShape.txBody.SetPArray(new CT_TextParagraph[1]
            {
                ctTextParagraph
            });
        }
Пример #4
0
        /**
         *
         * @return list of shapes in this drawing
         */
        public List <XSSFShape> GetShapes()
        {
            List <XSSFShape> lst = new List <XSSFShape>();

            foreach (IEG_Anchor anchor in drawing.CellAnchors)
            {
                XSSFShape shape = null;
                if (anchor.picture != null)
                {
                    shape = new XSSFPicture(this, anchor.picture);
                }
                else if (anchor.connector != null)
                {
                    shape = new XSSFConnector(this, anchor.connector);
                }
                else if (anchor.groupShape != null)
                {
                    shape = new XSSFShapeGroup(this, anchor.groupShape);
                }
                else if (anchor.graphicFrame != null)
                {
                    shape = new XSSFGraphicFrame(this, anchor.graphicFrame);
                }
                else if (anchor.sp != null)
                {
                    shape = new XSSFSimpleShape(this, anchor.sp);
                }
                if (shape != null)
                {
                    shape.anchor = GetAnchorFromIEGAnchor(anchor);
                    lst.Add(shape);
                }
            }
            //foreach (XmlNode obj in xmldoc.SelectNodes("./*/*/*"))
            //{
            //    XSSFShape shape = null;
            //    if (obj.LocalName == "sp")
            //    {
            //        shape = new XSSFSimpleShape(this, obj);
            //    }
            //    else if (obj.LocalName == "pic")
            //    {
            //        shape = new XSSFPicture(this, obj);
            //    }
            //    else if (obj.LocalName == "cxnSp")
            //    {
            //        shape = new XSSFConnector(this, obj);
            //    }
            //    //    else if (obj is CT_GraphicalObjectFrame) shape = new XSSFGraphicFrame(this, (CT_GraphicalObjectFrame)obj);
            //    //    else if (obj is CT_GroupShape) shape = new XSSFShapeGroup(this, (CT_GroupShape)obj);
            //    if (shape != null)
            //    {
            //        shape.anchor = GetAnchorFromParent(obj);
            //        lst.Add(shape);
            //    }
            //}
            return(lst);
        }
Пример #5
0
        public ITextbox CreateTextbox(IClientAnchor anchor)
        {
            long num = this.newShapeId();

            NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_Shape ctShape = this.CreateTwoCellAnchor(anchor).AddNewSp();
            ctShape.Set(XSSFSimpleShape.Prototype());
            ctShape.nvSpPr.cNvPr.id = (uint)num;
            XSSFTextBox xssfTextBox = new XSSFTextBox(this, ctShape);

            xssfTextBox.anchor = (XSSFAnchor)anchor;
            return((ITextbox)xssfTextBox);
        }
Пример #6
0
        public XSSFSimpleShape CreateSimpleShape(XSSFClientAnchor anchor)
        {
            long num = this.newShapeId();

            NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_Shape ctShape = this.CreateTwoCellAnchor((IClientAnchor)anchor).AddNewSp();
            ctShape.Set(XSSFSimpleShape.Prototype());
            ctShape.nvSpPr.cNvPr.id = (uint)num;
            XSSFSimpleShape xssfSimpleShape = new XSSFSimpleShape(this, ctShape);

            xssfSimpleShape.anchor = (XSSFAnchor)anchor;
            return(xssfSimpleShape);
        }
Пример #7
0
        public XSSFSimpleShape CreateSimpleShape(XSSFChildAnchor anchor)
        {
            CT_Shape ctShape = this.ctGroup.AddNewSp();

            ctShape.Set(XSSFSimpleShape.Prototype());
            XSSFSimpleShape xssfSimpleShape = new XSSFSimpleShape(this.GetDrawing(), ctShape);

            xssfSimpleShape.parent = this;
            xssfSimpleShape.anchor = (XSSFAnchor)anchor;
            xssfSimpleShape.GetCTShape().spPr.xfrm = anchor.GetCTTransform2D();
            return(xssfSimpleShape);
        }
Пример #8
0
        /**
         * Creates a simple shape.  This includes such shapes as lines, rectangles,
         * and ovals.
         *
         * @param anchor    the client anchor describes how this group is attached
         *                  to the sheet.
         * @return  the newly Created shape.
         */
        public XSSFSimpleShape CreateSimpleShape(XSSFClientAnchor anchor)
        {
            long             shapeId  = newShapeId();
            CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor);
            CT_Shape         ctShape  = ctAnchor.AddNewSp();

            ctShape.Set(XSSFSimpleShape.Prototype());
            ctShape.nvSpPr.cNvPr.id = (uint)(shapeId);
            XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape);

            shape.anchor = anchor;
            return(shape);
        }
Пример #9
0
        /**
         * Constructs a textbox under the Drawing.
         *
         * @param anchor    the client anchor describes how this group is attached
         *                  to the sheet.
         * @return      the newly Created textbox.
         */
        public ITextbox CreateTextbox(IClientAnchor anchor)
        {
            long             shapeId  = newShapeId();
            CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor);
            CT_Shape         ctShape  = ctAnchor.AddNewSp();

            ctShape.Set(XSSFSimpleShape.Prototype());
            ctShape.nvSpPr.cNvPr.id = (uint)shapeId;
            XSSFTextBox shape = new XSSFTextBox(this, ctShape);

            shape.anchor = (XSSFClientAnchor)anchor;
            return(shape);
        }
Пример #10
0
        /**
         * Constructs a textbox.
         *
         * @param anchor the child anchor describes how this shape is attached
         *               to the group.
         * @return      the newly Created textbox.
         */
        public XSSFTextBox CreateTextbox(XSSFChildAnchor anchor)
        {
            CT_Shape ctShape = ctGroup.AddNewSp();

            ctShape.Set(XSSFSimpleShape.Prototype());

            XSSFTextBox shape = new XSSFTextBox(GetDrawing(), ctShape);

            shape.parent = this;
            shape.anchor = anchor;
            shape.GetCTShape().spPr.xfrm = (anchor.GetCTTransform2D());
            return(shape);
        }
Пример #11
0
        public void TestNew()
        {
            XSSFWorkbook wb    = new XSSFWorkbook();
            XSSFSheet    sheet = (XSSFSheet)wb.CreateSheet();
            //multiple calls of CreateDrawingPatriarch should return the same instance of XSSFDrawing
            XSSFDrawing dr1 = (XSSFDrawing)sheet.CreateDrawingPatriarch();
            XSSFDrawing dr2 = (XSSFDrawing)sheet.CreateDrawingPatriarch();

            Assert.AreSame(dr1, dr2);

            List <POIXMLDocumentPart> rels = sheet.GetRelations();

            Assert.AreEqual(1, rels.Count);
            Assert.IsTrue(rels[0] is XSSFDrawing);

            XSSFDrawing drawing   = (XSSFDrawing)rels[0];
            String      drawingId = drawing.GetPackageRelationship().Id;

            //there should be a relation to this Drawing in the worksheet
            Assert.IsTrue(sheet.GetCTWorksheet().IsSetDrawing());
            Assert.AreEqual(drawingId, sheet.GetCTWorksheet().drawing.id);

            XSSFClientAnchor anchor = new XSSFClientAnchor();

            XSSFConnector c1 = drawing.CreateConnector(anchor);

            c1.LineWidth = 3;
            c1.LineStyle = SS.UserModel.LineStyle.DashDotSys;

            XSSFShapeGroup c2 = drawing.CreateGroup(anchor);

            XSSFSimpleShape c3 = drawing.CreateSimpleShape(anchor);

            c3.SetText(new XSSFRichTextString("Test String"));
            c3.SetFillColor(128, 128, 128);

            XSSFTextBox        c4 = (XSSFTextBox)drawing.CreateTextbox(anchor);
            XSSFRichTextString rt = new XSSFRichTextString("Test String");

            rt.ApplyFont(0, 5, wb.CreateFont());
            rt.ApplyFont(5, 6, wb.CreateFont());
            c4.SetText(rt);

            c4.IsNoFill = (true);
        }
Пример #12
0
        public void TestReadTextBoxParagraphs()
        {
            XSSFWorkbook wb    = XSSFTestDataSamples.OpenSampleWorkbook("WithTextBox.xlsx");
            XSSFSheet    sheet = wb.GetSheetAt(0) as XSSFSheet;
            //the sheet has one relationship and it is XSSFDrawing
            List <RelationPart> rels = sheet.RelationParts;

            Assert.AreEqual(1, rels.Count);
            RelationPart rp = rels[0];

            Assert.IsTrue(rp.DocumentPart is XSSFDrawing);

            XSSFDrawing drawing = (XSSFDrawing)rp.DocumentPart;

            //sheet.CreateDrawingPatriarch() should return the same instance of XSSFDrawing
            Assert.AreSame(drawing, sheet.CreateDrawingPatriarch());
            String drawingId = rp.Relationship.Id;

            //there should be a relation to this Drawing in the worksheet
            Assert.IsTrue(sheet.GetCTWorksheet().IsSetDrawing());
            Assert.AreEqual(drawingId, sheet.GetCTWorksheet().drawing.id);

            List <XSSFShape> shapes = drawing.GetShapes();

            Assert.AreEqual(1, shapes.Count);

            Assert.IsTrue(shapes[0] is XSSFSimpleShape);

            XSSFSimpleShape textbox = (XSSFSimpleShape)shapes[0];

            List <XSSFTextParagraph> paras = textbox.TextParagraphs;

            Assert.AreEqual(3, paras.Count);

            Assert.AreEqual("Line 2", paras[1].Text);                // check content of second paragraph

            Assert.AreEqual("Line 1\nLine 2\nLine 3", textbox.Text); // check content of entire textbox

            // check attributes of paragraphs
            Assert.AreEqual(TextAlign.LEFT, paras[0].TextAlign);
            Assert.AreEqual(TextAlign.CENTER, paras[1].TextAlign);
            Assert.AreEqual(TextAlign.RIGHT, paras[2].TextAlign);

            Color clr = paras[0].TextRuns[0].FontColor;

            Assert.IsTrue(Arrays.Equals(
                              new int[] { 255, 0, 0 },
                              new int[] { clr.R, clr.G, clr.B }));

            clr = paras[1].TextRuns[0].FontColor;
            Assert.IsTrue(Arrays.Equals(
                              new int[] { 0, 255, 0 },
                              new int[] { clr.R, clr.G, clr.B }));

            clr = paras[2].TextRuns[0].FontColor;
            Assert.IsTrue(Arrays.Equals(
                              new int[] { 0, 0, 255 },
                              new int[] { clr.R, clr.G, clr.B }));

            checkRewrite(wb);
            wb.Close();
        }
Пример #13
0
        public void TestNew()
        {
            XSSFWorkbook wb    = new XSSFWorkbook();
            XSSFSheet    sheet = (XSSFSheet)wb.CreateSheet();
            //multiple calls of CreateDrawingPatriarch should return the same instance of XSSFDrawing
            XSSFDrawing dr1 = (XSSFDrawing)sheet.CreateDrawingPatriarch();
            XSSFDrawing dr2 = (XSSFDrawing)sheet.CreateDrawingPatriarch();

            Assert.AreSame(dr1, dr2);

            List <POIXMLDocumentPart> rels = sheet.GetRelations();

            Assert.AreEqual(1, rels.Count);
            Assert.IsTrue(rels[0] is XSSFDrawing);

            XSSFDrawing drawing   = (XSSFDrawing)rels[0];
            String      drawingId = drawing.GetPackageRelationship().Id;

            //there should be a relation to this Drawing in the worksheet
            Assert.IsTrue(sheet.GetCTWorksheet().IsSetDrawing());
            Assert.AreEqual(drawingId, sheet.GetCTWorksheet().drawing.id);

            //XSSFClientAnchor anchor = new XSSFClientAnchor();

            XSSFConnector c1 = drawing.CreateConnector(new XSSFClientAnchor(0, 0, 0, 0, 0, 0, 2, 2));

            c1.LineWidth = 2.5;
            c1.LineStyle = SS.UserModel.LineStyle.DashDotSys;

            XSSFShapeGroup c2 = drawing.CreateGroup(new XSSFClientAnchor(0, 0, 0, 0, 0, 0, 5, 5));

            Assert.IsNotNull(c2);

            XSSFSimpleShape c3 = drawing.CreateSimpleShape(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));

            c3.SetText(new XSSFRichTextString("Test String"));
            c3.SetFillColor(128, 128, 128);

            XSSFTextBox        c4 = (XSSFTextBox)drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 4, 4, 5, 6));
            XSSFRichTextString rt = new XSSFRichTextString("Test String");

            rt.ApplyFont(0, 5, wb.CreateFont());
            rt.ApplyFont(5, 6, wb.CreateFont());
            c4.SetText(rt);

            c4.IsNoFill = (true);

            Assert.AreEqual(4, drawing.GetCTDrawing().SizeOfTwoCellAnchorArray());

            List <XSSFShape> shapes = drawing.GetShapes();

            Assert.AreEqual(4, shapes.Count);
            Assert.IsTrue(shapes[(0)] is XSSFConnector);
            Assert.IsTrue(shapes[(1)] is XSSFShapeGroup);
            Assert.IsTrue(shapes[(2)] is XSSFSimpleShape);
            Assert.IsTrue(shapes[(3)] is XSSFSimpleShape);

            // Save and re-load it
            wb    = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook;
            sheet = wb.GetSheetAt(0) as XSSFSheet;

            // Check
            dr1 = sheet.CreateDrawingPatriarch() as XSSFDrawing;
            CT_Drawing ctDrawing = dr1.GetCTDrawing();

            // Connector, shapes and text boxes are all two cell anchors
            Assert.AreEqual(0, ctDrawing.SizeOfAbsoluteAnchorArray());
            Assert.AreEqual(0, ctDrawing.SizeOfOneCellAnchorArray());
            Assert.AreEqual(4, ctDrawing.SizeOfTwoCellAnchorArray());

            shapes = dr1.GetShapes();
            Assert.AreEqual(4, shapes.Count);
            Assert.IsTrue(shapes[0] is XSSFConnector);
            Assert.IsTrue(shapes[1] is XSSFShapeGroup);
            Assert.IsTrue(shapes[2] is XSSFSimpleShape);
            Assert.IsTrue(shapes[3] is XSSFSimpleShape); //

            // Ensure it got the right namespaces
            //String xml = ctDrawing.ToString();
            //Assert.IsTrue(xml.Contains("xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\""));
            //Assert.IsTrue(xml.Contains("xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\""));

            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb));
        }
Пример #14
0
        /**
         * Creates a simple shape.  This includes such shapes as lines, rectangles,
         * and ovals.
         *
         * @param anchor the child anchor describes how this shape is attached
         *               to the group.
         * @return the newly Created shape.
         */
        public XSSFSimpleShape CreateSimpleShape(XSSFChildAnchor anchor)
        {
            CT_Shape ctShape = ctGroup.AddNewSp();
            ctShape.Set(XSSFSimpleShape.Prototype());

            XSSFSimpleShape shape = new XSSFSimpleShape(GetDrawing(), ctShape);
            shape.parent = (this);
            shape.anchor = anchor;
            shape.GetCTShape().spPr.xfrm = (anchor.GetCTTransform2D());
            return shape;
        }
Пример #15
0
        public void TestXSSFTextParagraph()
        {
            XSSFWorkbook wb = new XSSFWorkbook();

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

                XSSFTextBox shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)) as XSSFTextBox;

                XSSFRichTextString rt = new XSSFRichTextString("Test String");

                XSSFFont font  = wb.CreateFont() as XSSFFont;
                Color    color = Color.FromArgb(0, 255, 255);
                font.SetColor(new XSSFColor(color));
                font.FontName = (/*setter*/ "Arial");
                rt.ApplyFont(font);

                shape.SetText(/*setter*/ rt);

                Assert.IsNotNull(shape.GetCTShape());
                Assert.IsNotNull(shape.GetEnumerator());
                Assert.IsNotNull(XSSFSimpleShape.GetPrototype());

                foreach (ListAutoNumber nr in Enum.GetValues(typeof(ListAutoNumber)))
                {
                    shape.TextParagraphs[(0)].SetBullet(nr);
                    Assert.IsNotNull(shape.Text);
                }

                shape.TextParagraphs[(0)].SetBullet(false);
                Assert.IsNotNull(shape.Text);

                shape.SetText("testtext");
                Assert.AreEqual("testtext", shape.Text);

                shape.SetText(new XSSFRichTextString());
                Assert.AreEqual("null", shape.Text);

                shape.AddNewTextParagraph();
                shape.AddNewTextParagraph("test-other-text");
                shape.AddNewTextParagraph(new XSSFRichTextString("rtstring"));
                shape.AddNewTextParagraph(new XSSFRichTextString());
                Assert.AreEqual("null\n\ntest-other-text\nrtstring\nnull", shape.Text);

                Assert.AreEqual(TextHorizontalOverflow.OVERFLOW, shape.TextHorizontalOverflow);
                shape.TextHorizontalOverflow = (/*setter*/ TextHorizontalOverflow.CLIP);
                Assert.AreEqual(TextHorizontalOverflow.CLIP, shape.TextHorizontalOverflow);
                shape.TextHorizontalOverflow = (/*setter*/ TextHorizontalOverflow.OVERFLOW);
                Assert.AreEqual(TextHorizontalOverflow.OVERFLOW, shape.TextHorizontalOverflow);
                shape.TextHorizontalOverflow = TextHorizontalOverflow.None;
                Assert.AreEqual(TextHorizontalOverflow.OVERFLOW, shape.TextHorizontalOverflow);
                shape.TextHorizontalOverflow = TextHorizontalOverflow.None;
                Assert.AreEqual(TextHorizontalOverflow.OVERFLOW, shape.TextHorizontalOverflow);

                Assert.AreEqual(TextVerticalOverflow.OVERFLOW, shape.TextVerticalOverflow);
                shape.TextVerticalOverflow = (/*setter*/ TextVerticalOverflow.CLIP);
                Assert.AreEqual(TextVerticalOverflow.CLIP, shape.TextVerticalOverflow);
                shape.TextVerticalOverflow = (/*setter*/ TextVerticalOverflow.OVERFLOW);
                Assert.AreEqual(TextVerticalOverflow.OVERFLOW, shape.TextVerticalOverflow);
                shape.TextVerticalOverflow = TextVerticalOverflow.None;
                Assert.AreEqual(TextVerticalOverflow.OVERFLOW, shape.TextVerticalOverflow);
                shape.TextVerticalOverflow = TextVerticalOverflow.None;
                Assert.AreEqual(TextVerticalOverflow.OVERFLOW, shape.TextVerticalOverflow);

                Assert.AreEqual((short)VerticalAlignment.Top, shape.VerticalAlignment);
                shape.VerticalAlignment = (short)VerticalAlignment.Bottom;
                Assert.AreEqual(VerticalAlignment.Bottom, shape.VerticalAlignment);
                shape.VerticalAlignment = (short)VerticalAlignment.Top;
                Assert.AreEqual(VerticalAlignment.Top, shape.VerticalAlignment);
                shape.VerticalAlignment = (short)VerticalAlignment.None;
                Assert.AreEqual(VerticalAlignment.Top, shape.VerticalAlignment);
                shape.VerticalAlignment = (short)VerticalAlignment.None;
                Assert.AreEqual(VerticalAlignment.Top, shape.VerticalAlignment);

                Assert.AreEqual(TextDirection.HORIZONTAL, shape.TextDirection);
                shape.TextDirection = (/*setter*/ TextDirection.STACKED);
                Assert.AreEqual(TextDirection.STACKED, shape.TextDirection);
                shape.TextDirection = (/*setter*/ TextDirection.HORIZONTAL);
                Assert.AreEqual(TextDirection.HORIZONTAL, shape.TextDirection);
                shape.TextDirection = (/*setter*/ TextDirection.None);
                Assert.AreEqual(TextDirection.HORIZONTAL, shape.TextDirection);
                shape.TextDirection = (/*setter*/ TextDirection.None);
                Assert.AreEqual(TextDirection.HORIZONTAL, shape.TextDirection);

                Assert.AreEqual(3.6, shape.BottomInset, 0.01);
                shape.BottomInset = (/*setter*/ 12.32);
                Assert.AreEqual(12.32, shape.BottomInset, 0.01);
                shape.BottomInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.BottomInset, 0.01);
                shape.BottomInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.BottomInset, 0.01);

                Assert.AreEqual(3.6, shape.LeftInset, 0.01);
                shape.LeftInset = (/*setter*/ 12.31);
                Assert.AreEqual(12.31, shape.LeftInset, 0.01);
                shape.LeftInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.LeftInset, 0.01);
                shape.LeftInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.LeftInset, 0.01);

                Assert.AreEqual(3.6, shape.RightInset, 0.01);
                shape.RightInset = (/*setter*/ 13.31);
                Assert.AreEqual(13.31, shape.RightInset, 0.01);
                shape.RightInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.RightInset, 0.01);
                shape.RightInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.RightInset, 0.01);

                Assert.AreEqual(3.6, shape.TopInset, 0.01);
                shape.TopInset = (/*setter*/ 23.31);
                Assert.AreEqual(23.31, shape.TopInset, 0.01);
                shape.TopInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.TopInset, 0.01);
                shape.TopInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.TopInset, 0.01);

                Assert.IsTrue(shape.WordWrap);
                shape.WordWrap = (/*setter*/ false);
                Assert.IsFalse(shape.WordWrap);
                shape.WordWrap = (/*setter*/ true);
                Assert.IsTrue(shape.WordWrap);

                Assert.AreEqual(TextAutofit.NORMAL, shape.TextAutofit);
                shape.TextAutofit = (/*setter*/ TextAutofit.NORMAL);
                Assert.AreEqual(TextAutofit.NORMAL, shape.TextAutofit);
                shape.TextAutofit = (/*setter*/ TextAutofit.SHAPE);
                Assert.AreEqual(TextAutofit.SHAPE, shape.TextAutofit);
                shape.TextAutofit = (/*setter*/ TextAutofit.NONE);
                Assert.AreEqual(TextAutofit.NONE, shape.TextAutofit);

                Assert.AreEqual(5, shape.ShapeType);
                shape.ShapeType = (/*setter*/ 23);
                Assert.AreEqual(23, shape.ShapeType);

                // TODO: should this be supported?
                //            shape.ShapeType=(/*setter*/-1);
                //            Assert.AreEqual(-1, shape.ShapeType);
                //            shape.ShapeType=(/*setter*/-1);
                //            Assert.AreEqual(-1, shape.ShapeType);

                Assert.IsNotNull(shape.GetShapeProperties());
            }
            finally
            {
                wb.Close();
            }
        }
Пример #16
0
 /**
  * Creates a simple shape.  This includes such shapes as lines, rectangles,
  * and ovals.
  *
  * @param anchor    the client anchor describes how this group is attached
  *                  to the sheet.
  * @return  the newly Created shape.
  */
 public XSSFSimpleShape CreateSimpleShape(XSSFClientAnchor anchor)
 {
     long shapeId = newShapeId();
     CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor);
     CT_Shape ctShape = ctAnchor.AddNewSp();
     ctShape.Set(XSSFSimpleShape.Prototype());
     ctShape.nvSpPr.cNvPr.id=(uint)(shapeId);
     XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape);
     shape.anchor = anchor;
     return shape;
 }
Пример #17
0
        public void TestAddNewTextParagraphWithRTS()
        {
            XSSFWorkbook wb1     = new XSSFWorkbook();
            XSSFSheet    sheet   = wb1.CreateSheet() as XSSFSheet;
            XSSFDrawing  Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            XSSFTextBox        shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
            XSSFRichTextString rt    = new XSSFRichTextString("Test Rich Text String");

            XSSFFont font = wb1.CreateFont() as XSSFFont;

            font.SetColor(new XSSFColor(Color.FromArgb(0, 255, 255)));
            font.FontName = ("Arial");
            rt.ApplyFont(font);

            XSSFFont midfont = wb1.CreateFont() as XSSFFont;

            midfont.SetColor(new XSSFColor(Color.FromArgb(0, 255, 0)));
            rt.ApplyFont(5, 14, midfont);       // Set the text "Rich Text" to be green and the default font

            XSSFTextParagraph para = shape.AddNewTextParagraph(rt);

            // Save and re-load it
            XSSFWorkbook wb2 = XSSFTestDataSamples.WriteOutAndReadBack(wb1) as XSSFWorkbook;

            wb1.Close();
            sheet = wb2.GetSheetAt(0) as XSSFSheet;

            // Check
            Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            List <XSSFShape> shapes = Drawing.GetShapes();

            Assert.AreEqual(1, shapes.Count);
            Assert.IsTrue(shapes[0] is XSSFSimpleShape);

            XSSFSimpleShape sshape = (XSSFSimpleShape)shapes[0];

            List <XSSFTextParagraph> paras = sshape.TextParagraphs;

            Assert.AreEqual(2, paras.Count);    // this should be 2 as XSSFSimpleShape Creates a default paragraph (no text), and then we add a string to that.

            List <XSSFTextRun> runs = para.TextRuns;

            Assert.AreEqual(3, runs.Count);

            // first run properties
            Assert.AreEqual("Test ", runs[0].Text);
            Assert.AreEqual("Arial", runs[0].FontFamily);

            Color clr = runs[0].FontColor;

            Assert.IsTrue(Arrays.Equals(
                              new int[] { 0, 255, 255 },
                              new int[] { clr.R, clr.G, clr.B }));

            // second run properties
            Assert.AreEqual("Rich Text", runs[1].Text);
            Assert.AreEqual(XSSFFont.DEFAULT_FONT_NAME, runs[1].FontFamily);

            clr = runs[1].FontColor;
            Assert.IsTrue(Arrays.Equals(
                              new int[] { 0, 255, 0 },
                              new int[] { clr.R, clr.G, clr.B }));

            // third run properties
            Assert.AreEqual(" String", runs[2].Text);
            Assert.AreEqual("Arial", runs[2].FontFamily);
            clr = runs[2].FontColor;
            Assert.IsTrue(Arrays.Equals(
                              new int[] { 0, 255, 255 },
                              new int[] { clr.R, clr.G, clr.B }));

            checkRewrite(wb2);
            wb2.Close();
        }
Пример #18
0
    /**
 *
 * @return list of shapes in this drawing
 */
    public List<XSSFShape> GetShapes()
    {
        List<XSSFShape> lst = new List<XSSFShape>();
        foreach (IEG_Anchor anchor in drawing.CellAnchors)
        {
            XSSFShape shape = null;
            if (anchor.picture != null)
            {
                shape = new XSSFPicture(this, anchor.picture);
            }
            else if (anchor.connector != null)
            {
                shape = new XSSFConnector(this, anchor.connector);
            }
            else if (anchor.groupShape != null)
            {
                shape = new XSSFShapeGroup(this, anchor.groupShape);
            }
            else if (anchor.graphicFrame != null)
            {
                shape = new XSSFGraphicFrame(this, anchor.graphicFrame);
            }
            else if (anchor.sp != null)
            {
               shape = new XSSFSimpleShape(this, anchor.sp);
            }
            if (shape != null)
            {
                shape.anchor = GetAnchorFromIEGAnchor(anchor);
                lst.Add(shape);
            }
        }
        //foreach (XmlNode obj in xmldoc.SelectNodes("./*/*/*"))
        //{
        //    XSSFShape shape = null;
        //    if (obj.LocalName == "sp")
        //    {
        //        shape = new XSSFSimpleShape(this, obj);
        //    }
        //    else if (obj.LocalName == "pic")
        //    {
        //        shape = new XSSFPicture(this, obj);
        //    }
        //    else if (obj.LocalName == "cxnSp")
        //    {
        //        shape = new XSSFConnector(this, obj);
        //    }
        //    //    else if (obj is CT_GraphicalObjectFrame) shape = new XSSFGraphicFrame(this, (CT_GraphicalObjectFrame)obj);
        //    //    else if (obj is CT_GroupShape) shape = new XSSFShapeGroup(this, (CT_GroupShape)obj);
        //    if (shape != null)
        //    {
        //        shape.anchor = GetAnchorFromParent(obj);
        //        lst.Add(shape);
        //    }
        //}
        return lst;
    }
Пример #19
0
        public void TestAddBulletParagraphs()
        {
            XSSFWorkbook wb1     = new XSSFWorkbook();
            XSSFSheet    sheet   = wb1.CreateSheet() as XSSFSheet;
            XSSFDrawing  drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            XSSFTextBox shape = drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 10, 20));

            String paraString1  = "A normal paragraph";
            String paraString2  = "First bullet";
            String paraString3  = "Second bullet (level 1)";
            String paraString4  = "Third bullet";
            String paraString5  = "Another normal paragraph";
            String paraString6  = "First numbered bullet";
            String paraString7  = "Second bullet (level 1)";
            String paraString8  = "Third bullet (level 1)";
            String paraString9  = "Fourth bullet (level 1)";
            String paraString10 = "Fifth Bullet";

            XSSFTextParagraph para = shape.AddNewTextParagraph(paraString1);

            para = shape.AddNewTextParagraph(paraString2);
            para.SetBullet(true);

            para = shape.AddNewTextParagraph(paraString3);
            para.SetBullet(true);
            para.Level = (1);

            para = shape.AddNewTextParagraph(paraString4);
            para.SetBullet(true);

            para = shape.AddNewTextParagraph(paraString5);
            para = shape.AddNewTextParagraph(paraString6);
            para.SetBullet(ListAutoNumber.ARABIC_PERIOD);

            para = shape.AddNewTextParagraph(paraString7);
            para.SetBullet(ListAutoNumber.ARABIC_PERIOD, 3);
            para.Level = (1);

            para = shape.AddNewTextParagraph(paraString8);
            para.SetBullet(ListAutoNumber.ARABIC_PERIOD, 3);
            para.Level = (1);

            para = shape.AddNewTextParagraph("");
            para.SetBullet(ListAutoNumber.ARABIC_PERIOD, 3);
            para.Level = (1);

            para = shape.AddNewTextParagraph(paraString9);
            para.SetBullet(ListAutoNumber.ARABIC_PERIOD, 3);
            para.Level = (1);

            para = shape.AddNewTextParagraph(paraString10);
            para.SetBullet(ListAutoNumber.ARABIC_PERIOD);

            // Save and re-load it
            XSSFWorkbook wb2 = XSSFTestDataSamples.WriteOutAndReadBack(wb1);

            sheet = wb2.GetSheetAt(0) as XSSFSheet;

            // Check
            drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            List <XSSFShape> shapes = drawing.GetShapes();

            Assert.AreEqual(1, shapes.Count);
            Assert.IsTrue(shapes[0] is XSSFSimpleShape);

            XSSFSimpleShape sshape = (XSSFSimpleShape)shapes[0];

            List <XSSFTextParagraph> paras = sshape.TextParagraphs;

            Assert.AreEqual(12, paras.Count);  // this should be 12 as XSSFSimpleShape Creates a default paragraph (no text), and then we Added to that

            StringBuilder builder = new StringBuilder();

            builder.Append(paraString1);
            builder.Append("\n");
            builder.Append("\u2022 ");
            builder.Append(paraString2);
            builder.Append("\n");
            builder.Append("\t\u2022 ");
            builder.Append(paraString3);
            builder.Append("\n");
            builder.Append("\u2022 ");
            builder.Append(paraString4);
            builder.Append("\n");
            builder.Append(paraString5);
            builder.Append("\n");
            builder.Append("1. ");
            builder.Append(paraString6);
            builder.Append("\n");
            builder.Append("\t3. ");
            builder.Append(paraString7);
            builder.Append("\n");
            builder.Append("\t4. ");
            builder.Append(paraString8);
            builder.Append("\n");
            builder.Append("\t");   // should be empty
            builder.Append("\n");
            builder.Append("\t5. ");
            builder.Append(paraString9);
            builder.Append("\n");
            builder.Append("2. ");
            builder.Append(paraString10);

            Assert.AreEqual(builder.ToString(), sshape.Text);

            checkRewrite(wb2);
            wb2.Close();
        }