We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replace auto-date in presentation

In MS Powerpoint, you can insert a date & time field and check a box to have it auto-update.



I have a need to open an existing presentation, find such date fields and possibly replace them with another value.



I’ve been able to locate the text within the presentation, but I don’t know how to determine if the text represents an auto-updating date & time field.

Hi Wade,

I like to share that the date time property belong to header footer category. Also, if text frame has auto update fields then there must be some meta characters associated with that text frame as well. You can access the correct text frame using the meta information. Please follow the threads link 1 and link 2 for further information.

Thanks and Regards,

Thanks for your response. The examples linked to apply only to PPT documents. Is there a similar way to do the same thing in a PPTX document?

Hello Dear,

I regret to share that MS PowerPoint 2007 does not add real headers and footers, rather it adds normal rectangle shapes as headers and footers. So, there is no classes or properties related to headers and footers in Aspose.Slides.Pptx.

As a work aroundIn, ShapeEx.AlternativeText property can be used to identify a shape, provided that the creator of the presentation adds unique "Alternative Text" to shapes. You can add a shapes and can add the slide index in the text of that rectangle to show slide number and your own saved time. Other option is to use a template PPTX slide, that has been created in PowerPoint and has macro enabled slide number or time.

An issue with issue id 13855 has already been created on our Issue Tracking System in order to figure out some other way to identify such headers and footers. This thread has been linked with this issue so that you can be updated here as soon as this issue is resolved.

Thanks and Regards,

Is this issue fixed in the latest version of aspose. If yes can you give me the sample code to replace/remove the date time fields.

@pradeepdone,

I suggest you to please refer to following code snippet for identifying DateTime fields in presentation.

    public static void TestDateTime()
    {

        Presentation pres = new Presentation("one.pptx");
        foreach (ISlide slide in pres.Slides)
        {
              
            IShapeCollection sc = slide.Shapes;
   
            for(int i=0;i<sc.Count;i++)
            {
                IShape shape = sc[i];
                IPlaceholder pc = ((AutoShape)shape).Placeholder;
                if(pc != null && pc.Type== PlaceholderType.DateAndTime)
                {
                   Console.WriteLine(((AutoShape)shape).TextFrame.Text);
                    //You may remove the shape if required using below code
                   //sc.Remove(shape);
                }
            }
        }

       
    }

You may use the sample code as per your convenience by using Aspose.Slides for .NET 18.2.

I have tried this code but i am not able to detect the update automatically date time field which was created in the ppt. It is not at all going in to the condition if(pc != null && pc.Type== PlaceholderType.DateAndTime) . Below is my code. Please find the attached ppt where i have added a date and its updates automatically whenever i opened the file. I would like to detect that date and remove before printing to pdf.

<a class="attachment" href="/uploads/discourse_instance3/12758">PPT FILE.zip</a> (21.6 KB)

using (Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(“D:\Convert\1.pptx”))
{

            foreach (ISlide slide in presentation.Slides)
            {

                IShapeCollection sc = slide.Shapes;
       
                for (int i = 0; i < sc.Count; i++)
                {
                    IShape shape = sc[i];
                    if (shape.Placeholder != null)
                    {
                        IPlaceholder pc = ((AutoShape)shape).Placeholder;
                      
                        //if (pc != null && pc.GetType() == PlaceholderType.DateAndTime)
                        if (pc != null && pc.Type == PlaceholderType.DateAndTime)
                        {
                            Console.WriteLine(((AutoShape)shape).TextFrame.Text);
                            sc.Remove(shape);
                        }
                    }
                }
            }

            presentation.Save("D:\\Convert\\PPT.pdf", Aspose.Slides.Export.SaveFormat.Pdf);

        }

@wpeeler,

I request you to please share the source presentation, generated output and desired output with us. We will investigate the issue further on our end to help you out.

Please attached zip file containing the input file ppt and the output file pdf. After converting to PDF the date which was created as to update automatically (Please find the below screenshot for reference) has to be defected and removed before saving it to PDF which is not happening with the sample code which is given.

image.png (57.6 KB)

PPT FILE.zip (51.3 KB)

Actually if there is any DateTime in header or footer then those PlaceholderType.DateAndTime condition is working but how do i detect the dateTime inside the title/subtitle or the content in the ppt.

@pradeepdone,

I have observed the presentation file shared by you. Actually, your text frame portion has got FiieldType that involve datetime in it. I suggest you to please try using following sample code to serve the purpose on your end.

    public static void TestRemoveDateTime()
    {
        String path=@"C:\Aspose Data\PPT FILE\";
        using (Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(path+"1.pptx"))
        {

            foreach (ISlide slide in presentation.Slides)
            {

                IShapeCollection sc = slide.Shapes;
   
                for (int i = 0; i < sc.Count; i++)
                {
                    IShape shape = sc[i];
                    if (shape.Placeholder != null)
                    {
                        IPlaceholder pc = ((AutoShape)shape).Placeholder;
                  
                        //if (pc != null && pc.GetType() == PlaceholderType.DateAndTime)
                        if (pc != null && pc.Type == PlaceholderType.DateAndTime)
                        {

                            Console.WriteLine(((AutoShape)shape).TextFrame.Text);
                            sc.Remove(shape);
                        }
                        else
                        {
                            if (((AutoShape)shape).TextFrame != null)
                            {
                                bool ifTimeType = false;
                                foreach (IParagraph para in ((AutoShape)shape).TextFrame.Paragraphs)
                                {
                                    foreach(IPortion port in para.Portions)
                                    {
                                        if (port.Field != null)
                                        {
                                            /*if (port.Field.Type == FieldType.DateTime || port.Field.Type == FieldType.DateTime1 || port.Field.Type == FieldType.DateTime2 || port.Field.Type == FieldType.DateTime3
                                                || port.Field.Type == FieldType.DateTime4 || port.Field.Type == FieldType.DateTime5 || port.Field.Type == FieldType.DateTime6
                                                || port.Field.Type == FieldType.DateTime7 || port.Field.Type == FieldType.DateTime8 || port.Field.Type == FieldType.DateTime9
                                                || port.Field.Type == FieldType.DateTime10 || port.Field.Type == FieldType.DateTime11 || port.Field.Type == FieldType.DateTime12)
                                            */
                                            if(port.Field.Type.InternalString.Contains("datetime"))
                                            {
                                                ifTimeType = true;
                                                Console.WriteLine(((AutoShape)shape).TextFrame.Text);
                                                sc.Remove(shape);

                                            }
                                        }
                                       
                                    }
                                    if (ifTimeType)
                                        break;
                                }
                            }
                        }
                    }
                }
            }

            presentation.Save(path+"Gen+PpT.pdf", Aspose.Slides.Export.SaveFormat.Pdf);

        }
    }

Thanks that actually worked.

@pradeepdone,

Its good know that things are working on your end. Please share feedback with us if there is still an issue.

The issues you have found earlier (filed as SLIDESNET-38606,SLIDESNET-38601) have been fixed in this update.