Apache POI - 如何为 XWPFRun 设置字符间距
Apache POI - How to set character spacing for XWPFRun
我需要创建一个字符间距扩大 1 磅的 XWPFRun。我尝试了 setCharacterSpacing
和 setKerning
方法,但无济于事。我还没有找到这两种方法的代码示例或文档。
有什么建议吗?
对我来说 XWPFRun.setCharacterSpacing 有效。需要知道的是,测量单位是 TWIP
- 二十分之一英寸点。所以 1*20 是 1 pt.
示例:
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.*;
public class CreateXWPFRunCharacterSpacing {
public static void main(String[] args) throws Exception {
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("This is sample text to compare character spacing.");
paragraph = document.createParagraph();
run = paragraph.createRun();
run.setText("This is sample text to compare character spacing.");
run.setCharacterSpacing(1*20); // measurement unit is TWIPS - twentieths of a point. So 1*20 is 1 pt.
FileOutputStream out = new FileOutputStream("CreateXWPFRunCharacterSpacing.docx");
document.write(out);
out.close();
document.close();
}
}
我需要创建一个字符间距扩大 1 磅的 XWPFRun。我尝试了 setCharacterSpacing
和 setKerning
方法,但无济于事。我还没有找到这两种方法的代码示例或文档。
有什么建议吗?
对我来说 XWPFRun.setCharacterSpacing 有效。需要知道的是,测量单位是 TWIP
- 二十分之一英寸点。所以 1*20 是 1 pt.
示例:
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.*;
public class CreateXWPFRunCharacterSpacing {
public static void main(String[] args) throws Exception {
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("This is sample text to compare character spacing.");
paragraph = document.createParagraph();
run = paragraph.createRun();
run.setText("This is sample text to compare character spacing.");
run.setCharacterSpacing(1*20); // measurement unit is TWIPS - twentieths of a point. So 1*20 is 1 pt.
FileOutputStream out = new FileOutputStream("CreateXWPFRunCharacterSpacing.docx");
document.write(out);
out.close();
document.close();
}
}