開心一笑
昨晚被一道神題考住了!
( )( ) ( )2 4 6 7 8
讓我填空~我按照數列組合算了一下午都不對
最后,
答案是這樣的
(門前大橋下)(游過一群鴨) (快來快來數一數)
2 4 6 7 8
我tm到現在都不想說話…
提出問題
POI中PPT如何添加表格???
解決問題
19.png
一下只是一個簡單的例子,具體生成表格,一般都是封裝成方法,不過沒事慢慢來,一步一步滴......
package com.hwy.test;
import org.apache.poi.xslf.usermodel.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
* PPT簡單導出
* Created by Ay on 2016/6/18.
*/
public class MyFirstPPTTest {
public static void main(String[] args) throws Exception{
/** 文件路徑 **/
String filePath = "D://MyPPT.pptx";
/** 加載PPT **/
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(filePath));
/** 創建一個slide,理解為PPT里的每一頁 **/
XSLFSlide slide = ppt.createSlide();
/** 獲得slideMasters**/
XSLFSlideMaster[] slideMasters = ppt.getSlideMasters();
/** 創建表格**/
XSLFTable table = slide.createTable();
/** 設置表格 x ,y ,width,height **/
Rectangle2D rectangle2D = new Rectangle2D.Double(20,90,700,500);
/** 生成第一行 **/
XSLFTableRow firstRow = table.addRow();
/** 生成第一個單元格**/
XSLFTableCell firstCell = firstRow.addCell();
/** 設置單元格的邊框顏色 **/
firstCell.setBorderBottomColor(new Color(10,100,120));
firstCell.setBorderRightColor(new Color(10,100,120));
firstCell.setBorderLeftColor(new Color(10,100,120));
firstCell.setBorderTopColor(new Color(10,100,120));
/** 設置單元格邊框 **/
firstCell.setBorderLeft(3);
firstCell.setBorderRight(3);
firstCell.setBorderTop(3);
firstCell.setBorderBottom(3);
/** 設置文本 **/
firstCell.setText("AAA");
/** 設置單元格的邊框寬度 **/
XSLFTableCell secondCell = firstRow.addCell();
secondCell.setText("BBB");
/** 設置單元格的邊框顏色 **/
secondCell.setBorderBottomColor(new Color(10,100,120));
secondCell.setBorderRightColor(new Color(10,100,120));
secondCell.setBorderLeftColor(new Color(10,100,120));
secondCell.setBorderTopColor(new Color(10,100,120));
/** 設置單元格邊框 **/
secondCell.setBorderLeft(3);
secondCell.setBorderRight(3);
secondCell.setBorderTop(3);
secondCell.setBorderBottom(3);
table.setAnchor(rectangle2D);
/** 輸出文件 **/
ppt.write(new FileOutputStream(filePath));
}
}
結果:
這里寫圖片描述
讀書感悟
來自《羅馬假日》
- 現在,我必須離開了。我走到街角,然后轉彎。答應我,別看著我,把車開走,離開我,就像我離開你。
- 羅馬不是一日建成的.