| | |
| | | public class AsposeUtil { |
| | | //是否初始了license |
| | | private static boolean isInitLicense=false; |
| | | |
| | | /** |
| | | * 获取license |
| | | * |
| | | * @return |
| | | */ |
| | | public static boolean getLicense(int type)throws BaseException { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param officePath |
| | | * @param OutPutPath |
| | | * @throws BaseException |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static void Excel2Html(String officePath,String OutPutPath)throws BaseException { |
| | | // 验证License |
| | | if (!getLicense(1)) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置单元格的自动适宽、高 |
| | | * |
| | | * @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 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param officePath |
| | | * @param OutPutPath |
| | | * @throws BaseException |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文档转换 |
| | | * |
| | | * @param officePath |
| | | * @param outFile |
| | | * @return |
| | |
| | | } |
| | | return outFile; |
| | | } |
| | | |
| | | /** |
| | | * 文档转换 |
| | | * |
| | | * @param officePath |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | return OutPutPath+officeName; |
| | | } |
| | | |
| | | /** |
| | | * word文档的合并 |
| | | * |
| | | * @param targetWordFile |
| | | * @param sourceWordFile |
| | | * @return |
| | |
| | | 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 |
| | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | return temp_target; |
| | | } |
| | | public static void main(String args[]) { |
| | | String file="E:/work/沄崃/FE6.6产品报价工具-新 - 副本.xlsx"; |
| | | AsposeUtil.OfficeToPdf(file); |
| | | } |
| | | } |