This commit is contained in:
PJ Fanning 2025-08-28 13:00:54 +01:00
parent c38f5f9577
commit 9f9ff14e56
8 changed files with 59 additions and 6 deletions

View File

@ -19,7 +19,8 @@ package org.apache.poi.xslf;
import org.apache.poi.POIException;
/**
* An exception that indicates a problem reading a pptx file.
* An exception that indicates a problem reading a pptx file. Usually, a more
* specific exception will be wrapped as the cause.
* <p>This exception is only used by some new methods.
* Historically, POI has used {@link RuntimeException} for most of its
* exceptions, but this is not a good practice. This class is a checked

View File

@ -19,7 +19,8 @@ package org.apache.poi.xssf;
import org.apache.poi.POIException;
/**
* An exception that indicates a problem reading an xlsx file.
* An exception that indicates a problem reading an xlsx file. Usually, a more
* specific exception will be wrapped as the cause.
* <p>This exception is only used by some new methods.
* Historically, POI has used {@link RuntimeException} for most of its
* exceptions, but this is not a good practice. This class is a checked

View File

@ -19,7 +19,8 @@ package org.apache.poi.xwpf;
import org.apache.poi.POIException;
/**
* An exception that indicates a problem reading a docx file.
* An exception that indicates a problem reading a docx file. Usually, a more
* specific exception will be wrapped as the cause.
* <p>This exception is only used by some new methods.
* Historically, POI has used {@link RuntimeException} for most of its
* exceptions, but this is not a good practice. This class is a checked

View File

@ -0,0 +1,47 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf;
import java.io.File;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestXSSFParser {
@Test
void testXlsx() throws Exception {
final File file = HSSFTestDataSamples.getSampleFile("HeaderFooterComplexFormats.xlsx");
try (XSSFWorkbook wb = XSSFParser.parse(file)) {
assertNotNull(wb);
assertEquals(3, wb.getNumberOfSheets());
}
}
@Test
void testFailOnXls() throws Exception {
final File file = HSSFTestDataSamples.getSampleFile("44010-SingleChart.xls");
XSSFReadException xre = assertThrows(XSSFReadException.class, () -> XSSFParser.parse(file));
assertInstanceOf(OLE2NotOfficeXmlFileException.class, xre.getCause());
}
}

View File

@ -19,7 +19,8 @@ package org.apache.poi.hslf;
import org.apache.poi.POIException;
/**
* An exception that indicates a problem reading a ppt file.
* An exception that indicates a problem reading a ppt file. Usually, a more
* specific exception will be wrapped as the cause.
* <p>This exception is only used by some new methods.
* Historically, POI has used {@link RuntimeException} for most of its
* exceptions, but this is not a good practice. This class is a checked

View File

@ -19,7 +19,8 @@ package org.apache.poi.hwpf;
import org.apache.poi.POIException;
/**
* An exception that indicates a problem reading a doc file.
* An exception that indicates a problem reading a doc file. Usually, a more
* specific exception will be wrapped as the cause.
* <p>This exception is only used by some new methods.
* Historically, POI has used {@link RuntimeException} for most of its
* exceptions, but this is not a good practice. This class is a checked

View File

@ -19,7 +19,8 @@ package org.apache.poi.hssf;
import org.apache.poi.POIException;
/**
* An exception that indicates a problem reading an xls file.
* An exception that indicates a problem reading an xls file. Usually, a more
* specific exception will be wrapped as the cause.
* <p>This exception is only used by some new methods.
* Historically, POI has used {@link RuntimeException} for most of its
* exceptions, but this is not a good practice. This class is a checked