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 |   88 ++++++++++++++++++++++++++++++++++++--------
 1 files changed, 72 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/product/file/util/AsposeUtil.java b/src/main/java/com/product/file/util/AsposeUtil.java
index 25e6f39..b21c310 100644
--- a/src/main/java/com/product/file/util/AsposeUtil.java
+++ b/src/main/java/com/product/file/util/AsposeUtil.java
@@ -1,24 +1,19 @@
 package com.product.file.util;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import com.aspose.cells.Cells;
 import com.aspose.cells.PdfSaveOptions;
-import com.aspose.cells.Workbook;
-import com.aspose.cells.Worksheet;
-import com.aspose.cells.WorksheetCollection;
+import com.aspose.cells.*;
 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;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 public class AsposeUtil {
 	private static int OFFICE_XLS = 1;
@@ -76,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
@@ -293,8 +349,8 @@
 			if (officeType.equals("doc") || officeType.equals("docx")) {
 				Word2Pdf(officePath, outFile);
 			} else if (officeType.equals("xls") || officeType.equals("xlsx")) {
-//                Excel2Pdf(officePath,outFile);
-				Excel2Html(officePath, outFile);
+                Excel2Pdf(officePath,outFile);
+//				Excel2Html(officePath, outFile);
 //                xls2xlsx(officePath,outFile,officeType);
 			} else if (officeType.equals("ppt") || officeType.equals("pptx")) {
 				PPT2Pdf(officePath, outFile);

--
Gitblit v1.9.2