Search in sources :

Example 16 with SXSSFWorkbook

use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.

the class TestSignatureInfo method bug58630.

@Test
public void bug58630() throws Exception {
    // test deletion of sheet 0 and signing
    File tpl = copy(testdata.getFile("bug58630.xlsx"));
    SXSSFWorkbook wb1 = new SXSSFWorkbook((XSSFWorkbook) WorkbookFactory.create(tpl), 10);
    wb1.setCompressTempFiles(true);
    wb1.removeSheetAt(0);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    wb1.write(os);
    wb1.close();
    OPCPackage pkg = OPCPackage.open(new ByteArrayInputStream(os.toByteArray()));
    initKeyPair("Test", "CN=Test");
    SignatureConfig signatureConfig = new SignatureConfig();
    signatureConfig.setKey(keyPair.getPrivate());
    signatureConfig.setSigningCertificateChain(Collections.singletonList(x509));
    signatureConfig.setOpcPackage(pkg);
    SignatureInfo si = new SignatureInfo();
    si.setSignatureConfig(signatureConfig);
    si.confirmSignature();
    assertTrue("invalid signature", si.verifySignature());
    pkg.close();
}
Also used : SignatureInfo(org.apache.poi.poifs.crypt.dsig.SignatureInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) SignatureConfig(org.apache.poi.poifs.crypt.dsig.SignatureConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 17 with SXSSFWorkbook

use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.

the class SXSSFITestDataProvider method createWorkbook.

//************ SXSSF-specific methods ***************//
@Override
public SXSSFWorkbook createWorkbook(int rowAccessWindowSize) {
    SXSSFWorkbook wb = new SXSSFWorkbook(rowAccessWindowSize);
    instances.add(wb);
    return wb;
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook)

Example 18 with SXSSFWorkbook

use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.

the class SXSSFITestDataProvider method writeOutAndReadBack.

/**
     * Returns an XSSFWorkbook since SXSSFWorkbook is write-only
     */
@Override
public XSSFWorkbook writeOutAndReadBack(Workbook wb) {
    // several times in succession
    if (!(wb instanceof SXSSFWorkbook || wb instanceof XSSFWorkbook)) {
        throw new IllegalArgumentException("Expected an instance of SXSSFWorkbook");
    }
    XSSFWorkbook result;
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
        wb.write(baos);
        InputStream is = new ByteArrayInputStream(baos.toByteArray());
        result = new XSSFWorkbook(is);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 19 with SXSSFWorkbook

use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project tika by apache.

the class Report method dumpXLSX.

private void dumpXLSX(Connection c, Path reportsRoot) throws IOException, SQLException {
    Statement st = c.createStatement();
    Path out = reportsRoot.resolve(reportFilename);
    Files.createDirectories(out.getParent());
    SXSSFWorkbook wb = new SXSSFWorkbook(new XSSFWorkbook(), 100, true, true);
    wb.setCompressTempFiles(true);
    defaultIntegerFormatter.reset(wb.getXSSFWorkbook());
    defaultDoubleFormatter.reset(wb.getXSSFWorkbook());
    sqlCellStyle = wb.createCellStyle();
    sqlCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
    sqlCellStyle.setWrapText(true);
    try {
        dumpReportToWorkbook(st, wb);
    } finally {
        try (OutputStream os = Files.newOutputStream(out)) {
            wb.write(os);
        } finally {
            wb.dispose();
        }
    }
}
Also used : Path(java.nio.file.Path) Statement(java.sql.Statement) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) OutputStream(java.io.OutputStream) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook)

Aggregations

SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)19 Test (org.junit.Test)7 Workbook (org.apache.poi.ss.usermodel.Workbook)6 Sheet (org.apache.poi.ss.usermodel.Sheet)5 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 FileInputStream (java.io.FileInputStream)3 Cell (org.apache.poi.ss.usermodel.Cell)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)2 BaseTestXSheet (org.apache.poi.ss.usermodel.BaseTestXSheet)2 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)2 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)2 RichTextString (org.apache.poi.ss.usermodel.RichTextString)2 Row (org.apache.poi.ss.usermodel.Row)2 TempFile (org.apache.poi.util.TempFile)2