开发内容记录-aspose


前言

依靠模版向word输出内容


提示:以下是本篇文章正文内容,下面案例可供参考

一、依赖

    <!-- 添加PageOffice依赖-->
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-words</artifactId>
        <classifier>jdk17</classifier>
    </dependency>

二、demo

1.引入库

代码如下(示例):

        File src = new File(filePath);//文件路径String
        String prePath = "xxx"//目标路径
        String tarPath = prePath + ".docx";//word路径
        String pdfPath = prePath + ".pdf";//pdf路径

        File target = FileUtil.copy(templatePath, tarPath, true);	//复制模版内容
        Document document = new Document(tarPath);;//生成word对象
        DocumentBuilder builder = new DocumentBuilder(document);//doc对象操作
        AsposeUtils asposeUtils = new AsposeUtils(document, builder);
        //定义书签输出必须PO_开头
        asposeUtils.moveToBookmarkWrite("PO_xx", "xx");
        // 第一个表格获取表格对象
        Table table01 = asposeUtils.getTableByBookMarkName(builder, "PO_TABLE_01");
        asposeUtils.setTable(table01);
        //新增表格行 7第几行开始
		Row startRow = table01.getRows().get(7);
        table01.insertAfter(startRow.deepClone(true), startRow);
		table01.setText(0, 0, "" + (i + 1)); //row第几行输出 col第几列输出 text内容
		// 合并单元格
		//合并行数数组
        int[] mergeNumArray = new int[gslist.size()];
        row = mergeNumArray[i] + 8;
        //第一次从第八行第一列开始
        Cell cellStartRange = table01.getRows().get(8).getCells().get(0);
        Cell cellEndRange = table01.getRows().get(row).getCells().get(0);
        mergeCells(cellStartRange, cellEndRange);
        //第一次从第八行第八列开始
        Cell cellStartRange1 = table01.getRows().get(8).getCells().get(8);
        Cell cellEndRange1 = table01.getRows().get(row - 1).getCells().get(8);
        mergeCells(cellStartRange1, cellEndRange1);
        asposeUtils.cellSetText(rowIndex, 0, "xx");//表格行 列 输出
		//word 保存
        document.save(tarPath);
        try {
        	//拿到目标对象
            Document doc = new Document(new FileInputStream(tarPath));
            doc.save(pdfPath);//转pdf保存
            log.info("word转pdf成功:{}", pdfPath);
        } catch (Exception e) {
            e.printStackTrace();
        }

总结

以上就是aspose Document 对word的操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值