java word书签_java poi XWPF word - 在新文档中创建书签 (java poi XWPF word - create bookmark in new document)...

英文原文

This is not implemented in high level classes of apache poi until now. Therefore low level CTP and CTBookmark are needed.

Example:

import java.io.FileOutputStream;

import org.apache.poi.xwpf.usermodel.*;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;

import java.math.BigInteger;

public class CreateWordBookmark {

public static void main(String[] args) throws Exception {

XWPFDocument document = new XWPFDocument();

XWPFParagraph paragraph = document.createParagraph();

//bookmark before the run

CTBookmark bookmark = paragraph.getCTP().addNewBookmarkStart();

bookmark.setName("before_testing_string");

bookmark.setId(BigInteger.valueOf(0));

paragraph.getCTP().addNewBookmarkEnd().setId(BigInteger.valueOf(0));

//bookmark the run

bookmark = paragraph.getCTP().addNewBookmarkStart();

bookmark.setName("testing_string");

bookmark.setId(BigInteger.valueOf(1));

XWPFRun run = paragraph.createRun();

run.setText("testing string ");

paragraph.getCTP().addNewBookmarkEnd().setId(BigInteger.valueOf(1));

//bookmark after the run

bookmark = paragraph.getCTP().addNewBookmarkStart();

bookmark.setName("after_testing_string");

bookmark.setId(BigInteger.valueOf(2));

paragraph.getCTP().addNewBookmarkEnd().setId(BigInteger.valueOf(2));

document.write(new FileOutputStream("CreateWordBookmark.docx"));

document.close();

}

}

中文翻译

直到现在,这还没有在apache poi的高级类中实现。因此低级CTP和CTBookmark。

示例:

import java.io.FileOutputStream;

import org.apache.poi.xwpf.usermodel。*;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;

import java.math.BigInteger;

公共类CreateWordBookmark {

public static void main(String [] args)throws Exception {

XWPFDocument document = new XWPFDocument();

XWPFParagraph段落= document.createParagraph();

//运行之前的书签

CTBookmark bookmark = paragraph.getCTP()。addNewBookmarkStart();

bookmark.setName( " before_testing_string" );

bookmark.setId(BigInteger.valueOf(0));

。paragraph.getCTP()addNewBookmarkEnd()SETID(BigInteger.valueOf(0))。

//为运行添加书签

bookmark = paragraph.getCTP()。addNewBookmarkStart();

bookmark.setName( " testing_string" );

bookmark.setId(BigInteger.valueOf(1));

XWPFRun run = paragraph.createRun();

run.setText(" testing string" );

。paragraph.getCTP()addNewBookmarkEnd()SETID(BigInteger.valueOf(1))。

//运行后的书签

bookmark = paragraph.getCTP()。addNewBookmarkStart();

bookmark.setName( " after_testing_string" );

bookmark.setId(BigInteger.valueOf(2));

。paragraph.getCTP()addNewBookmarkEnd()SETID(BigInteger.valueOf(2))。

document.write(new FileOutputStream(" CreateWordBookmark.docx" ));

document.close();

}

}

This is not implemented in high level classes of apache poi until now. Therefore low level CTP and CTBookmark are needed.

Example:

import java.io.FileOutputStream;

import org.apache.poi.xwpf.usermodel.*;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;

import java.math.BigInteger;

public class CreateWordBookmark {

public static void main(String[] args) throws Exception {

XWPFDocument document = new XWPFDocument();

XWPFParagraph paragraph = document.createParagraph();

//bookmark before the run

CTBookmark bookmark = paragraph.getCTP().addNewBookmarkStart();

bookmark.setName("before_testing_string");

bookmark.setId(BigInteger.valueOf(0));

paragraph.getCTP().addNewBookmarkEnd().setId(BigInteger.valueOf(0));

//bookmark the run

bookmark = paragraph.getCTP().addNewBookmarkStart();

bookmark.setName("testing_string");

bookmark.setId(BigInteger.valueOf(1));

XWPFRun run = paragraph.createRun();

run.setText("testing string ");

paragraph.getCTP().addNewBookmarkEnd().setId(BigInteger.valueOf(1));

//bookmark after the run

bookmark = paragraph.getCTP().addNewBookmarkStart();

bookmark.setName("after_testing_string");

bookmark.setId(BigInteger.valueOf(2));

paragraph.getCTP().addNewBookmarkEnd().setId(BigInteger.valueOf(2));

document.write(new FileOutputStream("CreateWordBookmark.docx"));

document.close();

}

}

直到现在,这还没有在apache poi的高级类中实现。因此低级CTP和CTBookmark。

示例:

import java.io.FileOutputStream;

import org.apache.poi.xwpf.usermodel。*;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;

import java.math.BigInteger;

公共类CreateWordBookmark {

public static void main(String [] args)throws Exception {

XWPFDocument document = new XWPFDocument();

XWPFParagraph段落= document.createParagraph();

//运行之前的书签

CTBookmark bookmark = paragraph.getCTP()。addNewBookmarkStart();

bookmark.setName( " before_testing_string" );

bookmark.setId(BigInteger.valueOf(0));

。paragraph.getCTP()addNewBookmarkEnd()SETID(BigInteger.valueOf(0))。

//为运行添加书签

bookmark = paragraph.getCTP()。addNewBookmarkStart();

bookmark.setName( " testing_string" );

bookmark.setId(BigInteger.valueOf(1));

XWPFRun run = paragraph.createRun();

run.setText(" testing string" );

。paragraph.getCTP()addNewBookmarkEnd()SETID(BigInteger.valueOf(1))。

//运行后的书签

bookmark = paragraph.getCTP()。addNewBookmarkStart();

bookmark.setName( " after_testing_string" );

bookmark.setId(BigInteger.valueOf(2));

。paragraph.getCTP()addNewBookmarkEnd()SETID(BigInteger.valueOf(2))。

document.write(new FileOutputStream(" CreateWordBookmark.docx" ));

document.close();

}

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值