[英]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.