use of com.alibaba.excel.exception.ExcelGenerateException in project easyexcel by alibaba.
the class WriteContextImpl method doOutputStreamEncrypt07.
/**
* To encrypt
*/
private boolean doOutputStreamEncrypt07() throws Exception {
if (StringUtils.isEmpty(writeWorkbookHolder.getPassword()) || !ExcelTypeEnum.XLSX.equals(writeWorkbookHolder.getExcelType())) {
return false;
}
if (writeWorkbookHolder.getFile() != null) {
return false;
}
File tempXlsx = FileUtils.createTmpFile(UUID.randomUUID() + ".xlsx");
FileOutputStream tempFileOutputStream = new FileOutputStream(tempXlsx);
try {
writeWorkbookHolder.getWorkbook().write(tempFileOutputStream);
} finally {
try {
writeWorkbookHolder.getWorkbook().close();
tempFileOutputStream.close();
} catch (Exception e) {
if (!tempXlsx.delete()) {
throw new ExcelGenerateException("Can not delete temp File!");
}
throw e;
}
}
try (POIFSFileSystem fileSystem = openFileSystemAndEncrypt(tempXlsx)) {
fileSystem.writeFilesystem(writeWorkbookHolder.getOutputStream());
} finally {
if (!tempXlsx.delete()) {
throw new ExcelGenerateException("Can not delete temp File!");
}
}
return true;
}
use of com.alibaba.excel.exception.ExcelGenerateException in project easyexcel by alibaba.
the class CsvSheet method flushData.
public void flushData() {
try {
for (CsvRow row : rowCache) {
Iterator<Cell> cellIterator = row.cellIterator();
int columnIndex = 0;
while (cellIterator.hasNext()) {
CsvCell csvCell = (CsvCell) cellIterator.next();
while (csvCell.getColumnIndex() > columnIndex++) {
csvPrinter.print(null);
}
csvPrinter.print(buildCellValue(csvCell));
}
csvPrinter.println();
}
rowCache.clear();
} catch (IOException e) {
throw new ExcelGenerateException(e);
}
}
use of com.alibaba.excel.exception.ExcelGenerateException in project easyexcel by alibaba.
the class FillDataTest method t03FillCsv.
@Test
public void t03FillCsv() {
ExcelGenerateException excelGenerateException = Assert.assertThrows(ExcelGenerateException.class, () -> fill(fileCsv, simpleTemplateCsv));
Assert.assertEquals("csv cannot use template.", excelGenerateException.getMessage());
}
Aggregations