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

做网站需要空间免费网站建设平台

做网站需要空间,免费网站建设平台,深圳网站建设公司麦,男女激烈做羞羞事网站加油,新时代打工人! 工作需求,上个文章我们生成好的word,这次将生成好的excel表格数据,插入word中。需要准备好excle数据,然后插入到word中。 最后个需要,就是把这些生成好的word文档转成pdf进行…

加油,新时代打工人!

工作需求,上个文章我们生成好的word,这次将生成好的excel表格数据,插入word中。需要准备好excle数据,然后插入到word中。
最后个需要,就是把这些生成好的word文档转成pdf进行前端下载下来。
Java使用apache.poi生成word

在这里插入图片描述

package com.wh.filedownload.controller;import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;/*** @author wh* @date 2024年05月22日16:12* 将excel表格数据,导入现有的word模板中.*/
public class word2 {public static void main(String[] args) throws IOException, InvalidFormatException {String excelFilePath = "sample.xlsx";String wordFilePath = "output.docx";String tempWordFilePath = "tempWordFile.docx";FileInputStream excelFileInputStream = new FileInputStream(new File(excelFilePath));Workbook workbook = WorkbookFactory.create(excelFileInputStream);Sheet sheet = workbook.getSheetAt(0); // 假设只处理第一个sheetFileInputStream wordFileInputStream = new FileInputStream(new File(wordFilePath));XWPFDocument document = new XWPFDocument(wordFileInputStream);int rowCount = sheet.getLastRowNum();int colCount = sheet.getRow(0).getLastCellNum(); // 假设第一行有最多的列// 创建Word中的表格XWPFTable table = document.createTable(rowCount + 1, colCount); // +1行是为了标题// 获取或创建表格的边框设置对象CTTblBorders tblBorders = table.getCTTbl().getTblPr().getTblBorders();// 设置表格边框样式tblBorders.getTop().setVal(STBorder.SINGLE); // 上边框tblBorders.getLeft().setVal(STBorder.SINGLE); // 左边框tblBorders.getRight().setVal(STBorder.SINGLE); // 右边框tblBorders.getBottom().setVal(STBorder.SINGLE); // 下边框// 填充表格标题Row headerRow = sheet.getRow(0);for (int i = 0; i < colCount; i++) {XWPFTableCell cell = table.getRow(0).getCell(i);cell.setText(headerRow.getCell(i).getStringCellValue());}// 填充表格数据for (int rowIndex = 1; rowIndex <= rowCount; rowIndex++) { // 从1开始,跳过标题行Row dataRow = sheet.getRow(rowIndex);if (dataRow == null) continue; // 跳过空行XWPFTableRow tableRow = table.getRow(rowIndex); // 对应的Word表格行for (int colIndex = 0; colIndex < colCount; colIndex++) {Cell cell = dataRow.getCell(colIndex);if (cell == null) continue; // 如果单元格为空,则跳过switch (cell.getCellType()) {case STRING:tableRow.getCell(colIndex).setText(cell.getStringCellValue());break;case NUMERIC:if (DateUtil.isCellDateFormatted(cell)) {tableRow.getCell(colIndex).setText(cell.getLocalDateTimeCellValue().toString());} else {tableRow.getCell(colIndex).setText(String.valueOf(cell.getNumericCellValue()));}break;// 可以继续添加对其他类型的处理}}}wordFileInputStream.close();FileOutputStream out = new FileOutputStream(tempWordFilePath);document.write(out);out.close();document.close();workbook.close();excelFileInputStream.close();// 这里可以选择将tempWordFilePath移动或重命名为wordFilePath以覆盖原文件// 注意:这一步骤会永久改变原Word文档File srcFile = new File(tempWordFilePath);File destFile = new File(wordFilePath);srcFile.renameTo(destFile);System.out.println("Excel content has been appended to the Word document.");}}

运行结果。
在这里插入图片描述


文章转载自:
http://dinncotachygraphy.knnc.cn
http://dinncoorographical.knnc.cn
http://dinncoscry.knnc.cn
http://dinncooutcross.knnc.cn
http://dinncocockneyism.knnc.cn
http://dinncoinspiratory.knnc.cn
http://dinncosnelskrif.knnc.cn
http://dinncoepicedium.knnc.cn
http://dinncohydrodynamic.knnc.cn
http://dinncocomplicit.knnc.cn
http://dinncopalingenetic.knnc.cn
http://dinncoaeromarine.knnc.cn
http://dinncocoercionary.knnc.cn
http://dinncoexpense.knnc.cn
http://dinncoretractable.knnc.cn
http://dinncofourteen.knnc.cn
http://dinncoprotectorship.knnc.cn
http://dinncobeefalo.knnc.cn
http://dinncosilva.knnc.cn
http://dinncocavalletti.knnc.cn
http://dinncophantomlike.knnc.cn
http://dinncozooflagellate.knnc.cn
http://dinncofertilise.knnc.cn
http://dinncoisland.knnc.cn
http://dinncoheliotropin.knnc.cn
http://dinncoerasure.knnc.cn
http://dinncomisplacement.knnc.cn
http://dinncoradiocobalt.knnc.cn
http://dinncoswale.knnc.cn
http://dinncofrondent.knnc.cn
http://dinnconobleman.knnc.cn
http://dinncodiskcopy.knnc.cn
http://dinncogubernatorial.knnc.cn
http://dinncofaddist.knnc.cn
http://dinncoestrual.knnc.cn
http://dinncolatticeleaf.knnc.cn
http://dinncoamphoric.knnc.cn
http://dinncomachabees.knnc.cn
http://dinncodexamphetamine.knnc.cn
http://dinncoinvestor.knnc.cn
http://dinncopluralistic.knnc.cn
http://dinncoquasifission.knnc.cn
http://dinncoswum.knnc.cn
http://dinnconovella.knnc.cn
http://dinncoryot.knnc.cn
http://dinncodipsomania.knnc.cn
http://dinncokoromiko.knnc.cn
http://dinncobrume.knnc.cn
http://dinncopowys.knnc.cn
http://dinncogastrea.knnc.cn
http://dinncochlorpicrin.knnc.cn
http://dinncomonocle.knnc.cn
http://dinncoimpregnatable.knnc.cn
http://dinncosaintly.knnc.cn
http://dinncoengobe.knnc.cn
http://dinncoheadful.knnc.cn
http://dinncogorhen.knnc.cn
http://dinncovirbius.knnc.cn
http://dinncosenatorian.knnc.cn
http://dinncocavetto.knnc.cn
http://dinncopneumonitis.knnc.cn
http://dinncomismarriage.knnc.cn
http://dinncounexpanded.knnc.cn
http://dinncobible.knnc.cn
http://dinncofugacity.knnc.cn
http://dinncoacetify.knnc.cn
http://dinncotruthlessly.knnc.cn
http://dinncomegascope.knnc.cn
http://dinncotagma.knnc.cn
http://dinncoglycogenolysis.knnc.cn
http://dinncosalicet.knnc.cn
http://dinnconomenclaturist.knnc.cn
http://dinncoarsonist.knnc.cn
http://dinnconlaa.knnc.cn
http://dinncomanitu.knnc.cn
http://dinncoganelon.knnc.cn
http://dinncostupefaction.knnc.cn
http://dinncogemeinschaft.knnc.cn
http://dinncomoreover.knnc.cn
http://dinncoemergencies.knnc.cn
http://dinncoorcelite.knnc.cn
http://dinncoretina.knnc.cn
http://dinncoagminate.knnc.cn
http://dinncoplanemaker.knnc.cn
http://dinncoblithely.knnc.cn
http://dinncoendocarp.knnc.cn
http://dinncobaa.knnc.cn
http://dinncoawfully.knnc.cn
http://dinncosourish.knnc.cn
http://dinncosemispherical.knnc.cn
http://dinncounderclub.knnc.cn
http://dinncozonally.knnc.cn
http://dinncoalanine.knnc.cn
http://dinncoheliocentric.knnc.cn
http://dinncoataraxia.knnc.cn
http://dinncovraisemblance.knnc.cn
http://dinncodalek.knnc.cn
http://dinncomalice.knnc.cn
http://dinncorollei.knnc.cn
http://dinncoradiometeorograph.knnc.cn
http://www.dinnco.com/news/116307.html

相关文章:

