java 读取ppt并写入txt
//excel文件
private static String path="d:\\document\\1.ppt";
public static void main(String[] args) {
?? try {
??? // 得到源文件
??? SlideShow ss = new SlideShow(new HSLFSlideShow(path));
??? // 得到源文件中的幻灯片数量
??? Slide[] slides = ss.getSlides();
??? for (int a = 0; a < slides.length; a++) {
???? // 得到每张幻灯片中的字符串数量
???? Shape[] sps = slides[a].getShapes();
???? for (int i = 0; i < sps.length; i++) {
????? System.out.println(((TextBox) sps[i]).getText());
????? new PPT().insert(ppt, ((TextBox)sps[i]).getText(), true);
???? }
??? }
?? } catch (Exception e) {
??? e.getMessage();
?? }
}
/**
* 将文本写入相应的文本中
*/
public void insert(String path, String content, boolean append) {
?? BufferedWriter bw;
?? File file;
?? try {
??? boolean addstr = append;
??? file = new File(path);
??? // 创建文件输出流写入文件
??? FileWriter fw = new FileWriter(file, addstr);
??? bw = new BufferedWriter(fw);
??? // 将文本内容写入文件
??? fw.write(content);
??? fw.flush();
??? fw.close();
?? } catch (Exception e) {
??? e.getMessage();
?? }
}
}