81,092
社区成员
发帖
与我相关
我的任务
分享
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.sl.usermodel.Line;
import org.apache.poi.hslf.usermodel.HSLFAutoShape;
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.HSLFTextBox;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.hslf.usermodel.HSLFTextRun;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
public class DrawShape {
/**
* 在一个幻灯片上话一个shape
*
* 一个shape的位置同安卓里控件的位置
*/
public static void main(String[] args)throws IOException{
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
//线
Line line = new Line();
line.setAnchor(new java.awt.Rectangle(50, 50, 100, 20));
line.setLineColor(new Color(0, 128, 0));
line.setLineCompound(LineCompound.DOUBLE);
slide.addShape(line);
//文本框
HSLFTextBox txt = new HSLFTextBox();
txt.setText("Hello, World!");
txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50));
// 用TextRun文本格式
HSLFTextParagraph tp = txt.getTextParagraphs().get(0);
tp.setTextAlign(TextAlign.RIGHT);// 右对齐
HSLFTextRun rt = tp.getTextRuns().get(0);
rt.setFontSize(32.);
rt.setFontFamily("Arial");
rt.setBold(true);
rt.setItalic(true);
rt.setUnderlined(true);
rt.setFontColor(Color.red);
slide.addShape(txt);
// 自定义图形
// 32-point star
HSLFAutoShape sh1 = new HSLFAutoShape(ShapeType.STAR_32);
sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200));
sh1.setFillColor(Color.red);
slide.addShape(sh1);
//梯形
HSLFAutoShape sh2 = new HSLFAutoShape(ShapeType.TRAPEZOID);
sh2.setAnchor(new java.awt.Rectangle(150, 150, 100, 200));
sh2.setFillColor(Color.blue);
slide.addShape(sh2);
FileOutputStream out = new FileOutputStream("C:/Users/Admin/Desktop/TestPOI/testppt.ppt");
ppt.write(out);
out.close();
}
}
就line那一块出错,不知道应该导入什么包