| | |
| | | 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; |
| | |
| | | } |
| | | 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 |
| | |
| | | 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); |