许鹏程
2023-06-13 c0b60dbd5791d499c037c2f7c8cdfc9760353bb3
src/main/java/com/product/file/util/AsposeUtil.java
@@ -24,8 +24,10 @@
public class AsposeUtil {
   //是否初始了license
   private static boolean isInitLicense=false;
    /**
     * 获取license
    *
     * @return
     */
    public static boolean getLicense(int type)throws BaseException {
@@ -63,8 +65,8 @@
      }
        return result;
    }
    /**
     *
     * @param officePath
     * @param OutPutPath
     * @throws BaseException
@@ -99,6 +101,7 @@
         }
      }
    }
    public static void Excel2Html(String officePath,String OutPutPath)throws BaseException {
        // 验证License
        if (!getLicense(1)) {
@@ -131,28 +134,27 @@
         }
      }
    }
    /**
     * 设置单元格的自动适宽、高
    *
     * @param sheet
     * @throws Exception
     */
    public static void setAutoWithHeight(Worksheet sheet)throws Exception
    {
   public static void setAutoWithHeight(Worksheet sheet) throws Exception {
        Cells cells =sheet.getCells();
        int columnCount = cells.getMaxColumn();  //获取表页的最大列数
        int rowCount = cells.getMaxRow();        //获取表页的最大行数
        if(columnCount<0 ||rowCount<0 )return ;
        for (int col = 0; col < columnCount; col++)
        {
      for (int col = 0; col < columnCount; col++) {
            sheet.autoFitColumn(col, 0, rowCount);
        }
        for (int row = 0; row < rowCount; row++)
        {
      for (int row = 0; row < rowCount; row++) {
            sheet.autoFitRow(row, 0, columnCount);
        }
    }
    /**
     *
     * @param officePath
     * @param OutPutPath
     * @throws BaseException
@@ -184,8 +186,8 @@
         }
      }
    }
    /**
     *
     * @param officePath
     * @param OutPutPath
     * @throws BaseException
@@ -218,8 +220,10 @@
         }
      }
    }
    /**
     * 文档转换
    *
     * @param officePath
     * @param outFile
     * @return
@@ -249,8 +253,10 @@
        }
        return outFile;
    }
    /**
     * 文档转换
    *
     * @param officePath
     * @return
     */
@@ -304,8 +310,10 @@
        }
        return OutPutPath+officeName;
    }
    /**
     * word文档的合并
    *
     * @param targetWordFile
     * @param sourceWordFile
     * @return
@@ -316,8 +324,15 @@
       File source=new File(sourceWordFile);
       return mergeWord(target,source);
    }
   public static void main(String args[]) {
      String file = "E:/work/沄崃/FE6.6产品报价工具-新 - 副本.xlsx";
      AsposeUtil.OfficeToPdf(file);
   }
    /**
     * word文档的合并
    *
     * @param targetWordFile
     * @param sourceWordFile
     * @return
@@ -349,17 +364,15 @@
          targetDoc.appendDocument(sourceDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
          File dir=new File(temp);
          if(!dir.exists()) {
             if(dir.mkdirs()) {
            dir.mkdirs();
         }
                if(temp_target.createNewFile()) {
                   out=new FileOutputStream(temp_target);
                   targetDoc.save(out, SaveFormat.DOCX);
                }
             }
          }
       }catch(Exception e) {
          throw new BaseException(FileCode.DOC_MERGE_FALL,e);
       }
       finally{
      } finally {
          try {
             if(tin!=null) {
               tin.close();
@@ -376,9 +389,5 @@
         }
      }
       return temp_target;
    }
    public static void main(String args[]) {
       String file="E:/work/沄崃/FE6.6产品报价工具-新 - 副本.xlsx";
       AsposeUtil.OfficeToPdf(file);
    }
}