shicf
3 天以前 00b070a1237576b49dea339887963228305567d1
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);
        // 向文档中添加标题和段落
//        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