0
我將html轉換爲使用aspose java庫的ppt。但是,我無法生成樣式,比如(填充,背景顏色等),而類似的款式(顏色,字體大小)的工作就好了,看看代碼..無法在aspose ppt中嵌入樣式,它是從html文件中呈現的
public class poi {
public static void main(String[] args) throws Exception {
// The path to the documents directory.
String dataDir = Utils.getDataDir(poi.class);
// Create Empty presentation instance
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, 50, 150, 300, 150);
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(dataDir + "file.html");
Reader reader = new InputStreamReader(inputStream);
int data = reader.read();
String content = ReadFile(dataDir + "file.html");
// Adding text from HTML stream reader in text frame
ashape.getTextFrame().getParagraphs().addFromHtml(content);
// Saving Presentation
pres.save(dataDir + "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();
}
}
正如你可以看到我正在加載具有內聯樣式的html文件,但我無法完成大部分要加載的CSS元素。有什麼建議麼?
我的需求是相當複雜的,它包括html表,每個單元格有不同的背景顏色,一些頁面有不同的圖表,如酒吧,列和餅圖等..這可能與aspose有關嗎? –
@Balchandar Reddy目前,Aspose.Slides只支持從HTML到演示文本框架的基本文本導入。 – Mudassir