Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Tue May 24, 2022 5:40 pm

Hello Spire.Presentation friends!
Is it possible to write a variable to an existing textbox in a presentation slide?

For example, read a textbox names CustomerName and update it with a value from a form.

Thank you so much for your help!

elcade00
 
Posts: 4
Joined: Tue May 24, 2022 1:05 pm

Wed May 25, 2022 9:58 am

Hello,

Thanks for your inquiry.

Please try the code below to read a textbox by name and update the text in it.
Code: Select all
            Presentation templatePresentation = new Presentation();
            templatePresentation.LoadFromFile("hello.pptx");
            var slide = templatePresentation.Slides[0];
            foreach(IShape shape in slide.Shapes)
            {
                if (shape.Name.Equals("CustomerName"))
                {
                    if (shape.IsTextBox)
                    {
                        IAutoShape autoShape = shape as IAutoShape;
                        autoShape.TextFrame.Paragraphs[0].Text = "Updated String";
                    }
                }
            }
            templatePresentation.SaveToFile("Test.pptx", Spire.Presentation.FileFormat.Pptx2013);
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed May 25, 2022 12:22 pm

Works great!
Thank you Andy!

elcade00
 
Posts: 4
Joined: Tue May 24, 2022 1:05 pm

Return to Spire.Presentation