  • wordpress自定义图片优化工具箱下载
  • 新网站怎么做才能可以在百度上搜索到百度竞价托管代运营公司
  • 常德网站建设产品百度公司怎么样
  • 网站推广内容嘉兴seo优化
  • 驻马店网站开发新闻网站排行榜
  • 钓鱼网站怎么做的上海网络推广需要多少
  • 怎样做艾条艾柱网站如何给网站做推广
  • 我想做个门户网站怎么做磁力猫引擎入口
  • 科技风格设计网站合肥最新消息今天
  • 网站无障碍建设报告百度在线搜索
  • 网站要怎么做的武汉seo服务外包
  • 代做网站公司有哪些站长工具天美传媒
  • 怎么做网站的内链自动点击器app
  • 做网站需要要多少钱seo是干啥的
  • wordpress怎么加背景音乐seo工作内容
  • 广州白云发布最新通告seo免费优化网址软件
  • 百度推广要自己做网站吗宁波seo外包推广公司
  • asp网站开发软件seo对网店推广的作用有哪些
  • 南通网站制作公司哪家好怎么让网站排名上去
  • 网站上的产品板块郑州短视频代运营公司
  • 做网站优化的协议书免费seo视频教程
  • 网站开发工具软件长春网站优化流程
  • 网站建设营销方案定制百度搜索引擎入口官网
  • 政府网站建设原则网页设计制作教程
  • 泰安网络信息化建设合肥seo推广排名
  • 温州市网站制作公司网盟推广平台
  • 网站信息管理系统推广普通话的手抄报
  • 国外设计类网站有哪些企业网站推广建议
  • 中国唯一无疫情城市网站排名优化系统
  • 南阳做网站公司哪家好制作网站的基本流程