Showing HTML in PowerPoint

前端 未结 2 503
遇见更好的自我
遇见更好的自我 2020-12-21 17:21

My Goal: Want to show HTML in Slide which I dynamically inject into a Master Presentation.

What I\'ve achieved So far: Converted Ht

2条回答
  •  借酒劲吻你
    2020-12-21 17:50

    I hope you managed to find something about your issue.

    A bit late, but for future people who might come here.

    This is for the HTML -> PPT part.

    PowerPoint.Presentation presentation;
    presentation = ppApp.Presentations.Open(configuration.PPTTExportedFile, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);       
    foreach (PowerPoint.Slide slide in presentation.Slides)
    {
        foreach (PowerPoint.Shape shape in slide.Shapes)
        {
            File.WriteAllText(temporaryFilePath, html);
            WebsiteToImage websiteToImage = new WebsiteToImage(temporaryFilePath, @"New picture path");
            websiteToImage.Generate();
            slide.Shapes.AddPicture(@"picture path", MsoTriState.msoTrue, MsoTriState.msoTrue, oldshapeleft, oldshapetop, oldshapewidth, oldshapeheight);
            fileToDelete.Add(temporaryFilePath);
            fileToDelete.Add(@""dont forget to remove tmp files");
        }
    }
    

    Convert webpage to image from ASP.NET

    If you want to do any object manipulation in Word/Excel/PowerPoint, I suggest to work with

    Console.Write("AlternativeText: ");
    Console.WriteLine(shape.AlternativeText);
    

    Because if you save in your original file an AlternativeText in your object, you can access it fast and you can even change the PATH into a simple variable.

    And if you want for example to export a HTML table, do an image from it and change the AlternativeText in order to access it easier later, while giving it an appropriate name that you can access with a 3rd software tool, because PowerPoint doesn't support HTML Tags

    Next to do:

    File.Copy(WordTemplateFile, WordExportedFile, true);
    

    Why you want to change the original? Just make a copy, and keep it as a template which you can change at any moment while creating a new changed version from it.( good for reports )

    AlternativeText is very useful if you plan to work with.

    For your replacement, you might want to use NetOffice/Microsoft Office libraries.

    foreach (NetOffice.WordApi.InlineShape s in docWord.InlineShapes)
    {
        if (s.Type==NetOffice.WordApi.Enums.WdInlineShapeType.wdInlineShapePicture &&  s.AlternativeText.Contains("any pattern you are looking for"))
        {
            
            s.Range.InsertFile();
        }
     }
    

    You loop through all your file and check if something fits your pattern.

    Good luck.

提交回复
热议问题