poi ppt 作者属性 修改_POI之PPT文本框生成及样式设置实例

该博客介绍了如何使用Apache POI库在PPT中创建文本框并设置样式,包括字体、颜色、大小、位置等。通过Java代码示例详细展示了创建文本段落、设置加粗、颜色、字体大小、字体类型以及文本框位置的方法。
摘要由CSDN通过智能技术生成

开心一笑

一大哥去医院看病。

医生问:你得了什么病?

大哥说: 我得了间接性失忆症。

医生问:具体什么症状?

大哥说:我一看到漂亮的姑娘就忘记自己已结婚了。

医生说:滚滚滚,这病我自己都没治好!

提出问题

POI如何生成PPT的文本框及各个样式????

解决问题

直接来例子,比较简单,但慢慢来,一步一步的......

package com.hwy.test;

import org.apache.poi.hslf.HSLFSlideShow;

import org.apache.poi.hslf.model.Slide;

import org.apache.poi.hslf.model.TextBox;

import org.apache.poi.hslf.usermodel.SlideShow;

import org.apache.poi.xslf.XSLFSlideShow;

import org.apache.poi.xslf.usermodel.*;

import java.awt.*;

import java.io.FileInputStream;

import java.io.FileOutputStream;

/**

* PPT简单导出

* Created by Ay on 2016/6/14.

*/

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 xslfSlide = ppt.createSlide();

/** 创建一个文本框 **/

XSLFTextBox xslfTextBox = xslfSlide.createTextBox();

XSLFTextBox xslfTextBox2 = xslfSlide.createTextBox();

XSLFTextBox xslfTextBox3 = xslfSlide.createTextBox();

/** 生成一个新的文本段落 **/

XSLFTextParagraph paragraph = xslfTextBox.addNewTextParagraph();

XSLFTextParagraph paragraph2 = xslfTextBox.addNewTextParagraph();

XSLFTextParagraph paragraph3 = xslfTextBox.addNewTextParagraph();

/** 添加新的文本 **/

XSLFTextRun xslfTextRun = paragraph.addNewTextRun();

XSLFTextRun xslfTextRun2 = paragraph2.addNewTextRun();

XSLFTextRun xslfTextRun3 = paragraph3.addNewTextRun();

/** 设置内容 **/

xslfTextRun.setText("标题一");

xslfTextRun2.setText("标题二");

xslfTextRun3.setText("标题三");

/** 设置加粗 **/

xslfTextRun.setBold(true);

xslfTextRun2.setBold(true);

xslfTextRun3.setBold(true);

/** 设置颜色 **/

xslfTextRun.setFontColor(new Color(32, 33, 101));

xslfTextRun2.setFontColor(new Color(32, 33, 101));

xslfTextRun3.setFontColor(new Color(32, 33, 101));

/** 设置字体大小 **/

xslfTextRun.setFontSize(24);

xslfTextRun2.setFontSize(24);

xslfTextRun3.setFontSize(24);

/** 设置字体 **/

xslfTextRun.setFontFamily("仿宋_GB2312");

xslfTextRun2.setFontFamily("仿宋_GB2312");

xslfTextRun3.setFontFamily("仿宋_GB2312");

/** 设置斜体 和 下划线 **/

//xslfTextRun.setItalic(true);

xslfTextRun.setUnderline(true);

xslfTextRun2.setUnderline(true);

xslfTextRun3.setUnderline(true);

/** 4个参数分别为 x , y , width , height **/

xslfTextBox.setAnchor(new Rectangle(20, 30, 100, 100));

xslfTextBox2.setAnchor(new Rectangle(20, 60, 100, 100));

xslfTextBox3.setAnchor(new Rectangle(20, 90, 100, 100));

/** 输出文件 **/

ppt.write(new FileOutputStream(filePath));

}

}

插画

读书感悟

日本电影《只是爱着你》

她习惯于说谎,可是这样的谎言却再也听不到了。

我只是想让我喜欢的人所喜欢的人喜欢我而已。

任何时候,离别都比预期来得早,便如此,大家还是笑着说:“再见,总有一天会再见;再见,我们会在别处相见!”所以我虽然离你很远很远,但还是想说:再见,总有一天我们会在别处相见!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值