本文整理汇总了Java中org.apache.poi.EncryptedDocumentException类的典型用法代码示例。如果您正苦于以下问题:Java EncryptedDocumentException类的具体用法?Java EncryptedDocumentException怎么用?Java EncryptedDocumentException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EncryptedDocumentException类属于org.apache.poi包,在下文中一共展示了EncryptedDocumentException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillTrie
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
@Override
protected void fillTrie(Logger logger, Trie<List<String>> trie, Corpus corpus) throws IOException, ModuleException {
Iterator<InputStream> inputStreams = xlsFile.getInputStreams();
while (inputStreams.hasNext()) {
try (InputStream is = inputStreams.next()) {
Workbook wb = WorkbookFactory.create(is);
for (int sheetNumber : sheets) {
Sheet sheet = wb.getSheetAt(sheetNumber);
fillSheetEntries(trie, sheet);
}
}
catch (EncryptedDocumentException|InvalidFormatException e) {
rethrow(e);
}
}
}
示例2: testLong
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
@Test
public void testLong() throws EncryptedDocumentException, InvalidFormatException, IOException{
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
Row row = sheet.createRow((short) 1);
Cell cell = row.createCell((short) 1);
cell.setCellValue("This is a aoptest of merging");
sheet.addMergedRegion(new CellRangeAddress(
1, //first row (0-based)
1, //last row (0-based)
1, //first column (0-based)
2 //last column (0-based)
));
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream(new File("E:/aoptest/gzb.xls"));
wb.write(fileOut);
fileOut.close();
}
示例3: innerExecute
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
@Override
protected void innerExecute() throws DPUException {
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.message");
try {
sheetNameSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); // case-insensitive sheet names
String sheetNames = config.getSheetNames();
if (sheetNames != null && sheetNames.length() > 0) {
sheetNameSet.addAll(Arrays.asList(sheetNames.split(Pattern.quote(":"))));
}
Set<FilesDataUnit.Entry> entries = FilesHelper.getFiles(input);
for (FilesDataUnit.Entry entry : entries) {
excelToCsv(entry);
}
} catch (DataUnitException | EncryptedDocumentException | InvalidFormatException | IOException ex) {
throw ContextUtils.dpuException(ctx, ex, "ExcelToCsv.dpuFailed");
}
}
示例4: buildExcelSheetsFromFile
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
@Override
public List<Sheet> buildExcelSheetsFromFile(File file)
throws IOException, InvalidFormatException, EmptySheetException
{
List<Sheet> sheets = newArrayList();
try (Workbook workbook = WorkbookFactory.create(file))
{
int numberOfSheets = workbook.getNumberOfSheets();
for (int index = 0; index < numberOfSheets; index++)
{
Sheet sheet = workbook.getSheetAt(index);
if (sheet.getPhysicalNumberOfRows() == 0)
{
throw new EmptySheetException("Sheet [" + sheet.getSheetName() + "] is empty");
}
else if (sheet.getPhysicalNumberOfRows() == 1)
{
throw new MolgenisDataException(
"Header was found, but no data is present in sheet [" + sheet.getSheetName() + "]");
}
else
{
sheets.add(sheet);
}
}
}
catch (IOException | InvalidFormatException | EncryptedDocumentException ex)
{
LOG.error(ex.getLocalizedMessage());
throw new MolgenisDataException("Could not create excel workbook from file");
}
return sheets;
}
示例5: readExcelFile
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
public static Workbook readExcelFile(File file) throws EncryptedDocumentException, InvalidFormatException, IOException {
return WorkbookFactory.create(file);
}
示例6: ExcelBase
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
/**
*
* son las celdas que ya se han modificado
* se necesitan almacenar para poder notificar los
* cambios en modificaciones posteriores
*/
protected ExcelBase(ArrayList<WorkBookInfo> arrWorkBookInfo) throws IOException, EncryptedDocumentException, InvalidFormatException
{
// System.setProperty ("org.apache.poi.util.POILogger",
// "org.apache.poi.util.SystemOutLogger");
// System.setProperty ("poi.log.level", POILogger.INFO + "");
// evaluator.setDebugEvaluationOutputForNextEval(true);
//Collection<String> unsupportedFuncs = WorkbookEvaluator.getNotSupportedFunctionNames ();
//agrego funciones personalizadas
//WorkbookEvaluator.registerFunction("DAVERAGE", new DAVERAGE());
FileInputStream fis;
WorkBookObject workBookObject;
Map<String,FormulaEvaluator> workbooksEvaluator = new HashMap<String, FormulaEvaluator>();
for (WorkBookInfo workBookInfoItem : arrWorkBookInfo)
{
workBookObject = new WorkBookObject();
workBookObject.workBookInfo = workBookInfoItem;
fis = new FileInputStream(workBookInfoItem.path);
workBookObject.workBook = WorkbookFactory.create(fis);
//recorro las hojas del libro
for (String sheetNameItem : workBookInfoItem.sheetsNames)
{
workBookObject.sheets.put(sheetNameItem,workBookObject.workBook.getSheet(sheetNameItem));
}
workBookObject.evaluator = workBookObject.workBook.getCreationHelper().createFormulaEvaluator();
//mapa de referencias de evaluator
workbooksEvaluator.put(workBookInfoItem.fileName, workBookObject.evaluator);
arrWorkBookObject.add(workBookObject);
}
//asigno referencias todos a todos
for (WorkBookObject workBookObjectItem : arrWorkBookObject)
{
workBookObjectItem.evaluator.setupReferencedWorkbooks(workbooksEvaluator);
}
}
示例7: importExcelDemo
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
/**
* 解析Excel Demo
* @throws IOException
* @throws InvalidFormatException
* @throws EncryptedDocumentException
*/
public static void importExcelDemo() throws EncryptedDocumentException, InvalidFormatException, IOException{
File uploadXlsFile = new File("/demo-sheet.xlsx");
Workbook book = WorkbookFactory.create(uploadXlsFile);
Sheet demoSheet = book.getSheet("demo-sheet");
Iterator<Row> demoSheetIterator = demoSheet.rowIterator();
while (demoSheetIterator.hasNext()) {
Row rowX = demoSheetIterator.next();
System.out.println("---------------------------");
for (int i = 0; i < 10; i++) {
System.out.println(rowX.getCell(i));
}
}
}
示例8: trackSLA
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
/**
* Uses everything else to do the Magic i.e the main code for tracking and
* writing to the file.
*/
public void trackSLA() {
try {
final String FILE = workbook.getAbsolutePath();
System.out.println("open " + workbook.getAbsolutePath());
InputStream inp = new FileInputStream(FILE);
int rowIndex = 1, cellIndex = 1;
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(rowIndex);
Cell cell = row.getCell(cellIndex);
Date firstCellContents = cell.getDateCellValue();
Calendar firstDayCalendar = Calendar.getInstance();
firstDayCalendar.setTime(firstCellContents);
rowIndex = getRow(firstDayCalendar);
cellIndex = getCell(firstDayCalendar);
//get the cell where it must write
row = sheet.getRow(rowIndex);
cell = row.getCell(cellIndex);
//get SLA time
String sla = getSLATime();
System.out.println("\nSLA:" + sla);
cell.setCellValue(sla);
cell = row.getCell(cellIndex + 1);
cell.setCellValue(botName);
try ( //write it on the file
FileOutputStream fileOut = new FileOutputStream(workbook)) {
wb.write(fileOut);
}
System.out.println("Saved on " + workbook.getAbsolutePath());
} catch (IOException | InvalidFormatException | EncryptedDocumentException e) {
System.out.println("ERROR : " + e.getMessage());
}
}
示例9: parserArchivo
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
@Override
protected List<Votante> parserArchivo(File archivo) throws IOException {
List<Votante> votantes = new ArrayList<Votante>();
Workbook wb;
try {
wb = WorkbookFactory.create(archivo);
org.apache.poi.ss.usermodel.Sheet sheet = wb.getSheetAt(0);
Iterator<Row> rows = sheet.iterator();
//Quitamos la primera fila que contiene los nombres de las columnas
if(rows.hasNext()) rows.next();
int fila = 2;
//Procesamos el documento
while(rows.hasNext()){
Row row = (Row) rows.next();
Iterator<Cell> cells = row.cellIterator();
List<String> datosVotante = new ArrayList<String>();
while(cells.hasNext()){
Cell cell = (Cell) cells.next();
datosVotante.add(cell.toString());
}
if(datosVotante.size() == 4){
Votante v = new Votante(datosVotante.get(0),
datosVotante.get(1),
datosVotante.get(2),
datosVotante.get(3));
votantes.add(v);
}
else{
rW.WriteReport(ruta, "[Fila " + fila + "] Faltan datos del usuario.");
}
fila++;
}
} catch (EncryptedDocumentException | InvalidFormatException e) {
rW.WriteReport(ruta, "Ha ocurrido un problema al leer el fichero excel.");
}
return votantes;
}
示例10: parserArchivo
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
@Override
protected List<Votante> parserArchivo(File archivo) throws IOException {
List<Votante> votantes = new ArrayList<Votante>();
Workbook wb;
try {
wb = WorkbookFactory.create(archivo);
org.apache.poi.ss.usermodel.Sheet sheet = wb.getSheetAt(0);
Iterator<Row> rows = sheet.iterator();
//Quitamos la primera fila que contiene los nombres de las columnas
if(rows.hasNext()) rows.next();
int fila = 2;
//Procesamos el documento
while(rows.hasNext()){
Row row = (Row) rows.next();
Iterator<Cell> cells = row.cellIterator();
List<String> datosVotante = new ArrayList<String>();
while(cells.hasNext()){
Cell cell = (Cell) cells.next();
datosVotante.add(cell.toString());
}
//magia autowiured
if(datosVotante.size() == 4){
Votante v = new Votante(datosVotante.get(0),
datosVotante.get(1),
datosVotante.get(2),
datosVotante.get(3) != "" ? Double.valueOf(datosVotante.get(3)).longValue() +"" : "");
votantes.add(v);
}
else{
rW.writeReport(ruta, "[Fila " + fila + "] Faltan datos del usuario.");
}
fila++;
}
} catch (EncryptedDocumentException | InvalidFormatException e) {
rW.writeReport(ruta, "Ha ocurrido un problema al leer el fichero excel.");
}
return votantes;
}
示例11: open
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
void open(File mainWorkbook, Integer maxWorkbookSize, boolean createIfNotExists, boolean forUpdate) {
file = mainWorkbook;
if(mainWorkbook.exists()) {
if(mainWorkbook.canRead()) {
if(forUpdate && isFileIsOpenedByAnotherProcess()) {
throw new RuntimeException("The file '" + file.getAbsolutePath() + "' is not writable. It might already be opened by another process.");
}
checkFileSize(mainWorkbook, maxWorkbookSize);
try {
inputStream = new BufferedInputStream(new FileInputStream(mainWorkbook));
workbook = WorkbookFactory.create(inputStream);
} catch (EncryptedDocumentException | InvalidFormatException | IOException e) {
throw new RuntimeException("Error while opening workbook '" + mainWorkbook.getName() + "'", e);
}
} else {
throw new RuntimeException("The workbook '" + mainWorkbook.getName() + "' cannot be read.");
}
} else {
if(createIfNotExists) {
create(mainWorkbook);
} else {
throw new RuntimeException("The workbook '" + mainWorkbook.getName() + "' doesn't exist.");
}
}
}
示例12: run
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
@Override
public void run(TaskSource taskSource, Schema schema, FileInput input, PageOutput output) {
PluginTask task = taskSource.loadTask(PluginTask.class);
List<String> sheetNames = new ArrayList<>();
Optional<String> sheetOption = task.getSheet();
if (sheetOption.isPresent()) {
sheetNames.add(sheetOption.get());
}
sheetNames.addAll(task.getSheets());
if (sheetNames.isEmpty()) {
throw new ConfigException("Attribute sheets is required but not set");
}
try (FileInputInputStream is = new FileInputInputStream(input)) {
while (is.nextFile()) {
Workbook workbook;
try {
workbook = WorkbookFactory.create(is);
} catch (IOException | EncryptedDocumentException | InvalidFormatException e) {
throw new RuntimeException(e);
}
List<String> list = resolveSheetName(workbook, sheetNames);
if (log.isDebugEnabled()) {
log.debug("resolved sheet names={}", list);
}
run(task, schema, workbook, list, output);
}
}
}
示例13: read
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
/**
* Read the given file either as .csv or .xls/.xlsx file, depending
* on the file-extension.
*
* @param dataFile The merge-file to read. Can have extension .csv, .xls or .xlsx
* @throws IOException If an error occurs while reading the file
* @throws EncryptedDocumentException If the document is encrypted (passwords are not supported currently)
* @throws InvalidFormatException If the .xls/.xlsx file cannot be read due to a file-format error
*/
public void read(File dataFile) throws IOException, EncryptedDocumentException, InvalidFormatException {
// read the lines from the data-file
if(FilenameUtils.getExtension(dataFile.getName()).equalsIgnoreCase("csv")) {
readCSVFile(dataFile);
} else {
readExcelFile(dataFile);
}
removeEmptyLines();
}
示例14: excelToCsv
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
private void excelToCsv(FilesDataUnit.Entry entry) throws EncryptedDocumentException, InvalidFormatException, IOException,
DataUnitException {
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.excelTransformationStared", entry.getSymbolicName());
File excelFile = FilesHelper.asFile(entry);
try (Workbook wb = WorkbookFactory.create(OPCPackage.open(excelFile, PackageAccess.READ))) {
for (int s = 0; s < wb.getNumberOfSheets(); s++) {
Sheet sheet = wb.getSheetAt(s);
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.sheetName", sheet.getSheetName());
if (sheetNameSet.isEmpty() || sheetNameSet.contains(sheet.getSheetName())) {
DpuFile csvFile = createCsvFile(entry.getSymbolicName(), sheet.getSheetName());
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.csvGenerationStarted", csvFile.symbolicName);
sheetToCsv(sheet, csvFile.file);
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.csvGenerationFinished", csvFile.symbolicName);
} else {
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.sheetIgnored", sheet.getSheetName());
}
}
} catch (EncryptedDocumentException | InvalidFormatException | IOException ex) {
ContextUtils.sendError(ctx, "ExcelToCsv.excelTransformationFailed", ex, "ExcelToCsv.excelTransformationFailed", entry.getSymbolicName());
throw ex;
}
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.excelTransformationFinishedSuccessfully", entry.getSymbolicName());
}
示例15: main
import org.apache.poi.EncryptedDocumentException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, EncryptedDocumentException, InvalidFormatException {
exportExcelDemo();
importExcelDemo();
}