From 00b070a1237576b49dea339887963228305567d1 Mon Sep 17 00:00:00 2001
From: shicf <shi_chongfu@163.com>
Date: 星期一, 17 十一月 2025 14:02:41 +0800
Subject: [PATCH] 创建word文档

---
 src/main/java/com/product/file/util/AsposeUtil.java |   64 +++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/product/file/util/AsposeUtil.java b/src/main/java/com/product/file/util/AsposeUtil.java
index c35bbfc..b21c310 100644
--- a/src/main/java/com/product/file/util/AsposeUtil.java
+++ b/src/main/java/com/product/file/util/AsposeUtil.java
@@ -5,6 +5,7 @@
 import com.aspose.slides.Presentation;
 import com.aspose.words.SaveFormat;
 import com.aspose.words.*;
+import com.aspose.words.Font;
 import com.product.core.exception.BaseException;
 import com.product.core.spring.context.SpringMVCContextHolder;
 import com.product.file.config.FileCode;
@@ -70,7 +71,68 @@
 		}
 		return result;
 	}
-
+	/**
+	 * 鍒涘缓Word
+	 * @param content
+	 * @param save_path
+	 * @throws Exception
+	 */
+	public static void createWord(StringBuilder content,String save_path) throws Exception {
+		// 楠岃瘉License
+		if (!getLicense(OFFICE_WORD)) {
+			return;
+		}
+		// 娣诲姞娈佃惤  
+		 // 鍒涘缓涓�涓柊鐨勬枃妗�
+        Document doc = new Document();
+        DocumentBuilder builder = new DocumentBuilder(doc);
+        Font font = builder.getFont();
+        font.setSize(12);
+        builder.writeln(content.toString());
+//        font.setBold(true);
+//        font.setColor(Color.BLACK);
+        
+//        font.setName("Arial");
+//        builder.write("How to Create a Rich Word Document?");
+//        builder.insertBreak(BreakType.LINE_BREAK);
+        // 鍚戞枃妗d腑娣诲姞鏍囬鍜屾钀�
+//        builder.writeln("Hello, Aspose!");
+//        builder.writeln("杩欐槸涓�涓娇鐢� Aspose 鍒涘缓鐨� Word 鏂囨。銆�");
+//        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
+//        paragraphFormat.setFirstLineIndent(12);
+//        paragraphFormat.setKeepTogether(true);
+		// 淇濆瓨鏂囨。  
+		doc.save(save_path); 
+	}
+	public static void createWordTable() throws Exception {
+		// Create a Document object
+		Document doc = new Document();
+		// Create a DocumentBuilder object
+		DocumentBuilder builder = new DocumentBuilder(doc);
+		// Create table
+		Table table = builder.startTable();
+		// Insert a cell
+		builder.insertCell();
+		table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
+		builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
+		builder.write("This is Row 1 Cell 1");
+		builder.insertCell();
+		builder.write("This is Row 1 Cell 2");
+		// End row
+		builder.endRow();
+		// start a next row and set its properties
+		builder.getRowFormat().setHeight(100);
+		builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
+		builder.insertCell();
+		builder.write("This is Row 2 Cell 1");
+		builder.insertCell();
+		builder.write("This is Row 2 Cell 2");
+		builder.endRow();
+		// End table
+		builder.endTable();
+		// Save the document
+		doc.save("Rich Word Document.docx");
+	}
 	/**
 	 * @param officePath
 	 * @param OutPutPath

--
Gitblit v1.9.2