您需要调用TextRun.appendText()
而不是调用TextRun.createTextRun()
两次,因为第二次调用将覆盖第一个实例。
import java.awt.geom.Rectangle2D;
import java.io.FileOutputStream;
import org.apache.poi.hslf.model.*;
import org.apache.poi.hslf.usermodel.*;
public class HslfTextBox {
public static void main(String[] args) throws Exception {
SlideShow ppt = new SlideShow();
Slide s = ppt.createSlide();
TextBox txt = new TextBox();
txt.setAnchor(new Rectangle2D.Double(100,100,100,100));
TextRun run = txt.createTextRun();
RichTextRun rtr1 = run.getRichTextRuns()[0];
rtr1.setText("small text\n");
rtr1.setFontSize(10);
RichTextRun rtr2 = run.appendText("big text\n");
rtr2.setBold(true);
rtr2.setFontSize(14);
s.addShape(txt);
FileOutputStream fos = new FileOutputStream("hssftext.ppt");
ppt.write(fos);
fos.close();
}
}