poi操作ppt创建表格

2024-02-01 02:48
文章标签 操作 ppt poi 创建表格

本文主要是介绍poi操作ppt创建表格,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

POI版本3.14。

创建powerpoint,一页ppt,里面插入两个表格。

/* ====================================================================Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements.  See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
==================================================================== */package org.apache.poi.hslf.examples;import java.awt.Color;
import java.io.FileOutputStream;import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.HSLFTable;
import org.apache.poi.hslf.usermodel.HSLFTableCell;
import org.apache.poi.hslf.usermodel.HSLFTextRun;
import org.apache.poi.sl.draw.DrawTableShape;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
import org.apache.poi.sl.usermodel.VerticalAlignment;/*** Demonstrates how to create tables** @author Yegor Kozlov*/
public final class TableDemo {public static void main(String[] args) throws Exception {//test data for the first taableString[][] txt1 = {{"INPUT FILE", "NUMBER OF RECORDS"},{"Item File", "11,559"},{"Vendor File", "502"},{"Purchase History File - # of PO\u2019s\r(12/01/04 - 05/31/06)", "12,852"},{"Purchase History File - # of PO Lines\r(12/01/04 - 05/31/06)", "53,523" },{"Total PO History Spend", "$10,172,038"}};//构造ppt对象HSLFSlideShow ppt = new HSLFSlideShow();//构造一页pptHSLFSlide slide = ppt.createSlide();//构造一个6行2列的表HSLFTable table1 = slide.createTable(6, 2);for (int i = 0; i < txt1.length; i++) {for (int j = 0; j < txt1[i].length; j++) {//获取表的单元格HSLFTableCell cell = table1.getCell(i, j);//单元格的文本域HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);//设置样式rt.setFontFamily("Arial");rt.setFontSize(10d);if(i == 0){cell.getFill().setForegroundColor(new Color(227, 227, 227));} else {rt.setBold(true);}//设置格子垂直居中cell.setVerticalAlignment(VerticalAlignment.MIDDLE);//设置格子水平居中cell.setHorizontalCentered(true);//设置格子文本cell.setText(txt1[i][j]);}}DrawTableShape dts1 = new DrawTableShape(table1);dts1.setAllBorders(1.0, Color.black);//设置第一列宽度table1.setColumnWidth(0, 300);//设置第二列宽度table1.setColumnWidth(1, 150);//页面宽度int pgWidth = ppt.getPageSize().width;//移动位置table1.moveTo((pgWidth - table1.getAnchor().getWidth())/2., 100.);//test data for the second taableString[][] txt2 = {{"Data Source"},{"CAS Internal Metrics - Item Master Summary\r" +"CAS Internal Metrics - Vendor Summary\r" +"CAS Internal Metrics - PO History Summary"}};//two rows, one columnHSLFTable table2 = slide.createTable(2, 1);for (int i = 0; i < txt2.length; i++) {for (int j = 0; j < txt2[i].length; j++) {HSLFTableCell cell = table2.getCell(i, j);HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);rt.setFontSize(10d);rt.setFontFamily("Arial");if(i == 0){cell.getFill().setForegroundColor(new Color(0, 51, 102));rt.setFontColor(Color.white);rt.setBold(true);rt.setFontSize(14d);cell.setHorizontalCentered(true);} else {rt.getTextParagraph().setBullet(true);rt.setFontSize(12d);rt.getTextParagraph().setTextAlign(TextAlign.LEFT);cell.setHorizontalCentered(false);}cell.setVerticalAlignment(VerticalAlignment.MIDDLE);cell.setText(txt2[i][j]);}}table2.setColumnWidth(0, 300);table2.setRowHeight(0, 30);table2.setRowHeight(1, 70);DrawTableShape dts2 = new DrawTableShape(table2);dts2.setOutsideBorders(Color.black, 1.0);table2.moveTo(200, 400);FileOutputStream out = new FileOutputStream("hslf-table.ppt");ppt.write(out);out.close();ppt.close();}
}


这篇关于poi操作ppt创建表格的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/665852

相关文章

mysql表操作与查询功能详解

《mysql表操作与查询功能详解》本文系统讲解MySQL表操作与查询,涵盖创建、修改、复制表语法,基本查询结构及WHERE、GROUPBY等子句,本文结合实例代码给大家介绍的非常详细,感兴趣的朋友跟随... 目录01.表的操作1.1表操作概览1.2创建表1.3修改表1.4复制表02.基本查询操作2.1 SE

c++中的set容器介绍及操作大全

《c++中的set容器介绍及操作大全》:本文主要介绍c++中的set容器介绍及操作大全,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录​​一、核心特性​​️ ​​二、基本操作​​​​1. 初始化与赋值​​​​2. 增删查操作​​​​3. 遍历方

MySQL追踪数据库表更新操作来源的全面指南

《MySQL追踪数据库表更新操作来源的全面指南》本文将以一个具体问题为例,如何监测哪个IP来源对数据库表statistics_test进行了UPDATE操作,文内探讨了多种方法,并提供了详细的代码... 目录引言1. 为什么需要监控数据库更新操作2. 方法1:启用数据库审计日志(1)mysql/mariad

springboot如何通过http动态操作xxl-job任务

《springboot如何通过http动态操作xxl-job任务》:本文主要介绍springboot如何通过http动态操作xxl-job任务的问题,具有很好的参考价值,希望对大家有所帮助,如有错... 目录springboot通过http动态操作xxl-job任务一、maven依赖二、配置文件三、xxl-

Oracle 数据库数据操作如何精通 INSERT, UPDATE, DELETE

《Oracle数据库数据操作如何精通INSERT,UPDATE,DELETE》在Oracle数据库中,对表内数据进行增加、修改和删除操作是通过数据操作语言来完成的,下面给大家介绍Oracle数... 目录思维导图一、插入数据 (INSERT)1.1 插入单行数据,指定所有列的值语法:1.2 插入单行数据,指

SQL中JOIN操作的条件使用总结与实践

《SQL中JOIN操作的条件使用总结与实践》在SQL查询中,JOIN操作是多表关联的核心工具,本文将从原理,场景和最佳实践三个方面总结JOIN条件的使用规则,希望可以帮助开发者精准控制查询逻辑... 目录一、ON与WHERE的本质区别二、场景化条件使用规则三、最佳实践建议1.优先使用ON条件2.WHERE用

Linux链表操作方式

《Linux链表操作方式》:本文主要介绍Linux链表操作方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、链表基础概念与内核链表优势二、内核链表结构与宏解析三、内核链表的优点四、用户态链表示例五、双向循环链表在内核中的实现优势六、典型应用场景七、调试技巧与

Java Multimap实现类与操作的具体示例

《JavaMultimap实现类与操作的具体示例》Multimap出现在Google的Guava库中,它为Java提供了更加灵活的集合操作,:本文主要介绍JavaMultimap实现类与操作的... 目录一、Multimap 概述Multimap 主要特点:二、Multimap 实现类1. ListMult

C#实现将Office文档(Word/Excel/PDF/PPT)转为Markdown格式

《C#实现将Office文档(Word/Excel/PDF/PPT)转为Markdown格式》Markdown凭借简洁的语法、优良的可读性,以及对版本控制系统的高度兼容性,逐渐成为最受欢迎的文档格式... 目录为什么要将文档转换为 Markdown 格式使用工具将 Word 文档转换为 Markdown(.

Python中文件读取操作漏洞深度解析与防护指南

《Python中文件读取操作漏洞深度解析与防护指南》在Web应用开发中,文件操作是最基础也最危险的功能之一,这篇文章将全面剖析Python环境中常见的文件读取漏洞类型,成因及防护方案,感兴趣的小伙伴可... 目录引言一、静态资源处理中的路径穿越漏洞1.1 典型漏洞场景1.2 os.path.join()的陷