use of org.apache.poi.xssf.usermodel.XSSFSheet in project poi by apache.
the class TestWorkbookProtection method testEncryptDecrypt.
@Test
public void testEncryptDecrypt() throws Exception {
final String password = "abc123";
final String sheetName = "TestSheet1";
final String cellValue = "customZipEntrySource";
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet1 = workbook.createSheet(sheetName);
XSSFRow row1 = sheet1.createRow(1);
XSSFCell cell1 = row1.createCell(1);
cell1.setCellValue(cellValue);
File tf1 = TempFile.createTempFile("poitest", ".xlsx");
FileOutputStream fos1 = new FileOutputStream(tf1);
workbook.write(fos1);
IOUtils.closeQuietly(fos1);
POIFSFileSystem poiFileSystem = new POIFSFileSystem();
EncryptionInfo encryptionInfo = new EncryptionInfo(EncryptionMode.agile);
Encryptor enc = encryptionInfo.getEncryptor();
enc.confirmPassword(password);
FileInputStream fis = new FileInputStream(tf1);
OPCPackage opc = OPCPackage.open(fis);
IOUtils.closeQuietly(fis);
try {
OutputStream os = enc.getDataStream(poiFileSystem);
opc.save(os);
IOUtils.closeQuietly(os);
} finally {
IOUtils.closeQuietly(opc);
}
tf1.delete();
FileOutputStream fos2 = new FileOutputStream(tf1);
poiFileSystem.writeFilesystem(fos2);
IOUtils.closeQuietly(fos2);
workbook.close();
fis = new FileInputStream(tf1);
POIFSFileSystem poiFileSystem2 = new POIFSFileSystem(fis);
IOUtils.closeQuietly(fis);
EncryptionInfo encryptionInfo2 = new EncryptionInfo(poiFileSystem2);
Decryptor decryptor = encryptionInfo2.getDecryptor();
decryptor.verifyPassword(password);
XSSFWorkbook workbook2 = new XSSFWorkbook(decryptor.getDataStream(poiFileSystem2));
workbook2.close();
tf1.delete();
}
use of org.apache.poi.xssf.usermodel.XSSFSheet in project poi by apache.
the class TestXSSFCloneSheet method testCloneSheetIntStringValidName.
@Test
public void testCloneSheetIntStringValidName() {
XSSFSheet cloned = wb.cloneSheet(0, OTHER_SHEET_NAME);
assertEquals(OTHER_SHEET_NAME, cloned.getSheetName());
assertEquals(2, wb.getNumberOfSheets());
}
use of org.apache.poi.xssf.usermodel.XSSFSheet in project CzechIdMng by bcvsolutions.
the class IdentityReportXlsxRenderer method render.
@Override
public InputStream render(RptReportDto report) {
try {
// read json stream
JsonParser jParser = getMapper().getFactory().createParser(getReportData(report));
XSSFWorkbook workbook = new XSSFWorkbook();
CreationHelper createHelper = workbook.getCreationHelper();
XSSFSheet sheet = workbook.createSheet("Report");
// header
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Username");
cell = row.createCell(1);
cell.setCellValue("First name");
cell = row.createCell(2);
cell.setCellValue("Last name");
cell = row.createCell(3);
cell.setCellValue("Disabled");
int rowNum = 1;
// json is array of identities
if (jParser.nextToken() == JsonToken.START_ARRAY) {
// write single identity
while (jParser.nextToken() == JsonToken.START_OBJECT) {
IdmIdentityDto identity = getMapper().readValue(jParser, IdmIdentityDto.class);
row = sheet.createRow(rowNum++);
cell = row.createCell(0);
cell.setCellValue(identity.getUsername());
cell = row.createCell(1);
cell.setCellValue(identity.getFirstName());
cell = row.createCell(2);
cell.setCellValue(identity.getLastName());
cell = row.createCell(3);
cell.setCellValue(identity.isDisabled());
}
}
// close json stream
jParser.close();
//
// footer info about more available reports
rowNum++;
rowNum++;
row = sheet.createRow(rowNum++);
cell = row.createCell(0);
cell.setCellValue("More reports are available in reports module:");
row = sheet.createRow(rowNum++);
cell = row.createCell(0);
cell.setCellValue("https://wiki.czechidm.com/devel/documentation/modules_reports");
Hyperlink link = createHelper.createHyperlink(XSSFHyperlink.LINK_URL);
link.setAddress("https://wiki.czechidm.com/devel/documentation/modules_reports");
cell.setHyperlink(link);
// close and return input stream
return getInputStream(workbook);
} catch (IOException ex) {
throw new ReportRenderException(report.getName(), ex);
}
}
use of org.apache.poi.xssf.usermodel.XSSFSheet in project mica2 by obiba.
the class ExcelContingencyWriter method writeBody.
private void writeBody(XSSFWorkbook workbook, Mica.DatasetVariableContingenciesDto dto) {
List<String> terms = getTermsHeaders(variable, dto);
List<String> values = getValuesHeaders(crossVariable, dto);
for (Mica.DatasetVariableContingencyDto c : dto.getContingenciesList()) {
addOpalTableSheet(workbook, c, terms, values);
}
XSSFSheet sheet = workbook.createSheet("All");
Mica.DatasetVariableContingencyDto c = dto.getAll();
writeTable(sheet, c, "All", terms, values);
}
Aggregations