poi ppt html,POI之PPT如何添加表格简单实例

开心一笑

昨晚被一道神题考住了!

( )( ) ( )2 4 6 7 8

让我填空~我按照数列组合算了一下午都不对

最后,

答案是这样的

(门前大桥下)(游过一群鸭) (快来快来数一数)

2 4 6 7 8

我tm到现在都不想说话…

提出问题

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

解决问题

030b3b4e8e1e?ref=myread

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

}

}

结果:

030b3b4e8e1e?ref=myread

这里写图片描述

读书感悟

来自《罗马假日》

现在,我必须离开了。我走到街角,然后转弯。答应我,别看着我,把车开走,离开我,就像我离开你。

罗马不是一日建成的.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值