往ppt插入表格,如何调适表格的位置?用table的哪个方法,试了moveTo(),发现边框移动哦了,内容没有移动?
public class AddTable { public static void createPPT() {
try {
SlideShow ppt = new SlideShow();
FileOutputStream out = new FileOutputStream("slideshow.ppt");
ppt.write(out);
out.close();
} catch (IOException ex) {
Logger.getLogger(AddTable.class.getName()).log(Level.SEVERE, null, ex);
}
} public static void main(String[] args) {
try {
createPPT();
SlideShow ppt = new SlideShow(new FileInputStream("slideshow.ppt")); Slide slide = ppt.createSlide();
String userName = "张三";
String department = "信息部";
String date = "2009-3-3";
//创建表格
String[][] data = {{"用户名称:", userName}, {"部门:", department}, {"用户上次登录时间:", date},}; Table table = new Table(3, 2);
TableCell cell = null;
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
cell = table.getCell(i, j);
cell.setText(data[i][j]); RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
rt.setFontName("Times New Roman");
rt.setFontSize(10); cell.setVerticalAlignment(TextBox.AnchorMiddle);
cell.setHorizontalAlignment(TextBox.AlignCenter);
}
} //设置表格位置
// cell.moveTo(150f, 150f);
// table.moveTo(150, 150);
//set table borders
Line border = table.createBorder();
border.setLineColor(Color.red);
border.setLineWidth(1.0);
table.setAllBorders(border); //set width of the 1st column
table.setColumnWidth(0, 120);
//set width of the 2nd column
table.setColumnWidth(1, 180);
table.setAnchor(new java.awt.Rectangle(100, 100, 400, 400));
table.setAllBorders(border);
slide.addShape(table);
FileOutputStream out = new FileOutputStream("slideshow.ppt");
ppt.write(out);
out.close(); } catch (IOException ex) {
Logger.getLogger(AddTable.class.getName()).log(Level.SEVERE, null, ex);
} }
}
public class AddTable { public static void createPPT() {
try {
SlideShow ppt = new SlideShow();
FileOutputStream out = new FileOutputStream("slideshow.ppt");
ppt.write(out);
out.close();
} catch (IOException ex) {
Logger.getLogger(AddTable.class.getName()).log(Level.SEVERE, null, ex);
}
} public static void main(String[] args) {
try {
createPPT();
SlideShow ppt = new SlideShow(new FileInputStream("slideshow.ppt")); Slide slide = ppt.createSlide();
String userName = "张三";
String department = "信息部";
String date = "2009-3-3";
//创建表格
String[][] data = {{"用户名称:", userName}, {"部门:", department}, {"用户上次登录时间:", date},}; Table table = new Table(3, 2);
TableCell cell = null;
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
cell = table.getCell(i, j);
cell.setText(data[i][j]); RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
rt.setFontName("Times New Roman");
rt.setFontSize(10); cell.setVerticalAlignment(TextBox.AnchorMiddle);
cell.setHorizontalAlignment(TextBox.AlignCenter);
}
} //设置表格位置
// cell.moveTo(150f, 150f);
// table.moveTo(150, 150);
//set table borders
Line border = table.createBorder();
border.setLineColor(Color.red);
border.setLineWidth(1.0);
table.setAllBorders(border); //set width of the 1st column
table.setColumnWidth(0, 120);
//set width of the 2nd column
table.setColumnWidth(1, 180);
table.setAnchor(new java.awt.Rectangle(100, 100, 400, 400));
table.setAllBorders(border);
slide.addShape(table);
FileOutputStream out = new FileOutputStream("slideshow.ppt");
ppt.write(out);
out.close(); } catch (IOException ex) {
Logger.getLogger(AddTable.class.getName()).log(Level.SEVERE, null, ex);
} }
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货