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.

Wed Jun 15, 2022 12:52 pm

I am using the Spire.Office version 5.2.0 (licensed) . The below code is giving the "Index out of range" error while trying to add the html to the shapes

Code: Select all
public void CreatePPTFromHtml(string htmlString, string outputFilename)
        {
            Presentation ppt = new Presentation();

            ShapeList shapes = ppt.Slides[0].Shapes;
            try
            {
               [color=#FF0000] shapes.AddFromHtml(htmlString);[/color]
            }
            catch (Exception ex)
            {

                throw ex;
            }


            ppt.SaveToFile(outputFilename, FileFormat.Pptx2013);
        }

Find the details of the exception:
Exception message:
Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

Stack Trace:
at System.Collections.ArrayList.get_Item(Int32 index)
at spr䚸.ᜀ(Int32 A_0, String A_1, Dictionary`2 A_2)
at spr䚷.ᜂ(ArrayList A_0, Char[] A_1)
at EmbedHtmlString.AppendHtmlString.CreatePPTFromHtml(String htmlString, String outputFilename) in line 8

Any insight on why this error is coming. Thanks in advance.

SudhiHebbar
 
Posts: 5
Joined: Thu May 26, 2022 12:56 pm

Thu Jun 16, 2022 2:52 am

Hello,

Thanks for your inquiry.

To help us reproduce the issue, could you please send the html string to us? Thanks in advance.

Besides, there is a good news for you. Regarding the issue SPIREPPT-1963 which you encountered, it has been resolved and now is currently in the testing phase. If all goes well, we will add this fix in the next new version of Spire.Office.
Sincerely,
Andy
E-iceblue support team
User avatar

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

Thu Jun 16, 2022 5:20 am

This is the HTML string used to pass to the method

Code: Select all
string htmlString = @"<HTML><BODY><div><img src='155-200x200.jpg' /><p>The tool is used to streamline and automate the process, improve coordination and communication, increase visibility. The key features of tool are:<br /><ul><li>Identifies tasks ready to be executed</li><li>Plan management in MS project with built-in sync</li><li>Notifies task readiness for team</li><li>Reporting</li></ul></p></div></BODY></HTML>";


Note: The image is stored in the executable library path.

SudhiHebbar
 
Posts: 5
Joined: Thu May 26, 2022 12:56 pm

Thu Jun 16, 2022 7:58 am

Hello,

This HTML is similar in structure to the HTML you provided last time, so we verified it using the fix for the previous issue(SPIREPPT-1963). We found the fix works for this HTML as well. So I will keep you informed as soon as issue SPIREPPT-1963 is completely resolved.
Sincerely,
Andy
E-iceblue support team
User avatar

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

Return to Spire.Presentation