public void save()
{ Presentation pres = new Presentation(filename);
ISlide slide = pres.getSlides().get_Item(0);
IShape shape= null;
for (int i = 0 ; i < slide.getShapes().size() ; i++)
{ shape = slide.getShapes().get_Item(i);
if (shape.getPlaceholder() != null)
{
((IAutoShape)shape).getTextFrame().setText(txtArea.getText());
}
}
pres.save(filename,SaveFormat.Ppt);
}
此代码用于更改文本但不起作用。我一次使用两个API,显示代码如下:
public void Display(int currentPage, String source)
{
try {
// Create a slideshow object; this creates an underlying POIFSFileSystem object for us
SlideShow ppt = new SlideShow(new HSLFSlideShow(source));
current=currentPage;
// Get all of the slides from the PPT file
Slide[] slides = ppt.getSlides();
Dimension pgsize = ppt.getPageSize();
all = slides.length;
String temp="";
lblPage.setText(currentPage+" / "+all);
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
//render
slides[currentPage-1].draw(graphics);
//save the output
/*FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
javax.imageio.ImageIO.write(img, "png", out);
out.close();
//ImageIcon icon = new ImageIcon("slide-" + (i + 1) + ".png");*/
ImageIcon icon = new ImageIcon(img);
lblPresentasi.setIcon(icon);
// Obtain metrics about the slide: its number and name
int number = slides[currentPage-1].getSlideNumber();
String title = slides[currentPage-1].getTitle();
// Obtain the embedded text in the slide
TextRun[] textRuns = slides[currentPage-1].getTextRuns();
System.out.println("Slide " + number + ": " + title);
System.out.println("\tText Runs");
txtArea.setText("Slide : " + number + " Title : " + title + "\n");
for (int j = 0; j < textRuns.length; j++) {
// Display each of the text runs present on the slide
System.out.println("\t\t" + j + ": " + textRuns[j].getText());
temp=txtArea.getText();
txtArea.setText(temp+"\t\t" + textRuns[j].getText() + "\n");
}
// Obtain the notes for this slide
System.out.println("\tNotes: ");
Notes notes = slides[currentPage-1].getNotesSheet();
if (notes != null) {
// Notes are comprised of an array of text runs
TextRun[] notesTextRuns = notes.getTextRuns();
for (int j = 0; j < notesTextRuns.length; j++) {
System.out.println("\t\t" + notesTextRuns[j].getText());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
任何人都可以请求帮助,我正在尝试用Java创建一个简单的powerpoint编辑器。 我想在textarea中更改文本按保存按钮,以便文本必须更改并调用显示功能。
答案 0 :(得分:0)
我已经观察了你的示例代码,并且喜欢分享那个与Aspose.Slides相关的代码,没有问题,这是完全正确的。您可以通过在PowerPoint中打开已更改文本的已保存演示文稿来验证这一点。如果您遇到任何问题,我们将很乐意为您提供进一步的帮助。您也可以通过Aspose.Slides support forums与我们联系。
我与Aspose一起担任开发人员传播者。