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"));
}
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();
}
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;
}
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;
}
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());
}
Aggregations