许鹏程
2025-02-10 ef26bf4fde77ba361bcd083a769c3a1b8a229738
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.product.file.util;
 
import com.aspose.words.*;
 
import java.io.File;
 
public class AsposeTest {
    public static void main(String args[]){
        try {
            test1();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static void test1() throws Exception {
        File f=new File("e:/qq/xxx.docx");
        if(!f.exists()){
            f.getParentFile().mkdirs();
            f.createNewFile();
        }
        Document doc=new Document("e:/qq/xxx.docx");
        DocumentBuilder builder =new DocumentBuilder(doc);
        //移动至文档结尾
        builder.moveToDocumentEnd();
//        //新建分页符
//        Run pageBreakRun = new Run(doc, ControlChar.PAGE_BREAK);
//        //插入分页符
//        builder.insertNode(pageBreakRun);
        //设置字体
 
        builder.getFont().setName("Arial");
 
        builder.getFont().setBold(true);
 
        builder.getFont().setSize(10);
 
        builder.write("sssssss");
 
        doc.save("e:/qq/xxx.docx", SaveFormat.DOCX);
    }
}