java实现word格式控制
时间: 2024-01-20 17:04:33 浏览: 28
以下是Java实现word格式控制的示例:
```java
import com.aspose.words.Document;
import com.aspose.words.Font;
import com.aspose.words.Paragraph;
import com.aspose.words.Run;
public class WordFormatControl {
public static void main(String[] args) throws Exception {
// 加载现有的word文档
Document doc = new Document("input.docx");
// 获取文档中的第一个段落
Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
// 在段落中添加文本
Run run = new Run(doc, "Formatted text");
para.appendChild(run);
// 设置文本格式
Font font = run.getFont();
font.setSize(16);
font.setColor(Color.BLUE);
font.setBold(true);
// 保存文档
doc.save("output.docx");
}
}
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)