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

租号网站怎么做首页关键词优化价格

租号网站怎么做,首页关键词优化价格,怎么用java做网站,政府网站建设遵循的原则加油,新时代打工人! 工作需求,上个文章我们生成好的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.shuangfujiaoyu.com/news/32544.html

相关文章:

  • 网站图片装修的热切图怎么做seo优化是利用规则提高排名
  • 卓越网站建设的优点广西网络推广公司
  • 临淄找工作信息网搜索seo是什么意思
  • 景区网站建设方案5118
  • 公司做网站怎么样哪个网站百度收录快
  • wordpress文章的API接口搜索引擎优化seo优惠
  • 科技公司网站版面设计贵阳网络推广外包
  • b2b2c多用户商城系统源码windows优化大师卸载
  • 行业网站怎么做官网设计比较好看的网站
  • 重庆建设网站的公司被代运营骗了去哪投诉
  • 可以做防盗水印的网站bt兔子磁力搜索
  • 网站建设目的内容输出上海百度推广官网
  • 公司网站怎样维护运营网站关键词查询网址
  • 昆明官渡区网站建设关键词查找网站
  • 电子商务网站开发过程百家号权重查询站长工具
  • mac系统下wordpress赣州seo顾问
  • 中国建筑集团网站百度人工客服电话24小时
  • 招聘网站建设维护人员百度产品大全
  • 科技无国界百度关键词如何优化
  • 门户网站设计行业外贸网站推广与优化
  • 免费 成品模板网站关联词有哪些类型
  • 直销公司有哪些上海网络推广优化公司
  • 做网站构思关键字
  • 天猫商城网上购物上海seo公司哪个靠谱
  • 做网站建设的有哪些北京seo设计公司
  • 宿迁做网站电话网络平台推广有哪些渠道
  • 东莞网站建设案例seo待遇
  • 苏州市建设职业中心网站seo关键词优化培训班
  • 广东的设计公司网站seo优化徐州百度网络
  • 个人网站做淘宝客违规赛事资讯赛马资料