Beispiel #1
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            Presentation pres  = new Presentation(dataDir + "ConnectorLineAngle.pptx");
            Slide        slide = (Slide)pres.Slides[0];
            Shape        shape;

            for (int i = 0; i < slide.Shapes.Count; i++)
            {
                double dir = 0.0;
                shape = (Shape)slide.Shapes[i];
                if (shape is AutoShape)
                {
                    AutoShape ashp = (AutoShape)shape;
                    if (ashp.ShapeType == ShapeType.Line)
                    {
                        dir = getDirection(ashp.Width, ashp.Height, Convert.ToBoolean(ashp.Frame.FlipH), Convert.ToBoolean(ashp.Frame.FlipV));
                    }
                }
                else if (shape is Connector)
                {
                    Connector ashp = (Connector)shape;
                    dir = getDirection(ashp.Width, ashp.Height, Convert.ToBoolean(ashp.Frame.FlipH), Convert.ToBoolean(ashp.Frame.FlipV));
                }

                Console.WriteLine(dir);
            }
        }
Beispiel #2
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Instantiate Presentation class that represents the PPTX
            Presentation pres = new Presentation();

            // Get the first slide
            ISlide sld = pres.Slides[0];

            // Add autoshape of rectangle type
            IShape shp1 = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 40, 150, 50);
            IShape shp2 = sld.Shapes.AddAutoShape(ShapeType.Moon, 160, 40, 150, 50);

            shp2.FillFormat.FillType             = FillType.Solid;
            shp2.FillFormat.SolidFillColor.Color = Color.Gray;

            for (int i = 0; i < sld.Shapes.Count; i++)
            {
                var shape = sld.Shapes[i] as AutoShape;
                if (shape != null)
                {
                    AutoShape ashp = shape;
                    ashp.AlternativeText = "User Defined";
                }
            }

            // Save presentation to disk
            pres.Save(dataDir + "Set_AlternativeText_out.pptx", SaveFormat.Pptx);
        }
        public static void Run()
        {
            //ExStart:Hidingshapes
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Instantiate Presentation class that represents the PPTX
            Presentation pres = new Presentation();

            // Get the first slide
            ISlide sld = pres.Slides[0];

            // Add autoshape of rectangle type
            IShape shp1    = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 40, 150, 50);
            IShape shp2    = sld.Shapes.AddAutoShape(ShapeType.Moon, 160, 40, 150, 50);
            String alttext = "User Defined";
            int    iCount  = sld.Shapes.Count;

            for (int i = 0; i < iCount; i++)
            {
                AutoShape ashp = (AutoShape)sld.Shapes[i];
                if (String.Compare(ashp.AlternativeText, alttext, StringComparison.Ordinal) == 0)
                {
                    ashp.Hidden = true;
                }
            }

            // Save presentation to disk
            pres.Save(dataDir + "Hiding_Shapes_out.pptx", SaveFormat.Pptx);
            //ExEnd:Hidingshapes
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Create Presentation object
            Presentation pres = new Presentation();

            // Get the first slide
            ISlide sld = pres.Slides[0];

            // Add autoshape of rectangle type
            IShape shp1    = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 40, 150, 50);
            IShape shp2    = sld.Shapes.AddAutoShape(ShapeType.Moon, 160, 40, 150, 50);
            String alttext = "User Defined";
            int    iCount  = sld.Shapes.Count;

            for (int i = 0; i < iCount; i++)
            {
                AutoShape ashp = (AutoShape)sld.Shapes[0];
                if (String.Compare(ashp.AlternativeText, alttext, StringComparison.Ordinal) == 0)
                {
                    sld.Shapes.Remove(ashp);
                }
            }

            // Save presentation to disk
            pres.Save(dataDir + "RemoveShape_out.pptx", SaveFormat.Pptx);
        }
Beispiel #5
0
        public static void Run()
        {
            //ExStart:SupportOfMorphTransition
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Slides_Presentations_Transitions();

            using (Presentation presentation = new Presentation())
            {
                AutoShape autoshape = (AutoShape)presentation.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 100, 100, 400, 100);
                autoshape.TextFrame.Text = "Test text";

                presentation.Slides.AddClone(presentation.Slides[0]);

                presentation.Slides[1].Shapes[0].X      += 100;
                presentation.Slides[1].Shapes[0].Y      += 50;
                presentation.Slides[1].Shapes[0].Width  -= 200;
                presentation.Slides[1].Shapes[0].Height -= 10;

                presentation.Slides[1].SlideShowTransition.Type = Aspose.Slides.SlideShow.TransitionType.Morph;

                presentation.Save(dataDir + "presentation-out.pptx", SaveFormat.Pptx);
            }

            //ExEnd:SupportOfMorphTransition
        }
