最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)excel/pdf/word/odt/圖片相互轉(zhuǎn)換

 更新時(shí)間:2023年04月13日 10:30:39   作者:芝麻粒兒  
這篇文章主要為大家詳細(xì)介紹了Android如何實(shí)現(xiàn)excel/pdf/word/odt/圖片之間的相互轉(zhuǎn)換,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下

實(shí)踐過(guò)程

pdf轉(zhuǎn)excel

public static long pdfToExcel(String inFile, String outFile) throws Exception {
    if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        Document doc = new Document(inFile);
        ExcelSaveOptions options = new ExcelSaveOptions();
        options.setFormat(ExcelSaveOptions.ExcelFormat.XLSX);
        doc.save(outFile, options);
        Out.print(inFile, outFile, System.currentTimeMillis(), old);
        return new File(outFile).length();
    }catch (Exception e) {
        e.printStackTrace();
        throw new Exception(e.getMessage());
    }
}

excel轉(zhuǎn)pdf

public static long excelToPdf(String inFile, String outFile) throws Exception {
    if (!com.yrnet.transfer.business.transfer.file.License.getExcelLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        File pdfFile = new File(outFile);
        Workbook wb = new Workbook(inFile);
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        pdfSaveOptions.setOnePagePerSheet(true);
        FileOutputStream fileOS = new FileOutputStream(pdfFile);
        wb.save(fileOS, SaveFormat.PDF);
        fileOS.close();
        long now = System.currentTimeMillis();
        Out.print(inFile, outFile, now, old);
        return pdfFile.length();
    }catch (Exception e) {
        e.printStackTrace();
        throw new Exception(e.getMessage());
    }
}

ppt轉(zhuǎn)pdf

public static long pptToPdf(String inFile, String outFile) throws Exception {
 if (!com.yrnet.transfer.business.transfer.file.License.getPptLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        File pdfFile = new File(outFile);
        FileOutputStream os = new FileOutputStream(pdfFile);
        Presentation pres = new Presentation(inFile);
        pres.save(os, com.aspose.slides.SaveFormat.Pdf);
        os.close();
        long now = System.currentTimeMillis();
        Out.print(inFile, outFile, now, old);
        return pdfFile.length();
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception(e.getMessage());
    }
}

pdf轉(zhuǎn)ppt

public static long pdfToPpt(String inFile, String outFile) {
   if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
        return 0;
    }
    long old = System.currentTimeMillis();
    Document pdfDocument = new Document(inFile);
    PptxSaveOptions pptxOptions = new PptxSaveOptions();
    pptxOptions.setExtractOcrSublayerOnly(true);
    pdfDocument.save(outFile, pptxOptions);
    long now = System.currentTimeMillis();
    Out.print(inFile, outFile, now, old);
    return new File(outFile).length();
}

pdf轉(zhuǎn)word

public static long pdfToDoc(String inFile, String outFile) {
  if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
        return 0;
    }
    log.info("開(kāi)始轉(zhuǎn)換...");
    long old = System.currentTimeMillis();
    Document pdfDocument = new Document(inFile);
    DocSaveOptions saveOptions = new DocSaveOptions();
    /** 或者DocSaveOptions.DocFormat.DocX*/
    saveOptions.setFormat(DocSaveOptions.DocFormat.Doc);
    pdfDocument.save(outFile, saveOptions);
    long now = System.currentTimeMillis();
    Out.print(inFile, outFile, now, old);
    log.info("轉(zhuǎn)換結(jié)束...");
    return new File(outFile).length();
}

word轉(zhuǎn)pdf

public static long wordToPdf(String inFile, String outFile) throws Exception {
    if (!com.yrnet.transfer.business.transfer.file.License.getWordLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        File file = new File(outFile);
        FileOutputStream os = new FileOutputStream(file);
        Document doc = new Document(inFile);
        Document tmp = new Document();
        tmp.removeAllChildren();
        tmp.appendDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);
        System.out.println("開(kāi)始解析word文檔" + inFile);
        doc.save(os, SaveFormat.PDF);
        long now = System.currentTimeMillis();
        log.info("target file size:{}",file.length());
        os.close();
        Out.print(inFile, outFile, now, old);
        return file.length();
    } catch (Exception e) {
        log.error(inFile + "轉(zhuǎn)換失敗,請(qǐng)重試",e);
        throw new Exception(e.getMessage());
    }
}

