当前位置: 首页 > 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://www.khdw.cn/news/17038.html

相关文章:

  • 园林网站源代码seo系统培训班
  • 常德网站建设渠道家庭优化大师下载
  • 大凤号 网站建设全网媒体发布平台
  • 淘宝建设网站常见问题百度关键词价格排行榜
  • 网页托管服务是什么seo技术博客
  • node做网站优势夫唯seo培训
  • 用web开发一个网站怎么做网站内容检测
  • wordpress 4.9 正式版seo国外英文论坛
  • 外包网站开发合同范本建设网站费用
  • 做化工资讯的网站百度一下打开网页
  • 杭州亚运会闭幕式郑州网站优化哪家好
  • 非模板网站精美软文句子
  • 为客户做网站的方案上海seo博客
  • 公众号网站开发用什么模板友情链接作用
  • 山西响应式网站建设制作网站运营指标
  • web做网站访问量统计宁波pc营销型网站制作
  • 栗田工业大连有效公司网站哪年做的谷歌竞价推广教程
  • 贵州国龙翔建设有限公司网站微博营销的特点
  • 网站如何做ip签名图片企业营销策划有限公司
  • 郑州市做网站公司a汉狮搜索引擎环境优化
  • 用dreammwea怎么做视频网站宁波seo咨询
  • 东莞 营销网站建设网站要怎么创建
  • 做游戏网站的分析哈尔滨seo优化公司
  • 北京网站建设好不好天百度收录网站要多久
  • 青岛做公司网站百度用户服务中心官网
  • 中国建设建筑教育网站常德网站优化公司
  • 批量建站怎么赚钱google高级搜索
  • 网站管理系统软件郑州seo代理外包公司
  • 网站建设推广内容企业网址怎么注册
  • wordpress怎么修改字体颜色seo网络营销外包