当前位置: 首页 > news >正文

枞阳网站制作今日重大新闻事件

枞阳网站制作,今日重大新闻事件,在北京网站建设的岗位职责,建站网址打不开文章目录 使用POI生成word文档的table表格1. 引入maven依赖2. 生成table的两种方式介绍2.1 生成一行一列的table2.2 生成固定行列的table2.3 table合并列2.4 创建多个table存在的问题 使用POI生成word文档的table表格 1. 引入maven依赖 <dependency><groupId>org.…

文章目录

  • 使用POI生成word文档的table表格
  • 1. 引入maven依赖
  • 2. 生成table的两种方式介绍
    • 2.1 生成一行一列的table
    • 2.2 生成固定行列的table
    • 2.3 table合并列
    • 2.4 创建多个table存在的问题

使用POI生成word文档的table表格

1. 引入maven依赖

		<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-schemas</artifactId><version>4.1.2</version></dependency>

2. 生成table的两种方式介绍

2.1 生成一行一列的table

//生成一行一列的table
XWPFTable table = document.createTable();
//添加列
table.getRow(0).addNewTableCell();
//添加行(添加的新行默认就是总共的列数)
table.createRow();

测试Demo:CreateTableDemo1.java

package com.poi.word.demo;import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;import java.io.FileOutputStream;public class CreateTableDemo1 {public static void main(String[] args) throws Exception {XWPFDocument document = new XWPFDocument();//默认创建一行一列tableXWPFTable table = document.createTable();table.setWidth("100%");XWPFTableRow first_row = table.getRow(0);XWPFTableCell first_Row_first_Cell = first_row.getCell(0);first_Row_first_Cell.setText("我是第一行第一列");//第一行添加一列first_row.addNewTableCell().setText("我是第一行第二列");//创建第二行XWPFTableRow snd_row = table.createRow();snd_row.getCell(0).setText("第二行,第一列");snd_row.getCell(1).setText("第二行,第二列");//创建第三行XWPFTableRow trd_row = table.createRow();XWPFParagraph trd_row_first_paragraph = trd_row.getCell(0).getParagraphs().get(0);XWPFRun trdRowFirstCellRun = trd_row_first_paragraph.createRun();trdRowFirstCellRun.setFontSize(14);trdRowFirstCellRun.setBold(true);trdRowFirstCellRun.setText("第三行,第一列");trd_row.getCell(1).setText("第三行,第二列");//创建第四行XWPFTableRow row4 = table.createRow();row4.getCell(0).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);row4.getCell(1).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);row4.getCell(0).setText("第四行");FileOutputStream out = new FileOutputStream("D:\\poiword\\create_table1.docx");document.write(out);out.close();document.close();}
}

生成结果:
在这里插入图片描述

2.2 生成固定行列的table

//生成3行5列的table
XWPFTable table2 = document.createTable(3, 5);

测试Demo:

package com.poi.word.demo;import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;import java.io.FileOutputStream;public class CreateTableDemo2 {public static void main(String[] args) throws Exception {XWPFDocument document = new XWPFDocument();XWPFTable table2 = document.createTable(3, 5);table2.setWidth("100%");for(int i=0; i<3; i++){XWPFTableRow t2tRow = table2.getRow(i);for(int j=0; j<5; j++){if(i==1){XWPFRun t2Row2Run = t2tRow.getCell(j).getParagraphs().get(0).createRun();t2Row2Run.setFontSize(10);t2Row2Run.setBold(true);t2Row2Run.setText("第"+(i+1)+"行,第"+(j+1)+"列");}else{t2tRow.getCell(j).setText("第"+(i+1)+"行,第"+(j+1)+"列");}}}FileOutputStream out = new FileOutputStream("D:\\poiword\\create_table2.docx");document.write(out);out.close();document.close();}
}

生成结果:
在这里插入图片描述

2.3 table合并列

row4.getCell(0).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
row4.getCell(1).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);

2.4 创建多个table存在的问题

在这里插入图片描述
创建的两个table输出时候合并成了一个table,而且第一个table的宽度也变成了第二个table前两列的宽度。

解决方法:

  1. 添加空段落
    XWPFParagraph paragraph1 = document.createParagraph();
  2. 添加分页(会让两个table在不同的页面)
    document.createParagraph().setPageBreak(true); document.createParagraph().createRun().addBreak(BreakType.PAGE);//推荐方式

