POI之PPT如何添加表格簡單實例

開心一笑

昨晚被一道神題考住了!

( )( ) ( )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));
    }

}

結果:

這里寫圖片描述

讀書感悟

來自《羅馬假日》

  • 現在,我必須離開了。我走到街角,然后轉彎。答應我,別看著我,把車開走,離開我,就像我離開你。
  • 羅馬不是一日建成的.
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 開心一笑 有個四歲的小鬼問我:哥哥你怎么長得那么丑啊?我想了想,到他耳邊說:你不要告訴別人哦。其實我就是未來的你。...
    架構師啟示錄閱讀 2,786評論 0 2
  • 原本定的今天試營業,被推遲了,還有很多準備工作沒有完成。因為裝了大風車的緣故,最近陸陸續續有客人進來詢問,什么時候...
    廚房里的xiao閱讀 251評論 1 1
  • 今天,在《三生三世》中東華帝君的扮演者高偉光在酒店被偷拍,其女友去探班在酒店同住,又引起大家一陣討論。 混在演藝圈...
    劇透社閱讀 869評論 0 0
  • 由于大寶和老公都感冒,于是老公和大寶去單位的房子住,我和二寶還有婆婆在小區的家里住。上午我給老公打電話詢問大寶的情...
    qing_love閱讀 272評論 0 0
  • 每日一感:喝茶總是口渴 2017-04-21 01:08 · 字數 277 · 今天晚上喝的茶是,安化黑茶中的百兩...
    金花奇跡閱讀 153評論 0 0