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

}

结果:

这里写图片描述

读书感悟

来自《罗马假日》

  • 现在,我必须离开了。我走到街角,然后转弯。答应我,别看着我,把车开走,离开我,就像我离开你。
  • 罗马不是一日建成的.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 开心一笑 有个四岁的小鬼问我:哥哥你怎么长得那么丑啊?我想了想,到他耳边说:你不要告诉别人哦。其实我就是未来的你。...
    架构师启示录阅读 7,690评论 0 2
  • 原本定的今天试营业,被推迟了,还有很多准备工作没有完成。因为装了大风车的缘故,最近陆陆续续有客人进来询问,什么时候...
    厨房里的xiao阅读 1,796评论 1 1
  • 今天,在《三生三世》中东华帝君的扮演者高伟光在酒店被偷拍,其女友去探班在酒店同住,又引起大家一阵讨论。 混在演艺圈...
    剧透社阅读 4,357评论 0 0
  • 由于大宝和老公都感冒,于是老公和大宝去单位的房子住,我和二宝还有婆婆在小区的家里住。上午我给老公打电话询问大宝的情...
    qing_love阅读 1,810评论 0 0
  • 每日一感:喝茶总是口渴 2017-04-21 01:08 · 字数 277 · 今天晚上喝的茶是,安化黑茶中的百两...
    金花奇迹阅读 1,279评论 0 0

友情链接更多精彩内容