繁体   English   中英

我们可以使用aspose或POI Api通过Java将HTML代码嵌入ppt吗?

[英]Can we embed HTML code in ppt through Java using aspose or POI Api?

我想将HTML代码嵌入ppt中,就像我将HTML代码作为Name一样,因此在ppt中应将其显示为Name 因为在数据库中,我将插入一些具有html代码的数据。 我尝试了很多方法,但是找不到适合我需要的方法。 因此,有关如何进行的任何建议。

@Niket Thada,

我已经观察到您的要求,并且希望与大家分享Aspose.Slides确实允许在演示文稿幻灯片文本框中导入与HTML文本相关的标签。 Aspose.Slides目前支持演示文稿中与文本相关的标签。 我建议您尝试最后使用以下示例代码。

    Presentation pres = new Presentation();

    // Access the default first slide of presentation
    ISlide slide = pres.getSlides().get_Item(0);

    // Adding the AutoShape to accommodate the HTML content
    IAutoShape ashape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10,
                    (float) pres.getSlideSize().getSize().getWidth(), (float) pres.getSlideSize().getSize().getHeight());

    ashape.getFillFormat().setFillType(FillType.NoFill);

    // Adding text frame to the shape
    ashape.addTextFrame("");

    // Clearing all paragraphs in added text frame
    ashape.getTextFrame().getParagraphs().clear();

    // Loading the HTML file using InputStream
    InputStream inputStream = new FileInputStream("html from pp2010 clipboard.html");
    Reader reader = new InputStreamReader(inputStream);

    int data = reader.read();
    String content = ReadFile("html from pp2010 clipboard.html");

    // Adding text from HTML stream reader in text frame
    ashape.getTextFrame().getParagraphs().addFromHtml(content);

    // Saving Presentation
    pres.save("output.pptx", SaveFormat.Pptx);

    public static String ReadFile(String FileName) throws Exception {

            File file = new File(FileName);
            StringBuilder contents = new StringBuilder();
            BufferedReader reader = null;

            try {
                    reader = new BufferedReader(new FileReader(file));
                    String text = null;

                    // repeat until all lines is read
                    while ((text = reader.readLine()) != null) {
                            contents.append(text).append(System.getProperty("line.separator"));
                    }
            } catch (IOException e) {
                    e.printStackTrace();
            } finally {
                    try {
                            if (reader != null) {
                                    reader.close();
                            }
                    } catch (IOException e) {
                            e.printStackTrace();
                            return null;
                    }
            }

            return contents.toString();

    }

我在Aspose担任技术支持/开发人员。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM