Search in sources :

Example 81 with XSSFWorkbook

use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.

the class TestWorkbookProtection method testHashPassword.

@SuppressWarnings("resource")
@Test
public void testHashPassword() throws Exception {
    XSSFWorkbook wb = new XSSFWorkbook();
    wb.lockRevision();
    wb.setRevisionsPassword("test", HashAlgorithm.sha1);
    wb = writeOutAndReadBack(wb);
    assertTrue(wb.isRevisionLocked());
    assertTrue(wb.validateRevisionsPassword("test"));
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Test(org.junit.Test)

Example 82 with XSSFWorkbook

use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.

the class TestXSSFCloneSheet method test60512.

@Test
public void test60512() throws IOException {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("60512.xlsm");
    assertEquals(1, wb.getNumberOfSheets());
    Sheet sheet = wb.cloneSheet(0);
    assertNotNull(sheet);
    assertEquals(2, wb.getNumberOfSheets());
    Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
    assertNotNull(wbBack);
    wbBack.close();
    wb.close();
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) BaseTestCloneSheet(org.apache.poi.ss.usermodel.BaseTestCloneSheet) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 83 with XSSFWorkbook

use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.

the class XSSFTestDataSamples method writeOutAndReadBack.

/**
     * Write out and read back using a memory buffer to avoid disk I/O.
     * If there is not enough memory to have two workbooks open at the same time,
     * consider using:
     * 
     * Workbook wb = new XSSFWorkbook();
     * String testName = "example";
     * 
     * <code>
     * File file = writeOutAndClose(wb, testName);
     * // clear all references that would prevent the workbook from getting garbage collected
     * wb = null;
     * Workbook wbBack = readBackAndDelete(file);
     * </code>
     *
     * @param wb the workbook to write out
     * @return the read back workbook
     */
public static <R extends Workbook> R writeOutAndReadBack(R wb) {
    Workbook result;
    try {
        result = readBack(writeOut(wb));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    @SuppressWarnings("unchecked") R r = (R) result;
    return r;
}
Also used : IOException(java.io.IOException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook)

Example 84 with XSSFWorkbook

use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.

the class SXSSFITestDataProvider method openSampleWorkbook.

@Override
public Workbook openSampleWorkbook(String sampleFileName) {
    XSSFWorkbook xssfWorkbook = XSSFITestDataProvider.instance.openSampleWorkbook(sampleFileName);
    SXSSFWorkbook swb = new SXSSFWorkbook(xssfWorkbook);
    instances.add(swb);
    return swb;
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook)

Example 85 with XSSFWorkbook

use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.

the class TestWorkbookProtection method shouldReadWorkbookProtection.

@Test
public void shouldReadWorkbookProtection() throws Exception {
    XSSFWorkbook workbook = openSampleWorkbook("workbookProtection_not_protected.xlsx");
    assertFalse(workbook.isStructureLocked());
    assertFalse(workbook.isWindowsLocked());
    assertFalse(workbook.isRevisionLocked());
    workbook = openSampleWorkbook("workbookProtection_workbook_structure_protected.xlsx");
    assertTrue(workbook.isStructureLocked());
    assertFalse(workbook.isWindowsLocked());
    assertFalse(workbook.isRevisionLocked());
    workbook = openSampleWorkbook("workbookProtection_workbook_windows_protected.xlsx");
    assertTrue(workbook.isWindowsLocked());
    assertFalse(workbook.isStructureLocked());
    assertFalse(workbook.isRevisionLocked());
    workbook = openSampleWorkbook("workbookProtection_workbook_revision_protected.xlsx");
    assertTrue(workbook.isRevisionLocked());
    assertFalse(workbook.isWindowsLocked());
    assertFalse(workbook.isStructureLocked());
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Test(org.junit.Test)

Aggregations

XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)334 Workbook (org.apache.poi.ss.usermodel.Workbook)131 Sheet (org.apache.poi.ss.usermodel.Sheet)119 Test (org.junit.Test)108 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)82 FileOutputStream (java.io.FileOutputStream)81 Row (org.apache.poi.ss.usermodel.Row)74 Cell (org.apache.poi.ss.usermodel.Cell)68 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)66 IOException (java.io.IOException)65 FileInputStream (java.io.FileInputStream)63 ArrayList (java.util.ArrayList)51 File (java.io.File)46 ByteArrayInputStream (java.io.ByteArrayInputStream)36 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)35 FileNotFoundException (java.io.FileNotFoundException)29 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)27 CellStyle (org.apache.poi.ss.usermodel.CellStyle)26 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)26 XSSFDrawing (org.apache.poi.xssf.usermodel.XSSFDrawing)25