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

java操作word里的表格

依赖:
<dependency><groupId>com.techCoLtd</groupId><artifactId>aspose-words-16.4.0-jdk16</artifactId><classifier>jdk16</classifier>
</dependency>/*** 删除表格及表格的行* @throws Exception*/
private static void deletedTable() throws Exception {Document doc = new Document("表格路径");Table table = doc.getFirstSection().getBody().getTables().get(0);// 删除整个表的方法table.remove();// 删除某一行 的方法if (table.getRows().getCount() > 1) { // 确保至少有两行才进行删除操作table.getRows().removeAt(0);// 删除第一行}doc.save("D:\\work\\save\\ceshi.docx");
}
/**** 读取表格的内容* @throws Exception*/
public static void readTableTxtByIndex() throws Exception {Document doc = new Document("表格路径");//获取所有的表格NodeCollection tableNodes = doc.getChildNodes(NodeType.TABLE, true);int tableCount = tableNodes.getCount();System.out.println("表格数量:{}"+ tableCount);for (int i = 0; i < tableCount; i++) {Table table = (Table)tableNodes.get(i);//按表格索引 单独写逻辑进行数据的读取 本示例中就1个表格 因此就放1个逻辑进行解析了if(0 == i){//获取表格中的所有行节点RowCollection rows = table.getRows();int rowCount = rows.getCount();System.out.println("共有表格行:{}" + rowCount);//获取每一行的单元格节点for (int j = 0; j < rowCount; j++) {Row row = rows.get(j);CellCollection cells = row.getCells();int cellsCount = cells.getCount();System.out.println("第" + j + "行有" + rowCount + "个单元格{}");for (int k = 0; k < cellsCount; k++) {Cell cell = cells.get(k);String cellText = cell.getText();System.out.println("第" + j + "行 第" + k + "个单元格的文本:{}" + cellText);}}}}
}

相关文章:

  • python3如何使用QT编写基础的对话框程序
  • 智能合约的浪潮:从区块链到业务自动化的 IT 新引擎
  • tcping工具使用指南
  • 中天互联在工业软件方面有哪些产品
  • QEMU源码全解析 —— 块设备虚拟化(27)
  • c/c++ 汇编码中的.cfi 指令有什么用途?
  • Python Docker 镜像构建完整指南:从基础到优化
  • Python实现web请求与访问
  • el-select+el-tree实现树形下拉选择
  • WebDebugX和多工具组合的移动端调试流程构建:一个混合App项目的实践案例
  • ref 应用于对象类型的一个案例
  • webgl(three.js 与 cesium 等实例应用)之浏览器渲染应用及内存释放的关联与应用
  • go-carbon v2.6.8 发布,轻量级、语义化、对开发者友好的 golang 时间处理库
  • 在 Flutter 项目中iOS 的 App 图标和 App 名称 的设置
  • Spring依赖注入的四种方式(面)
  • 集装箱残损识别系统如何检测残损?它的识别率能达到多少?
  • MySQL 索引学习笔记
  • OpenCV CUDA模块图像变形------对图像进行下采样操作函数pyrDown()
  • 基于Node.js的线上教学系统的设计与实现(源码+论文+调试+安装+售后)
  • Transformer-GRU、Transformer、CNN-GRU、GRU、CNN五模型时序预测对比
  • 广东哪家网站建设/百度seo优化服务
  • 黄页网络的推广网/如何获取网站的seo
  • 公司的网站建设 交给谁做更好些/千锋教育学费
  • 重庆做网站推广/中国互联网数据平台
  • 网站模板psd/免费seo课程
  • 网站不用域名可以吗/潍坊seo建站