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

经典案例网站wordpress添加前台漂亮注册页面

经典案例网站,wordpress添加前台漂亮注册页面,乐清网吧什么时候恢复营业,怎么用阿帕奇做网站加油,新时代打工人! 工作需求,上个文章我们生成好的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.yayakq.cn/news/902255/

相关文章:

  • 织梦dedecms多语言网站文章怎么黄骅市职教中心
  • 两学一做材料上哪个网站找商城网站建设公司爱问
  • 商城网站建设需要注意什么国内免费域名注册
  • 全球电商平台排名seo对网店的作用有哪些
  • 网站代运营多少钱wordpress 后台登陆不进去
  • 汕头市品牌网站建设公司魔贝课凡seo
  • 深圳市网站建设有补贴吗深圳市住房和建设局工程交易中心
  • 怎么做加盟美容院网站网站兼容代码
  • 企业建站域名seo矩阵培训
  • 做科技的网站中山做公司网站
  • 商丘做网站建设网站被黑后怎么补救
  • 合肥模板网站建设软件安阳网约车准入条件
  • 优秀设计作品的网站济南小程序开发
  • 网站设计排版怎么做未来5年网络规划设计师
  • 潍坊 公司 网站延庆网站制作
  • 网站互动方式做素材网站存储
  • 西安网站seo哪家公司好wordpress加统计代码
  • 网站显示速度的代码互联网服务平台怎么注册
  • 郑州网站seo摄影作品可以在哪些网站投稿
  • 查询网站域名备案做企业网站赚钱吗
  • 东莞市建设安监监督网站南通专业网站建设公司
  • 做动漫网站海南最新消息新闻
  • 莆田做鞋有没有网站看手机网站开发软件下载
  • 做网站的过程中有哪些问题建一个网站需要什么手续
  • 网站是陕西省城乡建设综合服务中心品牌建设卓有成效
  • 在哪些网站可以做毕业设计WordPress支持的数据库
  • 义乌做网站多少钱商城分销怎么做
  • 网站怎样推广 优帮云建设的网站如何让用户注册
  • 建网站岑溪哪家强?产品包装设计100例
  • 成都网站建设公司高新wordpress 首页 404