POI之PPT如何添加表格簡(jiǎn)單實(shí)例

開(kāi)心一笑

昨晚被一道神題考住了!

( )( ) ( )2 4 6 7 8

讓我填空~我按照數(shù)列組合算了一下午都不對(duì)
最后,

答案是這樣的
(門(mén)前大橋下)(游過(guò)一群鴨) (快來(lái)快來(lái)數(shù)一數(shù))
2 4 6 7 8
我tm到現(xiàn)在都不想說(shuō)話…

提出問(wèn)題

POI中PPT如何添加表格???

解決問(wèn)題

19.png

一下只是一個(gè)簡(jiǎn)單的例子,具體生成表格,一般都是封裝成方法,不過(guò)沒(méi)事慢慢來(lái),一步一步滴......

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簡(jiǎn)單導(dǎo)出
 * 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));

        /** 創(chuàng)建一個(gè)slide,理解為PPT里的每一頁(yè) **/
        XSLFSlide slide = ppt.createSlide();
        /** 獲得slideMasters**/
        XSLFSlideMaster[] slideMasters = ppt.getSlideMasters();
        /** 創(chuàng)建表格**/
        XSLFTable table = slide.createTable();
        /** 設(shè)置表格 x ,y ,width,height **/
        Rectangle2D rectangle2D = new Rectangle2D.Double(20,90,700,500);
        /** 生成第一行 **/
        XSLFTableRow firstRow =  table.addRow();
        /** 生成第一個(gè)單元格**/
        XSLFTableCell firstCell =  firstRow.addCell();

        /** 設(shè)置單元格的邊框顏色 **/
        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));

        /** 設(shè)置單元格邊框 **/
        firstCell.setBorderLeft(3);
        firstCell.setBorderRight(3);
        firstCell.setBorderTop(3);
        firstCell.setBorderBottom(3);
        /** 設(shè)置文本 **/
        firstCell.setText("AAA");
        /** 設(shè)置單元格的邊框?qū)挾?**/
        XSLFTableCell secondCell =  firstRow.addCell();
        secondCell.setText("BBB");

        /** 設(shè)置單元格的邊框顏色 **/
        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));

        /** 設(shè)置單元格邊框 **/
        secondCell.setBorderLeft(3);
        secondCell.setBorderRight(3);
        secondCell.setBorderTop(3);
        secondCell.setBorderBottom(3);

        table.setAnchor(rectangle2D);


        /** 輸出文件 **/
        ppt.write(new FileOutputStream(filePath));
    }

}

結(jié)果:

這里寫(xiě)圖片描述

讀書(shū)感悟

來(lái)自《羅馬假日》

  • 現(xiàn)在,我必須離開(kāi)了。我走到街角,然后轉(zhuǎn)彎。答應(yīng)我,別看著我,把車(chē)開(kāi)走,離開(kāi)我,就像我離開(kāi)你。
  • 羅馬不是一日建成的.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 開(kāi)心一笑 有個(gè)四歲的小鬼問(wèn)我:哥哥你怎么長(zhǎng)得那么丑???我想了想,到他耳邊說(shuō):你不要告訴別人哦。其實(shí)我就是未來(lái)的你。...
    架構(gòu)師啟示錄閱讀 2,812評(píng)論 0 2
  • 原本定的今天試營(yíng)業(yè),被推遲了,還有很多準(zhǔn)備工作沒(méi)有完成。因?yàn)檠b了大風(fēng)車(chē)的緣故,最近陸陸續(xù)續(xù)有客人進(jìn)來(lái)詢問(wèn),什么時(shí)候...
    廚房里的xiao閱讀 296評(píng)論 1 1
  • 今天,在《三生三世》中東華帝君的扮演者高偉光在酒店被偷拍,其女友去探班在酒店同住,又引起大家一陣討論。 混在演藝圈...
    劇透社閱讀 964評(píng)論 0 0
  • 由于大寶和老公都感冒,于是老公和大寶去單位的房子住,我和二寶還有婆婆在小區(qū)的家里住。上午我給老公打電話詢問(wèn)大寶的情...
    qing_love閱讀 287評(píng)論 0 0
  • 每日一感:喝茶總是口渴 2017-04-21 01:08 · 字?jǐn)?shù) 277 · 今天晚上喝的茶是,安化黑茶中的百兩...
    金花奇跡閱讀 174評(píng)論 0 0

友情鏈接更多精彩內(nèi)容