我想在ppt中嵌入HTML代码,就好像我的HTML代码名称所以在ppt中这应该显示为名称。因为在数据库中我会插入一些具有html代码的数据。我尝试了很多方法,但找不到合适的方法来满足我的需求。所以关于如何进行的任何建议。
答案 0 :(得分:0)
@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的支持开发人员/传播者。