static void Main(string[] args)
        {
            //Create a workbook
            Workbook wb = new Workbook();

            //Add an excel chart
            int chartSheetIndex = AddExcelChartInWorkbook(wb);

            wb.Worksheets.SetOleSize(0, 5, 0, 5);

            Bitmap imgChart = wb.Worksheets[chartSheetIndex].Charts[0].ToImage();

            //Save the workbook to stream
            MemoryStream wbStream = wb.SaveToStream();

            //Create a presentation
            PresentationEx pres = new PresentationEx();
            SlideEx        sld  = pres.Slides[0];

            //Add the workbook on slide
            AddExcelChartInPresentation(pres, sld, wbStream, imgChart);

            //Write the output presentation on disk
            pres.Write("chart.pptx");
        }
示例#2
0
        static void Main(string[] args)
        {
            //Instantiate a Presentation class that represents the presentation file
            string MyDir = @"Files\";

            using (PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx"))
            {
                //Access the second slide
                SlideEx sld = pres.Slides[1];

                //Create a memory stream object
                MemoryStream SvgStream = new MemoryStream();

                //Generate SVG image of slide and save in memory stream
                sld.WriteAsSvg(SvgStream);
                SvgStream.Position = 0;

                //Save memory stream to file
                using (Stream fileStream = System.IO.File.OpenWrite(MyDir + "PresentatoinTemplate.svg"))
                {
                    byte[] buffer = new byte[8 * 1024];
                    int    len;
                    while ((len = SvgStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        fileStream.Write(buffer, 0, len);
                    }
                }
                SvgStream.Close();
            }
        }
示例#3
0
        // Get all the text in a slide.
        public static List <string> GetAllTextInSlide(string presentationFile, int slideIndex)
        {
            // Create a new linked list of strings.
            List <string> texts = new List <string>();

            //Instantiate PresentationEx class that represents PPTX
            using (PresentationEx pres = new PresentationEx(presentationFile))
            {
                //Access the slide
                SlideEx sld = pres.Slides[slideIndex];

                //Iterate through shapes to find the placeholder
                foreach (ShapeEx shp in sld.Shapes)
                {
                    if (shp.Placeholder != null)
                    {
                        //get the text of each placeholder
                        texts.Add(((AutoShapeEx)shp).TextFrame.Text);
                    }
                }
            }

            // Return an array of strings.
            return(texts);
        }
        static void Main(string[] args)
        {
            //Create empty presentation
            using (PresentationEx pres = new PresentationEx())
            {
                //Accessing first slide
                SlideEx slide = pres.Slides[0];

                //Addding default chart
                ChartEx ppChart = slide.Shapes.AddChart(ChartTypeEx.ClusteredColumn3D, 20F, 30F, 400F, 300F);

                //Getting Chart data
                ChartDataEx chartData = ppChart.ChartData;

                //Removing Extra default series
                chartData.Series.RemoveAt(1);
                chartData.Series.RemoveAt(1);

                //Modifying chart categories names
                chartData.Categories[0].ChartDataCell.Value = "Bikes";
                chartData.Categories[1].ChartDataCell.Value = "Accessories";
                chartData.Categories[2].ChartDataCell.Value = "Repairs";
                chartData.Categories[3].ChartDataCell.Value = "Clothing";

                //Modifying chart series values for first category
                chartData.Series[0].Values[0].Value = 1000;
                chartData.Series[0].Values[1].Value = 2500;
                chartData.Series[0].Values[2].Value = 4000;
                chartData.Series[0].Values[3].Value = 3000;

                //Setting Chart title
                ppChart.HasTitle             = true;
                ppChart.ChartTitle.Text.Text = "2007 Sales";
                PortionFormatEx format = ppChart.ChartTitle.Text.Paragraphs[0].Portions[0].PortionFormat;
                format.FontItalic                      = NullableBool.True;
                format.FontHeight                      = 18;
                format.FillFormat.FillType             = FillTypeEx.Solid;
                format.FillFormat.SolidFillColor.Color = Color.Black;


                //Setting Axis values
                ppChart.ValueAxis.IsAutomaticMaxValue  = false;
                ppChart.ValueAxis.IsAutomaticMinValue  = false;
                ppChart.ValueAxis.IsAutomaticMajorUnit = false;
                ppChart.ValueAxis.IsAutomaticMinorUnit = false;

                ppChart.ValueAxis.MaxValue          = 4000.0F;
                ppChart.ValueAxis.MinValue          = 0.0F;
                ppChart.ValueAxis.MajorUnit         = 2000.0F;
                ppChart.ValueAxis.MinorUnit         = 1000.0F;
                ppChart.ValueAxis.TickLabelPosition = TickLabelPositionType.NextTo;

                //Setting Chart rotation
                ppChart.Rotation3D.RotationX = 15;
                ppChart.Rotation3D.RotationY = 20;

                //Saving Presentation
                pres.Write("AsposeSampleChart.pptx");
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            string MyDir = @"Files\";

            //Instantiate a Presentation class that represents the presentation file
            using (PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx"))
            {
                //Access the first slide
                SlideEx sld = pres.Slides[0];

                //User defined dimension
                int desiredX = 1200;
                int desiredY = 800;

                //Getting scaled value  of X and Y
                float ScaleX = (float)(1.0 / pres.SlideSize.Size.Width) * desiredX;
                float ScaleY = (float)(1.0 / pres.SlideSize.Size.Height) * desiredY;

                //Create a full scale image
                Bitmap bmp = sld.GetThumbnail(ScaleX, ScaleY);

                //Save the image to disk in JPEG format
                bmp.Save(MyDir + "Thumbnail2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
示例#6
0
 public static void AccessingSlidesOfPresentation()
 {
     string MyDir = @"Files\";
     //Instantiate a Presentation object that represents a presentation file
     PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx");
     //Accessing a slide using its slide index
     SlideEx slide = pres.Slides[0];
 }
示例#7
0
 private static void AddExcelChartInPresentation(PresentationEx pres, SlideEx sld, Stream wbStream, Bitmap imgChart)
 {
     float oleWidth = pres.SlideSize.Size.Width;
     float oleHeight = pres.SlideSize.Size.Height;
     int x = 0;
     byte[] chartOleData = new byte[wbStream.Length];
     wbStream.Position = 0;
     wbStream.Read(chartOleData, 0, chartOleData.Length);
     OleObjectFrameEx oof = null;
     oof = sld.Shapes.AddOleObjectFrame(x, 0, oleWidth, oleHeight, "Excel.Sheet.8", chartOleData);
     oof.Image = pres.Images.AddImage((System.Drawing.Image)imgChart);
 }
        private static void AddExcelChartInPresentation(PresentationEx pres, SlideEx sld, Stream wbStream, Bitmap imgChart)
        {
            float oleWidth  = pres.SlideSize.Size.Width;
            float oleHeight = pres.SlideSize.Size.Height;
            int   x         = 0;

            byte[] chartOleData = new byte[wbStream.Length];
            wbStream.Position = 0;
            wbStream.Read(chartOleData, 0, chartOleData.Length);
            OleObjectFrameEx oof = null;

            oof       = sld.Shapes.AddOleObjectFrame(x, 0, oleWidth, oleHeight, "Excel.Sheet.8", chartOleData);
            oof.Image = pres.Images.AddImage((System.Drawing.Image)imgChart);
        }
示例#9
0
 public static void ChangingPositionOfSlide()
 {
     string MyDir = @"Files\";
     //Instantiate Presentation class to load the source presentation file
     PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx");
     {
         //Get the slide whose position is to be changed
         SlideEx sld = pres.Slides[0];
         //Set the new position for the slide
         sld.SlideNumber = 2;
         //Write the presentation to disk
         pres.Save(MyDir + "Changed Slide Position Presentation.pptx", SaveFormat.Pptx);
     }
 }
示例#10
0
        public static void RemovingSlides()
        {
            string MyDir = @"Files\";
            //Instantiate a Presentation object that represents a presentation file
            PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx");

            //Accessing a slide using its index in the slides collection
            SlideEx slide = pres.Slides[0];

            //Removing a slide using its reference
            pres.Slides.Remove(slide);

            //Writing the presentation file
            pres.Write(MyDir + "modified.pptx");
        }
示例#11
0
        public static void DeleteSlide(string presentationFile, int slideIndex)
        {
            //Instantiate a PresentationEx object that represents a PPTX file
            using (PresentationEx pres = new PresentationEx(presentationFile))
            {
                //Accessing a slide using its index in the slides collection
                SlideEx slide = pres.Slides[slideIndex];


                //Removing a slide using its reference
                pres.Slides.Remove(slide);


                //Writing the presentation as a PPTX file
                pres.Write(presentationFile);
            }
        }
示例#12
0
        static void Main(string[] args)
        {
            string MyDir = @"Files\";

            //Instantiate a Presentation class that represents the presentation file
            using (PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx"))
            {
                //Access the first slide
                SlideEx sld = pres.Slides[0];

                //Create a full scale image
                Bitmap bmp = sld.GetThumbnail(1f, 1f);

                //Save the image to disk in JPEG format
                bmp.Save(MyDir + "Test Thumbnail.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
示例#13
0
        // Move a slide to a different position in the slide order in the presentation.
        public static void MoveSlide(string presentationFile, int from, int to)
        {
            //Instantiate PresentationEx class to load the source PPTX file
            using (PresentationEx pres = new PresentationEx(presentationFile))
            {
                //Get the slide whose position is to be changed
                SlideEx sld = pres.Slides[from];
                SlideEx sld2 = pres.Slides[to];

                //Set the new position for the slide
                sld2.SlideNumber = from;
                sld.SlideNumber = to;

                //Write the PPTX to disk
                pres.Write(presentationFile);

            }
        }
示例#14
0
        public static string GetSlideText(string docName, int index)
        {
            string sldText = "";

            //Instantiate PresentationEx class that represents PPTX
            using (PresentationEx pres = new PresentationEx(docName))
            {
                //Access the slide
                SlideEx sld = pres.Slides[index];

                //Iterate through shapes to find the placeholder
                foreach (ShapeEx shp in sld.Shapes)
                {
                    if (shp.Placeholder != null)
                    {
                        //get the text of each placeholder
                        sldText += ((AutoShapeEx)shp).TextFrame.Text;
                    }
                }
            }
            return(sldText);
        }
示例#15
0
        static void Main(string[] args)
        {
            string path = @"Files\";
            //Accessing the presentation
            PresentationEx pres         = new PresentationEx(path + "RenderImageFromShape.pptx");
            ImageEx        img          = null;
            int            slideIndex   = 0;
            String         ImageType    = "";
            bool           ifImageFound = false;

            for (int i = 0; i < pres.Slides.Count; i++)
            {
                slideIndex++;
                //Accessing the first slide
                SlideEx sl = pres.Slides[i];
                System.Drawing.Imaging.ImageFormat Format = System.Drawing.Imaging.ImageFormat.Jpeg;
                for (int j = 0; j < sl.Shapes.Count; j++)
                {
                    // Accessing the shape with picture
                    ShapeEx sh = sl.Shapes[j];

                    if (sh is AutoShapeEx)
                    {
                        AutoShapeEx ashp = (AutoShapeEx)sh;
                        if (ashp.FillFormat.FillType == FillTypeEx.Picture)
                        {
                            img          = ashp.FillFormat.PictureFillFormat.Picture.Image;
                            ImageType    = img.ContentType;
                            ImageType    = ImageType.Remove(0, ImageType.IndexOf("/") + 1);
                            ifImageFound = true;
                        }
                    }

                    else if (sh is PictureFrameEx)
                    {
                        PictureFrameEx pf = (PictureFrameEx)sh;
                        if (pf.FillFormat.FillType == FillTypeEx.Picture)
                        {
                            img          = pf.PictureFormat.Picture.Image;
                            ImageType    = img.ContentType;
                            ImageType    = ImageType.Remove(0, ImageType.IndexOf("/") + 1);
                            ifImageFound = true;
                        }
                    }


                    //
                    //Setting the desired picture format
                    if (ifImageFound)
                    {
                        switch (ImageType)
                        {
                        case "jpeg":
                            Format = System.Drawing.Imaging.ImageFormat.Jpeg;
                            break;

                        case "emf":
                            Format = System.Drawing.Imaging.ImageFormat.Emf;
                            break;

                        case "bmp":
                            Format = System.Drawing.Imaging.ImageFormat.Bmp;
                            break;

                        case "png":
                            Format = System.Drawing.Imaging.ImageFormat.Png;
                            break;

                        case "wmf":
                            Format = System.Drawing.Imaging.ImageFormat.Wmf;
                            break;

                        case "gif":
                            Format = System.Drawing.Imaging.ImageFormat.Gif;
                            break;
                        }
                        //

                        img.Image.Save(path + "ResultedImage" + "." + ImageType, Format);
                    }
                    ifImageFound = false;
                }
            }
        }
示例#16
0
        static void RemovingProtection()
        {
            string MyDir = @"Files\";
            //Open the desired presentation
            PresentationEx pTemplate = new PresentationEx(MyDir + "ProtectedSample.pptx");

            //ISlide object for accessing the slides in the presentation
            SlideEx slide = pTemplate.Slides[0];

            //IShape object for holding temporary shapes
            ShapeEx shape;

            //Traversing through all the slides in presentation
            for (int slideCount = 0; slideCount < pTemplate.Slides.Count; slideCount++)
            {
                slide = pTemplate.Slides[slideCount];

                //Travesing through all the shapes in the slides
                for (int count = 0; count < slide.Shapes.Count; count++)
                {
                    shape = slide.Shapes[count];

                    //if shape is autoshape
                    if (shape is AutoShapeEx)
                    {
                        //Type casting to Auto shape and  getting auto shape lock
                        AutoShapeEx     Ashp          = shape as AutoShapeEx;
                        AutoShapeLockEx AutoShapeLock = Ashp.ShapeLock;

                        //Applying shapes locks
                        AutoShapeLock.PositionLocked = false;
                        AutoShapeLock.SelectLocked   = false;
                        AutoShapeLock.SizeLocked     = false;
                    }

                    //if shape is group shape
                    else if (shape is GroupShapeEx)
                    {
                        //Type casting to group shape and  getting group shape lock
                        GroupShapeEx     Group          = shape as GroupShapeEx;
                        GroupShapeLockEx groupShapeLock = Group.ShapeLock;

                        //Applying shapes locks
                        groupShapeLock.GroupingLocked = false;
                        groupShapeLock.PositionLocked = false;
                        groupShapeLock.SelectLocked   = false;
                        groupShapeLock.SizeLocked     = false;
                    }

                    //if shape is Connector shape
                    else if (shape is ConnectorEx)
                    {
                        //Type casting to connector shape and  getting connector shape lock
                        ConnectorEx     Conn     = shape as ConnectorEx;
                        ConnectorLockEx ConnLock = Conn.ShapeLock;

                        //Applying shapes locks
                        ConnLock.PositionMove = false;
                        ConnLock.SelectLocked = false;
                        ConnLock.SizeLocked   = false;
                    }

                    //if shape is picture frame
                    else if (shape is PictureFrameEx)
                    {
                        //Type casting to pitcture frame shape and  getting picture frame shape lock
                        PictureFrameEx     Pic     = shape as PictureFrameEx;
                        PictureFrameLockEx PicLock = Pic.ShapeLock;

                        //Applying shapes locks
                        PicLock.PositionLocked = false;
                        PicLock.SelectLocked   = false;
                        PicLock.SizeLocked     = false;
                    }
                }
            }
            //Saving the presentation file
            pTemplate.Save(MyDir + "RemoveProtectionSample.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
        }