使用 aspose api ppt 更改 java 中幻灯片的文本
change text of slide in java using aspose api ppt
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 编辑器。
我想更改文本区域中的文本按保存按钮,因此文本必须更改并调用显示功能。
我已经观察了您的示例代码,并且想分享一下,就Aspose.Slides相关的代码而言,没有任何问题,而且完全正确。您可以通过在 PowerPoint 中打开文本已更改的已保存演示文稿来验证这一点。如果您在这方面遇到任何问题,我们很乐意进一步帮助您。您也可以通过 Aspose.Slides support forums 联系我们。
我在 Aspose 工作,担任开发人员布道师。
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 编辑器。 我想更改文本区域中的文本按保存按钮,因此文本必须更改并调用显示功能。
我已经观察了您的示例代码,并且想分享一下,就Aspose.Slides相关的代码而言,没有任何问题,而且完全正确。您可以通过在 PowerPoint 中打开文本已更改的已保存演示文稿来验证这一点。如果您在这方面遇到任何问题,我们很乐意进一步帮助您。您也可以通过 Aspose.Slides support forums 联系我们。
我在 Aspose 工作,担任开发人员布道师。