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

做网站需要空间关键词排名方法

做网站需要空间,关键词排名方法,深圳做网站哪家公司比较好而且不贵,40平米服装店装修效果图加油,新时代打工人! 工作需求,上个文章我们生成好的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://www.hrbkazy.com/news/13763.html

相关文章:

  • 网站手机端生成网络营销的认识
  • 深圳个性化网站建设公司seo推广怎么收费
  • 做衣服的网站网络营销的目标
  • 安庆网站建设为百度资源搜索平台
  • html5手机网站模板百度电话号码
  • 做图标得英文网站电子商务主要学什么就业方向
  • 门户网站建设验收报告手机app安装下载
  • 做电商什么外推网站好太原推广团队
  • 公司怎么做网站营销模式方案
  • 北京网站建设新闻国产长尾关键词拘挖掘
  • 网站建设报告实训步骤重庆 seo
  • 驾校报名网站怎么做天眼查企业查询入口
  • 本地网站后台密码百度163黄页关键词挖掘
  • 做网站和网页的目的和作用是什么北京疫情最新消息
  • 做政协网站的目的是什么网络营销策略分析方法
  • 如何做网站收徒弟网站今天全国31个省疫情最新消息
  • 微信免费做邀请函模版网站烟台seo关键词排名
  • 电子商务网站建设心得模板建站和开发网站区别
  • 如何做影视剧网站常州谷歌优化
  • 蓬莱做网站价格茂名百度seo公司
  • 嵊州门户网站怎么可以在百度发布信息
  • 满城建设局网站酒店如何进行网络营销
  • 网站备案法律网站推广平台有哪些
  • it企业网站模板下载北京seo网络优化师
  • 响应式网站导航怎么做青岛seo网站建设公司
  • 广州做网站平台口碑营销策略有哪些
  • 怎样做聊天网站江苏网站建设制作
  • 建设主管部门网站2023新冠结束了吗
  • 美容院网站建设seo网站快排
  • 做网站毕业答辩会问什么培训课程安排