hongchuangyanfa пре 2 година
родитељ
комит
4916de91ec

+ 116 - 21
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExpaileHtml.java

@@ -1,46 +1,141 @@
 package org.springblade.manager.controller;
 
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
+import com.aspose.cells.SaveFormat;
 import com.spire.xls.CellRange;
 import com.spire.xls.Workbook;
 import com.spire.xls.Worksheet;
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
-import org.springblade.core.tool.utils.*;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import org.springblade.common.utils.CommonUtil;
+import org.springblade.core.tool.utils.FileUtil;
+import org.springblade.core.tool.utils.IoUtil;
+import org.springblade.core.tool.utils.ResourceUtil;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.*;
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public class ExpaileHtml {
 
-    // private final IExctabCellService exctabCellService;
 
-    public static void main11(String[] args) throws Exception {
+    public static void excelToPdf(String exUrl,String pdfUrl){
+
+        org.apache.poi.ss.usermodel.Workbook ss = null;
+        ByteArrayInputStream byteArrayInputStream = null;
+        InputStream pdfInput = null;
+        ByteArrayOutputStream outReport = null, bos = null;
+        try{
+            File file1 = ResourceUtil.getFile(exUrl);
+            InputStream inputStream = new FileInputStream(file1);
+            ss = WorkbookFactory.create(inputStream);
+            for(int i = 0, l = ss.getNumberOfSheets(); i < l; i ++){
+                Sheet sheet = ss.getSheetAt(i);
+                //去掉表格虚线
+                sheet.setPrintGridlines(false);
+                //设置 整个工作表为一页
+                sheet.setFitToPage(true);
+            }
+            outReport = new ByteArrayOutputStream();
+            ss.write(outReport);
+            byteArrayInputStream = new ByteArrayInputStream(outReport.toByteArray());
+            com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(byteArrayInputStream);
+            wb.save(pdfUrl,SaveFormat.PDF);
+
+        }catch (Exception e){
+            e.printStackTrace();
+        } finally {
+            if(bos != null){
+                IoUtil.closeQuietly(bos);
+            }
+            if(outReport != null){
+                IoUtil.closeQuietly(outReport);
+            }
+            if(pdfInput != null){
+                IoUtil.closeQuietly(pdfInput);
+            }
+            if(byteArrayInputStream != null){
+                IoUtil.closeQuietly(byteArrayInputStream);
+            }
+            if(ss != null){
+                IoUtil.closeQuietly(ss);
+            }
+        }
+    }
 
- /*       Workbook wb = new Workbook();
-        File file1 = ResourceUtil.getFile("/Users/hongchuangyanfa/Downloads/C14.4.xlsx");
-        wb.loadFromMHtml(new FileInputStream(file1));
+
+    //图片压缩
+    public static void CompressImage(String imgUrl){
+        try {
+            //图片所在路径
+            BufferedImage templateImage = ImageIO.read(new File(imgUrl));
+            //原始图片的长度和宽度
+            int height = templateImage.getHeight();
+            int width = templateImage.getWidth();
+
+            //通过比例压缩
+            float scale = 0.5f;
+
+            //通过固定长度压缩
+            /*int doWithHeight = 100;
+            int dowithWidth = 300;*/
+
+            //压缩之后的长度和宽度
+            int doWithHeight = (int) (scale * height);
+            int dowithWidth = (int) (scale * width);
+
+            BufferedImage finalImage = new BufferedImage(dowithWidth, doWithHeight, BufferedImage.TYPE_INT_RGB);
+
+            finalImage.getGraphics().drawImage(templateImage.getScaledInstance(dowithWidth, doWithHeight, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
+
+
+            //图片输出路径,以及图片名
+            FileOutputStream  fileOutputStream = new FileOutputStream(imgUrl);
+            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fileOutputStream);
+            encoder.encode(finalImage);
+            fileOutputStream.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void main11(String[] args) throws Exception {
+        Workbook wb = new Workbook();
+        String excelUrl = "/Users/hongchuangyanfa/Downloads/A15 检验申请批复单.xlsx";
+        wb.loadFromMHtml(excelUrl);
         //获取工作表
         Worksheet sheet = wb.getWorksheets().get(0);
 
-         CellRange[] columns = sheet.getMergedCells();
-         for (int i = 0; i< columns.length; i++){
-             if(columns[i].getStyle().getFont().getSize()>=17){
-                 System.out.println("哈哈");
-                 break;
-             }
 
-         }*/
 
-        String data = "__";
-        System.out.println(data.length());
+
+
+      //  sheet.saveToFile(thmlUrl3,"UTF-8");
+
+
+      //  sheet.saveToFile(thmlUrl3, FileFormat.PDF);
+      //  sheet.
+
+        //获取工作表
+
+       // wb.saveToFile(thmlUrl3, FileFormat.PDF);
+
+      //  byteArrayInputStream = new ByteArrayInputStream(outReport.toByteArray());
+        /*com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(byteArrayInputStream);
+
+        bos = new ByteArrayOutputStream();
+        wb.save(bos, SaveFormat.PDF);
+        bos.flush();*/
+
+
 /*
         System.out.println("xcc");
         File file1 = ResourceUtil.getFile("/Users/hongchuangyanfa/Desktop/privateUrl/1572868137710256128.html");