Search in sources :

Example 1 with OpcPackage

use of org.docx4j.openpackaging.packages.OpcPackage in project docx4j-template by vindell.

the class Word_解压_Unzip_S3_Test method zipXml.

public void zipXml(String inputfilepath, String outFilePath) throws Exception {
    System.out.println(inputfilepath);
    // Load the docx
    File baseDir = new File(inputfilepath);
    UnzippedPartStore partLoader = new UnzippedPartStore(baseDir);
    final Load3 loader = new Load3(partLoader);
    OpcPackage opc = loader.get();
    // Save it zipped
    ZipPartStore zps = new ZipPartStore();
    zps.setSourcePartStore(opc.getSourcePartStore());
    Save saver = new Save(opc, zps);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(new File(outFilePath));
        saver.save(fos);
    } catch (FileNotFoundException e) {
        throw new Docx4JException("Couldn't save " + outFilePath, e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}
Also used : UnzippedPartStore(org.docx4j.openpackaging.io3.stores.UnzippedPartStore) ZipPartStore(org.docx4j.openpackaging.io3.stores.ZipPartStore) FileOutputStream(java.io.FileOutputStream) OpcPackage(org.docx4j.openpackaging.packages.OpcPackage) FileNotFoundException(java.io.FileNotFoundException) Save(org.docx4j.openpackaging.io3.Save) File(java.io.File) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException) Load3(org.docx4j.openpackaging.io3.Load3)

Example 2 with OpcPackage

use of org.docx4j.openpackaging.packages.OpcPackage in project Aspose.Cells-for-Java by aspose-cells.

the class Xlsx4jOpenSaveSpreadSheet method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(Xlsx4jOpenSaveSpreadSheet.class);
    String inputfilepath = dataDir + "pivot.xlsm";
    boolean save = true;
    String outputfilepath = dataDir + "pivot-rtt-xlsx4j.xlsm";
    // Open a document from the file system
    // 1. Load the Package
    OpcPackage pkg = OpcPackage.load(new java.io.File(inputfilepath));
    // Save it
    if (save) {
        SaveToZipFile saver = new SaveToZipFile(pkg);
        saver.save(outputfilepath);
    }
}
Also used : OpcPackage(org.docx4j.openpackaging.packages.OpcPackage) SaveToZipFile(org.docx4j.openpackaging.io.SaveToZipFile)

Example 3 with OpcPackage

use of org.docx4j.openpackaging.packages.OpcPackage in project docx4j-template by vindell.

the class Docx4j_工具类_S3_Test method loadWordprocessingMLPackageWithPwd.

/**
 * @Description:加载带密码WordprocessingMLPackage
 */
public WordprocessingMLPackage loadWordprocessingMLPackageWithPwd(String filePath, String password) throws Exception {
    OpcPackage opcPackage = WordprocessingMLPackage.load(new java.io.File(filePath), password);
    WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage) opcPackage;
    return wordMLPackage;
}
Also used : OpcPackage(org.docx4j.openpackaging.packages.OpcPackage) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File)

Example 4 with OpcPackage

use of org.docx4j.openpackaging.packages.OpcPackage in project docx4j-template by vindell.

the class Word_解压_Unzip_S3_Test2 method zipXml.

public void zipXml(String inputfilepath, String outFilePath) throws Exception {
    System.out.println(inputfilepath);
    // Load the docx
    File baseDir = new File(inputfilepath);
    UnzippedPartStore partLoader = new UnzippedPartStore(baseDir);
    final Load3 loader = new Load3(partLoader);
    OpcPackage opc = loader.get();
    // Save it zipped
    ZipPartStore zps = new ZipPartStore();
    zps.setSourcePartStore(opc.getSourcePartStore());
    Save saver = new Save(opc, zps);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(new File(outFilePath));
        saver.save(fos);
    } catch (FileNotFoundException e) {
        throw new Docx4JException("Couldn't save " + outFilePath, e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}
Also used : UnzippedPartStore(org.docx4j.openpackaging.io3.stores.UnzippedPartStore) ZipPartStore(org.docx4j.openpackaging.io3.stores.ZipPartStore) FileOutputStream(java.io.FileOutputStream) OpcPackage(org.docx4j.openpackaging.packages.OpcPackage) FileNotFoundException(java.io.FileNotFoundException) Save(org.docx4j.openpackaging.io3.Save) File(java.io.File) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException) Load3(org.docx4j.openpackaging.io3.Load3)

Aggregations

OpcPackage (org.docx4j.openpackaging.packages.OpcPackage)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)2 Load3 (org.docx4j.openpackaging.io3.Load3)2 Save (org.docx4j.openpackaging.io3.Save)2 UnzippedPartStore (org.docx4j.openpackaging.io3.stores.UnzippedPartStore)2 ZipPartStore (org.docx4j.openpackaging.io3.stores.ZipPartStore)2 SaveToZipFile (org.docx4j.openpackaging.io.SaveToZipFile)1 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)1