Beispiel #6
0
        private void btn_create_Click(object sender, EventArgs e)
        {
            Presentation pres = new Presentation(dataDir + "test.ppt");
            ISlide       sld  = pres.Slides[0];
            // sld.Name = "123456";

            // Add autoshape of rectangle type
            IShape shp1 = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 40, 150, 50);

            shp1.AlternativeText = "User Defined";
            shp1.Name            = "20170876";
            IShape shp2    = sld.Shapes.AddAutoShape(ShapeType.Moon, 160, 40, 150, 50);
            String alttext = "User Defined";
            int    iCount  = sld.Shapes.Count;

            for (int i = 0; i < iCount; i++)
            {
                AutoShape ashp = (AutoShape)sld.Shapes[i];
                if (String.Compare(ashp.AlternativeText, alttext, StringComparison.Ordinal) == 0)
                {
                    //ashp.Hidden = true;
                }
            }

            // Save presentation to disk
            pres.Save(dataDir + "Hiding_Shapes.pptx", SaveFormat.Ppt);
        }
        public static void Run()
        {
            // ExStart:1
            CellsApi   cellsApi   = new CellsApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String fileName        = "Sample_Test_Book.xls";
            String sheetName       = "Sheet4";
            int    autoshapeNumber = 1;
            String storage         = "";
            String folder          = "";

            try
            {
                // Upload source file to aspose cloud storage
                storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));

                // Invoke Aspose.Cells Cloud SDK API to get autoshape from worksheet
                AutoShapeResponse apiResponse = cellsApi.GetWorksheetAutoshape(fileName, sheetName, autoshapeNumber, storage, folder);

                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    AutoShape autoShape = apiResponse.AutoShape;
                    Console.WriteLine(autoShape.HtmlText);
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
        public static string GetVerticalAlignmentStyle(TextFrame textFrame, AutoShape parentShape)
        {
            // workaround with padding for div/p case

            string paddingTop = "";
            var    textFrameFormatEffective = textFrame.TextFrameFormat.GetEffective();

            float paraHeights = 0;

            foreach (var para in textFrame.Paragraphs)
            {
                paraHeights += para.GetRect().Height;
            }

            switch (textFrame.TextFrameFormat.GetEffective().AnchoringType)
            {
            case TextAnchorType.Bottom:
                paddingTop = string.Format("padding-top: {0}px;", parentShape.Height - paraHeights - textFrameFormatEffective.MarginTop - textFrameFormatEffective.MarginBottom);
                break;

            case TextAnchorType.Center:
                paddingTop = string.Format("padding-top: {0}px;", (parentShape.Height - paraHeights - textFrameFormatEffective.MarginTop - textFrameFormatEffective.MarginBottom) / 2);
                break;
            }

            return(paddingTop);
        }
        public static void Run()
        {
            string dataDir  = RunExamples.GetDataDir_Text();
            string pptxFile = Path.Combine(dataDir, "BulletData.pptx");

            using (Presentation pres = new Presentation(pptxFile))
            {
                AutoShape autoShape = (AutoShape)pres.Slides[0].Shapes[0];
                foreach (Paragraph para in autoShape.TextFrame.Paragraphs)
                {
                    IBulletFormatEffectiveData bulletFormatEffective = para.ParagraphFormat.Bullet.GetEffective();
                    Console.WriteLine("Bullet type: " + bulletFormatEffective.Type);
                    if (bulletFormatEffective.Type != BulletType.None)
                    {
                        Console.WriteLine("Bullet fill type: " + bulletFormatEffective.FillFormat.FillType);
                        switch (bulletFormatEffective.FillFormat.FillType)
                        {
                        case FillType.Solid:
                            Console.WriteLine(
                                "Solid fill color: " + bulletFormatEffective.FillFormat.SolidFillColor);
                            break;

                        case FillType.Gradient:
                            Console.WriteLine("Gradient stops count: " +
                                              bulletFormatEffective.FillFormat.GradientFormat.GradientStops.Count);
                            foreach (IGradientStopEffectiveData gradStop in bulletFormatEffective.FillFormat
                                     .GradientFormat.GradientStops)
                            {
                                Console.WriteLine(gradStop.Position + ": " + gradStop.Color);
                            }
                            break;

                        case FillType.Pattern:
                            Console.WriteLine("Pattern style: " +
                                              bulletFormatEffective.FillFormat.PatternFormat.PatternStyle);
                            Console.WriteLine("Fore color: " +
                                              bulletFormatEffective.FillFormat.PatternFormat.ForeColor);
                            Console.WriteLine("Back color: " +
                                              bulletFormatEffective.FillFormat.PatternFormat.BackColor);
                            break;
                        }
                    }

                    Console.WriteLine();
                }
            }
        }