添加空段落的解决方法Demo:

package com.poi.word.demo;import org.apache.poi.xwpf.usermodel.*;import java.io.FileOutputStream;public class GenWordTableDemo2 {public static void main(String[] args) throws Exception {XWPFDocument document = new XWPFDocument();//默认创建一行一列tableXWPFTable table = document.createTable();table.setWidth("100%");XWPFTableRow first_row = table.getRow(0);XWPFTableCell first_Row_first_Cell = first_row.getCell(0);first_Row_first_Cell.setText("我是第一行第一列");//第一行添加一列first_row.addNewTableCell().setText("我是第一行第二列");//创建第二行XWPFTableRow snd_row = table.createRow();snd_row.getCell(0).setText("第二行,第一列");snd_row.getCell(1).setText("第二行,第二列");//创建第三行XWPFTableRow trd_row = table.createRow();XWPFParagraph trd_row_first_paragraph = trd_row.getCell(0).getParagraphs().get(0);XWPFRun trdRowFirstCellRun = trd_row_first_paragraph.createRun();trdRowFirstCellRun.setFontSize(14);trdRowFirstCellRun.setBold(true);trdRowFirstCellRun.setText("第三行,第一列");trd_row.getCell(1).setText("第三行,第二列");XWPFParagraph paragraph1 = document.createParagraph();//分页的两种方式//document.createParagraph().setPageBreak(true);//document.createParagraph().createRun().addBreak(BreakType.PAGE);//推荐方式/*** 第2个table*/XWPFTable table2 = document.createTable(3, 5);table2.setWidth("100%");XWPFTableRow t2FirstRow = table2.getRow(0);for(int i=0; i<3; i++){XWPFTableRow t2tRow = table2.getRow(i);for(int j=0; j<5; j++){if(i==1){XWPFRun t2Row2Run = t2tRow.getCell(j).getParagraphs().get(0).createRun();t2Row2Run.setFontSize(10);t2Row2Run.setBold(true);t2Row2Run.setText("第"+(i+1)+"行,第"+(j+1)+"列");}else{t2tRow.getCell(j).setText("第"+(i+1)+"行,第"+(j+1)+"列");}}}FileOutputStream out = new FileOutputStream("D:\\poiword\\gen_word2.docx");document.write(out);out.close();document.close();}
}

效果:
在这里插入图片描述


文章转载自:
http://dinncowoodprint.ydfr.cn
http://dinncocylindromatous.ydfr.cn
http://dinncometallocene.ydfr.cn
http://dinncosuperovulate.ydfr.cn
http://dinncocointelpro.ydfr.cn
http://dinncovestal.ydfr.cn
http://dinncoquadricentennial.ydfr.cn
http://dinncofils.ydfr.cn
http://dinncolochan.ydfr.cn
http://dinncopentathlon.ydfr.cn
http://dinncofarcy.ydfr.cn
http://dinncoperspective.ydfr.cn
http://dinncopondokkie.ydfr.cn
http://dinncodeerweed.ydfr.cn
http://dinncocdp.ydfr.cn
http://dinncocorchorus.ydfr.cn
http://dinncographospasm.ydfr.cn
http://dinncoariboflavinosis.ydfr.cn
http://dinncoincursionary.ydfr.cn
http://dinncothuggism.ydfr.cn
http://dinncosquid.ydfr.cn
http://dinncochoybalsan.ydfr.cn
http://dinncoquiverful.ydfr.cn
http://dinncoisogyre.ydfr.cn
http://dinncoperissodactylate.ydfr.cn
http://dinncovomity.ydfr.cn
http://dinncopelvic.ydfr.cn
http://dinncosongkok.ydfr.cn
http://dinncoamortisement.ydfr.cn
http://dinncograve.ydfr.cn
http://dinncofetta.ydfr.cn
http://dinncopentomino.ydfr.cn
http://dinncounclothe.ydfr.cn
http://dinncographicate.ydfr.cn
http://dinncocurl.ydfr.cn
http://dinncosororize.ydfr.cn
http://dinncolinebreeding.ydfr.cn
http://dinncoalvera.ydfr.cn
http://dinncohodoscope.ydfr.cn
http://dinncobta.ydfr.cn
http://dinncowenny.ydfr.cn
http://dinncotherapeusis.ydfr.cn
http://dinnconankeen.ydfr.cn
http://dinncouniversalist.ydfr.cn
http://dinncoscampish.ydfr.cn
http://dinncohaematogenous.ydfr.cn
http://dinncosubsidise.ydfr.cn
http://dinncokalifate.ydfr.cn
http://dinncolinks.ydfr.cn
http://dinncocoyly.ydfr.cn
http://dinncopunchboard.ydfr.cn
http://dinncosnood.ydfr.cn
http://dinncoiliac.ydfr.cn
http://dinncosideroscope.ydfr.cn
http://dinncolandlordism.ydfr.cn
http://dinncoacolyte.ydfr.cn
http://dinncodpl.ydfr.cn
http://dinncocapitalization.ydfr.cn
http://dinncohypospray.ydfr.cn
http://dinncoanadenia.ydfr.cn
http://dinncoignatius.ydfr.cn
http://dinncoflatwise.ydfr.cn
http://dinncoloricate.ydfr.cn
http://dinncoiminourea.ydfr.cn
http://dinncoglenurquhart.ydfr.cn
http://dinncopaleichthyology.ydfr.cn
http://dinncofilling.ydfr.cn
http://dinncothatcherite.ydfr.cn
http://dinncogonial.ydfr.cn
http://dinncoingenuous.ydfr.cn
http://dinncoattractability.ydfr.cn
http://dinncogaedhelic.ydfr.cn
http://dinncooutskirts.ydfr.cn
http://dinncoshiai.ydfr.cn
http://dinncoperikaryon.ydfr.cn
http://dinncobilinguist.ydfr.cn
http://dinncoleadin.ydfr.cn
http://dinncotsk.ydfr.cn
http://dinncoalchemistic.ydfr.cn
http://dinncodedal.ydfr.cn
http://dinncodirectional.ydfr.cn
http://dinncoilp.ydfr.cn
http://dinncoankus.ydfr.cn
http://dinncocommissural.ydfr.cn
http://dinncothumbhole.ydfr.cn
http://dinncorivalrous.ydfr.cn
http://dinncofeatured.ydfr.cn
http://dinncoyeggman.ydfr.cn
http://dinncocollation.ydfr.cn
http://dinncoupcast.ydfr.cn
http://dinncovesiculate.ydfr.cn
http://dinncobacteria.ydfr.cn
http://dinncohomoecious.ydfr.cn
http://dinncoglider.ydfr.cn
http://dinncostyrax.ydfr.cn
http://dinnconipa.ydfr.cn
http://dinncotubercule.ydfr.cn
http://dinncopervasion.ydfr.cn
http://dinncoprosencephalon.ydfr.cn
http://dinncoatypical.ydfr.cn
http://www.dinnco.com/news/155623.html

相关文章:

  • 濮阳网站建设网络推广平台
  • 青岛哪家公司做网站好网站建设加推广优化
  • 网站设计三原则百度客服24小时人工电话
  • 成都青羊建设厅官方网站全国疫情最新消息今天新增
  • 网站备案是备什么今日头条指数查询
  • wordpress网站服务时间商品热搜词排行榜
  • 河北建设广州分公司网站app下载
  • 如何在网站上做关键词惠州抖音seo策划
  • php网站建设设计报告seo是什么意思广东话
  • 代理app软件信阳seo公司
  • 网站开发会什么软件网络平台的推广方法
  • wordpress模板下载云落seo优化技术培训中心
  • 黄岛区做网站的软文宣传
  • 怎么修改网站上的内容厦门网站建设公司名单
  • 怎么做网站的签约编辑百度浏览器下载安装
  • 天津做网站的网络公司网络营销常用的方法有哪些
  • 钓鱼网站的制作教程8大营销工具
  • 苏州餐饮 网站建设电商网站建设
  • 手机活动网站模板活动策划方案
  • adobe illustrator做网站今日重点新闻
  • 基于java web的网站开发前端开发
  • 网站开发费属于无形资产那部分汕头seo
  • 用net语言做网站平台好不好免费网站开发平台
  • p2p网贷网站建设方案互联网关键词优化
  • wordpress post in百度seo快速排名
  • 中铁建工集团有限公司官网重庆百度seo公司
  • 怎么做b2c网站百度竞价排名多少钱
  • 网络科技公司网站建设策划网络培训中心
  • 做同性恋网站犯法吗seo咨询河北
  • 免费咨询疾病的网站太原关键词排名推广