Search in sources :

Example 1 with Save

use of org.docx4j.openpackaging.io3.Save 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 Save

use of org.docx4j.openpackaging.io3.Save in project docx4j-template by vindell.

the class Word_解压_Unzip_S3_Test2 method unzipWord.

public void unzipWord(String fileName, String outFilePath) throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(fileName));
    File baseDir = new File(outFilePath);
    baseDir.mkdir();
    UnzippedPartStore ups = new UnzippedPartStore(baseDir);
    ups.setSourcePartStore(wordMLPackage.getSourcePartStore());
    Save saver = new Save(wordMLPackage, ups);
    saver.save(null);
}
Also used : UnzippedPartStore(org.docx4j.openpackaging.io3.stores.UnzippedPartStore) Save(org.docx4j.openpackaging.io3.Save) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) File(java.io.File)

Example 3 with Save

use of org.docx4j.openpackaging.io3.Save in project com.revolsys.open by revolsys.

the class XlsxRecordWriter method close.

/**
 * Closes the underlying reader.
 */
@Override
public synchronized void close() {
    if (this.out != null) {
        try {
            final long fieldCount = this.recordDefinition.getFieldCount();
            final String ref = "A1:" + getRef(fieldCount, this.sheetRows.size());
            final TablePart tablePart = new TablePart();
            this.spreadsheetPackage.addTargetPart(tablePart);
            final CTTable table = smlObjectFactory.createCTTable();
            tablePart.setContents(table);
            table.setId(1);
            table.setName("Table1");
            table.setDisplayName(this.recordDefinition.getName());
            table.setRef(ref);
            final CTAutoFilter autoFilter = smlObjectFactory.createCTAutoFilter();
            autoFilter.setRef(ref);
            table.setAutoFilter(autoFilter);
            long columnIndex = 1;
            final CTTableColumns tableColumns = smlObjectFactory.createCTTableColumns();
            tableColumns.setCount(fieldCount);
            table.setTableColumns(tableColumns);
            final List<CTTableColumn> columns = tableColumns.getTableColumn();
            for (final String fieldName : this.recordDefinition.getFieldNames()) {
                final CTTableColumn column = smlObjectFactory.createCTTableColumn();
                column.setId(columnIndex);
                column.setName(fieldName);
                columns.add(column);
                columnIndex++;
            }
            final CTTableStyleInfo tableStyleInfo = smlObjectFactory.createCTTableStyleInfo();
            table.setTableStyleInfo(tableStyleInfo);
            tableStyleInfo.setName("TableStyleMedium14");
            tableStyleInfo.setShowFirstColumn(false);
            tableStyleInfo.setShowLastColumn(false);
            tableStyleInfo.setShowRowStripes(true);
            tableStyleInfo.setShowColumnStripes(false);
            this.sheet.addTargetPart(tablePart, "rId1");
            final Save save = new Save(this.spreadsheetPackage);
            save.save(this.out);
            try {
                this.out.flush();
            } catch (final IOException e) {
            }
        } catch (final Docx4JException e) {
            throw Exceptions.wrap(e);
        } finally {
            FileUtil.closeSilent(this.out);
            this.out = null;
            this.sheet = null;
            this.sheetData = null;
            this.spreadsheetPackage = null;
            this.sheetRows = Collections.emptyList();
        }
    }
}
Also used : CTTableColumns(org.xlsx4j.sml.CTTableColumns) CTAutoFilter(org.xlsx4j.sml.CTAutoFilter) CTTableStyleInfo(org.xlsx4j.sml.CTTableStyleInfo) TablePart(org.docx4j.openpackaging.parts.SpreadsheetML.TablePart) CTTablePart(org.xlsx4j.sml.CTTablePart) CTTable(org.xlsx4j.sml.CTTable) Save(org.docx4j.openpackaging.io3.Save) IOException(java.io.IOException) CTTableColumn(org.xlsx4j.sml.CTTableColumn) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

Example 4 with Save

use of org.docx4j.openpackaging.io3.Save in project docx4j-template by vindell.

the class Word_解压_Unzip_S3_Test method unzipWord.

public void unzipWord(String fileName, String outFilePath) throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(fileName));
    File baseDir = new File(outFilePath);
    baseDir.mkdir();
    UnzippedPartStore ups = new UnzippedPartStore(baseDir);
    ups.setSourcePartStore(wordMLPackage.getSourcePartStore());
    Save saver = new Save(wordMLPackage, ups);
    saver.save(null);
}
Also used : UnzippedPartStore(org.docx4j.openpackaging.io3.stores.UnzippedPartStore) Save(org.docx4j.openpackaging.io3.Save) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) File(java.io.File)

Example 5 with Save

use of org.docx4j.openpackaging.io3.Save 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

Save (org.docx4j.openpackaging.io3.Save)5 File (java.io.File)4 UnzippedPartStore (org.docx4j.openpackaging.io3.stores.UnzippedPartStore)4 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)3 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 Load3 (org.docx4j.openpackaging.io3.Load3)2 ZipPartStore (org.docx4j.openpackaging.io3.stores.ZipPartStore)2 OpcPackage (org.docx4j.openpackaging.packages.OpcPackage)2 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)2 IOException (java.io.IOException)1 TablePart (org.docx4j.openpackaging.parts.SpreadsheetML.TablePart)1 CTAutoFilter (org.xlsx4j.sml.CTAutoFilter)1 CTTable (org.xlsx4j.sml.CTTable)1 CTTableColumn (org.xlsx4j.sml.CTTableColumn)1 CTTableColumns (org.xlsx4j.sml.CTTableColumns)1 CTTablePart (org.xlsx4j.sml.CTTablePart)1 CTTableStyleInfo (org.xlsx4j.sml.CTTableStyleInfo)1