Beispiel #10
0
    public static Shape CreateSimpeShape(EscherContainerRecord spContainer, Shape parent){
        Shape shape = null;
        EscherSpRecord spRecord = spContainer.GetChildById(EscherSpRecord.RECORD_ID);

        int type = spRecord.GetOptions() >> 4;
        switch (type){
            case ShapeTypes.TextBox:
                shape = new TextBox(spContainer, parent);
                break;
            case ShapeTypes.HostControl:
            case ShapeTypes.PictureFrame: {
                InteractiveInfo info = (InteractiveInfo)getClientDataRecord(spContainer, RecordTypes.InteractiveInfo.typeID);
                OEShapeAtom oes = (OEShapeAtom)getClientDataRecord(spContainer, RecordTypes.OEShapeAtom.typeID);
                if(info != null && info.GetInteractiveInfoAtom() != null){
                    switch(info.GetInteractiveInfoAtom().GetAction()){
                        case InteractiveInfoAtom.ACTION_OLE:
                            shape = new OLEShape(spContainer, parent);
                            break;
                        case InteractiveInfoAtom.ACTION_MEDIA:
                            shape = new MovieShape(spContainer, parent);
                            break;
                        default:
                            break;
                    }
                } else if (oes != null){
                    shape = new OLEShape(spContainer, parent);
                }

                if(shape == null) shape = new Picture(spContainer, parent);
                break;
            }
            case ShapeTypes.Line:
                shape = new Line(spContainer, parent);
                break;
            case ShapeTypes.NotPrimitive: {
                EscherOptRecord opt = (EscherOptRecord)Shape.GetEscherChild(spContainer, EscherOptRecord.RECORD_ID);
                EscherProperty prop = Shape.GetEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES);
                if(prop != null)
                    shape = new Freeform(spContainer, parent);
                else {

                    logger.log(POILogger.WARN, "Creating AutoShape for a NotPrimitive shape");
                    shape = new AutoShape(spContainer, parent);
                }
                break;
            }
            default:
                shape = new AutoShape(spContainer, parent);
                break;
        }
        return shape;

    }
        public static string GetTextPositioningStyle(TextFrame textFrame, AutoShape parentShape)
        {
            var textFrameFormatEffective = textFrame.TextFrameFormat.GetEffective();

            float paraHeights  = 0;
            float maxParaWidth = float.MinValue;

            foreach (var para in textFrame.Paragraphs)
            {
                var paraRect = para.GetRect();
                paraHeights += paraRect.Height;
                if (paraRect.Width > maxParaWidth)
                {
                    maxParaWidth = paraRect.Width;
                }
            }

            bool verticalText = textFrameFormatEffective.TextVerticalType == TextVerticalType.Vertical ||
                                textFrameFormatEffective.TextVerticalType == TextVerticalType.WordArtVertical ||
                                textFrameFormatEffective.TextVerticalType == TextVerticalType.Vertical270;

            double paddingTop       = 0;
            double paddingLeft      = 0;
            string writingModeStyle = "";

            if (!verticalText)
            {
                switch (textFrameFormatEffective.AnchoringType)
                {
                case TextAnchorType.Bottom:
                    paddingTop = parentShape.Height - paraHeights - textFrameFormatEffective.MarginTop - textFrameFormatEffective.MarginBottom;
                    break;

                case TextAnchorType.Center:
                    paddingTop = (parentShape.Height - paraHeights - textFrameFormatEffective.MarginTop - textFrameFormatEffective.MarginBottom) / 2;
                    break;
                }
            }
            else
            {
                if (textFrameFormatEffective.TextVerticalType == TextVerticalType.WordArtVertical)
                {
                    writingModeStyle = "width: 1px; word-wrap: break-word; white-space: pre-wrap;";
                }
                else
                {
                    writingModeStyle = "writing-mode: vertical-rl;";
                }

                if ((textFrameFormatEffective.AnchoringType == TextAnchorType.Top && (textFrameFormatEffective.TextVerticalType == TextVerticalType.Vertical || textFrameFormatEffective.TextVerticalType == TextVerticalType.WordArtVertical)) ||
                    (textFrameFormatEffective.AnchoringType == TextAnchorType.Bottom && textFrameFormatEffective.TextVerticalType == TextVerticalType.Vertical270))
                {
                    paddingLeft = parentShape.Width - paraHeights - textFrameFormatEffective.MarginLeft - textFrameFormatEffective.MarginRight;
                }

                if (textFrameFormatEffective.AnchoringType == TextAnchorType.Center)
                {
                    if (textFrameFormatEffective.TextVerticalType == TextVerticalType.Horizontal || textFrame.Paragraphs.Count == 1)
                    {
                        paddingLeft = (parentShape.Width - paraHeights - textFrameFormatEffective.MarginLeft - textFrameFormatEffective.MarginRight) / 2;
                    }
                    else
                    {
                        paddingLeft = parentShape.Width - paraHeights - textFrameFormatEffective.MarginLeft - textFrameFormatEffective.MarginRight;
                    }
                }

                if (textFrameFormatEffective.TextVerticalType == TextVerticalType.Vertical270)
                {
                    writingModeStyle += "transform: rotate(180deg);";
                }
            }

            string paddingTopStyle  = string.Format("padding-top: {0}px;", paddingTop);
            string paddingLeftStyle = string.Format("padding-left: {0}px;", paddingLeft);

            return(string.Join(" ", paddingTopStyle, paddingLeftStyle, writingModeStyle));
        }