excel轉(zhuǎn)圖片

public static long excelToPic(String inFile, String outFile) throws Exception {
   if (!com.yrnet.transfer.business.transfer.file.License.getExcelLicense()) {
        return 0;
    }
    try {
        long old = System.currentTimeMillis();
        Workbook wb = new Workbook(inFile);
        Worksheet sheet = wb.getWorksheets().get(0);
        ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
        imgOptions.setImageFormat(ImageFormat.getPng());
        imgOptions.setCellAutoFit(true);
        imgOptions.setOnePagePerSheet(true);
        SheetRender render = new SheetRender(sheet, imgOptions);
        render.toImage(0, outFile);
        long now = System.currentTimeMillis();
        Out.print(inFile, outFile, now, old);
        return new File(outFile).length();
    }catch (Exception e) {
        e.printStackTrace();
        throw new Exception(e.getMessage());
    }
}

pdf轉(zhuǎn)圖片

public static long pdfToPng(String inFile, List<String> outFile) throws Exception {
  long size = 0;
   if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
       return size;
   }
   try {
       long old = System.currentTimeMillis();
       Document pdfDocument = new Document(inFile);
       Resolution resolution = new Resolution(960);
       JpegDevice jpegDevice = new JpegDevice(resolution);
       for (int index=1;index<=pdfDocument.getPages().size();index++) {
           String path = inFile.substring(0,inFile.lastIndexOf(".")) + "_"+index+".png";
           File file = new File(path);
           size += file.length();
           FileOutputStream fileOs = new FileOutputStream(file);
           jpegDevice.process(pdfDocument.getPages().get_Item(index), fileOs);
           outFile.add(path);
           fileOs.close();
           long now = System.currentTimeMillis();
           Out.print(inFile, path, now, old);
       }
       return size;
   }catch (Exception e){
       log.error(e.getMessage(),e);
       throw new Exception(e.getMessage());
   }
}

odt轉(zhuǎn)pdf

public static long pdfToPng(String inFile, List<String> outFile) throws Exception {
  long size = 0;
    if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
        return size;
    }
    try {
        long old = System.currentTimeMillis();
        Document pdfDocument = new Document(inFile);
        Resolution resolution = new Resolution(960);
        JpegDevice jpegDevice = new JpegDevice(resolution);
        for (int index=1;index<=pdfDocument.getPages().size();index++) {
            String path = inFile.substring(0,inFile.lastIndexOf(".")) + "_"+index+".png";
            File file = new File(path);
            size += file.length();
            FileOutputStream fileOs = new FileOutputStream(file);
            jpegDevice.process(pdfDocument.getPages().get_Item(index), fileOs);
            outFile.add(path);
            fileOs.close();
            long now = System.currentTimeMillis();
            Out.print(inFile, path, now, old);
        }
        return size;
    }catch (Exception e){
        log.error(e.getMessage(),e);
        throw new Exception(e.getMessage());
    }
}

以上就是Android實(shí)現(xiàn)excel/pdf/word/odt/圖片相互轉(zhuǎn)換的詳細(xì)內(nèi)容,更多關(guān)于Android excel pdf word odt圖片轉(zhuǎn)換的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

红桥区| 龙陵县| 霍山县| 五河县| 九江县| 甘谷县| 林口县| 景东| 平顶山市| 崇州市| 延寿县| 浠水县| 永善县| 麦盖提县| 沭阳县| 涟源市| 花莲县| 太保市| 巍山| 谢通门县| 金华市| 威宁| 密云县| 前郭尔| 洪雅县| 香格里拉县| 永仁县| 北安市| 富宁县| 成武县| 重庆市| 澎湖县| 墨竹工卡县| 平凉市| 霞浦县| 会同县| 淳安县| 芦山县| 许昌县| 吴旗县| 怀仁县|